AddCommandTest: Create Git instances in try-with-resource
Change-Id: Idf42f03099eeb9975fef9492ea8a75776afc2a3c Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
a833fec219
commit
a8d99d9a4f
|
@ -77,9 +77,7 @@ public class AddCommandTest extends RepositoryTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddNothing() throws GitAPIException {
|
public void testAddNothing() throws GitAPIException {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
try {
|
|
||||||
git.add().call();
|
git.add().call();
|
||||||
fail("Expected IllegalArgumentException");
|
fail("Expected IllegalArgumentException");
|
||||||
} catch (NoFilepatternException e) {
|
} catch (NoFilepatternException e) {
|
||||||
|
@ -90,11 +88,10 @@ public void testAddNothing() throws GitAPIException {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddNonExistingSingleFile() throws GitAPIException {
|
public void testAddNonExistingSingleFile() throws GitAPIException {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
DirCache dc = git.add().addFilepattern("a.txt").call();
|
||||||
DirCache dc = git.add().addFilepattern("a.txt").call();
|
assertEquals(0, dc.getEntryCount());
|
||||||
assertEquals(0, dc.getEntryCount());
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -105,13 +102,13 @@ public void testAddExistingSingleFile() throws IOException, GitAPIException {
|
||||||
writer.print("content");
|
writer.print("content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
git.add().addFilepattern("a.txt").call();
|
assertEquals(
|
||||||
|
"[a.txt, mode:100644, content:content]",
|
||||||
assertEquals(
|
indexState(CONTENT));
|
||||||
"[a.txt, mode:100644, content:content]",
|
}
|
||||||
indexState(CONTENT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -124,18 +121,19 @@ public void testCleanFilter() throws IOException,
|
||||||
writeTrashFile("src/a.txt", "foo\n");
|
writeTrashFile("src/a.txt", "foo\n");
|
||||||
File script = writeTempFile("sed s/o/e/g");
|
File script = writeTempFile("sed s/o/e/g");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + slashify(script.getPath()));
|
"sh " + slashify(script.getPath()));
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
git.add().addFilepattern("src/a.txt").addFilepattern("src/a.tmp")
|
git.add().addFilepattern("src/a.txt").addFilepattern("src/a.tmp")
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[src/a.tmp, mode:100644, content:foo][src/a.txt, mode:100644, content:fee\n]",
|
"[src/a.tmp, mode:100644, content:foo][src/a.txt, mode:100644, content:fee\n]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -145,17 +143,18 @@ public void testCleanFilterEnvironment()
|
||||||
writeTrashFile("src/a.txt", "foo");
|
writeTrashFile("src/a.txt", "foo");
|
||||||
File script = writeTempFile("echo $GIT_DIR; echo 1 >xyz");
|
File script = writeTempFile("echo $GIT_DIR; echo 1 >xyz");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + slashify(script.getPath()));
|
"sh " + slashify(script.getPath()));
|
||||||
config.save();
|
config.save();
|
||||||
git.add().addFilepattern("src/a.txt").call();
|
git.add().addFilepattern("src/a.txt").call();
|
||||||
|
|
||||||
String gitDir = db.getDirectory().getAbsolutePath();
|
String gitDir = db.getDirectory().getAbsolutePath();
|
||||||
assertEquals("[src/a.txt, mode:100644, content:" + gitDir
|
assertEquals("[src/a.txt, mode:100644, content:" + gitDir
|
||||||
+ "\n]", indexState(CONTENT));
|
+ "\n]", indexState(CONTENT));
|
||||||
assertTrue(new File(db.getWorkTree(), "xyz").exists());
|
assertTrue(new File(db.getWorkTree(), "xyz").exists());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -169,22 +168,23 @@ public void testMultipleCleanFilter() throws IOException, GitAPIException {
|
||||||
File script = writeTempFile("sed s/o/e/g");
|
File script = writeTempFile("sed s/o/e/g");
|
||||||
File script2 = writeTempFile("sed s/f/x/g");
|
File script2 = writeTempFile("sed s/f/x/g");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + slashify(script.getPath()));
|
"sh " + slashify(script.getPath()));
|
||||||
config.setString("filter", "tstFilter2", "clean",
|
config.setString("filter", "tstFilter2", "clean",
|
||||||
"sh " + slashify(script2.getPath()));
|
"sh " + slashify(script2.getPath()));
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
git.add().addFilepattern("src/a.txt").addFilepattern("src/a.tmp")
|
git.add().addFilepattern("src/a.txt").addFilepattern("src/a.tmp")
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[src/a.tmp, mode:100644, content:xoo\n][src/a.txt, mode:100644, content:fee\n]",
|
"[src/a.tmp, mode:100644, content:xoo\n][src/a.txt, mode:100644, content:fee\n]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
|
||||||
// TODO: multiple clean filters for one file???
|
// TODO: multiple clean filters for one file???
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,17 +202,18 @@ public void testCommandInjection() throws IOException, GitAPIException {
|
||||||
writeTrashFile("; echo virus", "foo\n");
|
writeTrashFile("; echo virus", "foo\n");
|
||||||
File script = writeTempFile("sed s/o/e/g");
|
File script = writeTempFile("sed s/o/e/g");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + slashify(script.getPath()) + " %f");
|
"sh " + slashify(script.getPath()) + " %f");
|
||||||
writeTrashFile(".gitattributes", "* filter=tstFilter");
|
writeTrashFile(".gitattributes", "* filter=tstFilter");
|
||||||
|
|
||||||
git.add().addFilepattern("; echo virus").call();
|
git.add().addFilepattern("; echo virus").call();
|
||||||
// Without proper escaping the content would be "feovirus". The sed
|
// Without proper escaping the content would be "feovirus". The sed
|
||||||
// command and the "echo virus" would contribute to the content
|
// command and the "echo virus" would contribute to the content
|
||||||
assertEquals("[; echo virus, mode:100644, content:fee\n]",
|
assertEquals("[; echo virus, mode:100644, content:fee\n]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -220,18 +221,19 @@ public void testBadCleanFilter() throws IOException, GitAPIException {
|
||||||
writeTrashFile("a.txt", "foo");
|
writeTrashFile("a.txt", "foo");
|
||||||
File script = writeTempFile("sedfoo s/o/e/g");
|
File script = writeTempFile("sedfoo s/o/e/g");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + script.getPath());
|
"sh " + script.getPath());
|
||||||
config.save();
|
config.save();
|
||||||
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
fail("Didn't received the expected exception");
|
fail("Didn't received the expected exception");
|
||||||
} catch (FilterFailedException e) {
|
} catch (FilterFailedException e) {
|
||||||
assertEquals(127, e.getReturnCode());
|
assertEquals(127, e.getReturnCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,18 +242,19 @@ public void testBadCleanFilter2() throws IOException, GitAPIException {
|
||||||
writeTrashFile("a.txt", "foo");
|
writeTrashFile("a.txt", "foo");
|
||||||
File script = writeTempFile("sed s/o/e/g");
|
File script = writeTempFile("sed s/o/e/g");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"shfoo " + script.getPath());
|
"shfoo " + script.getPath());
|
||||||
config.save();
|
config.save();
|
||||||
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
fail("Didn't received the expected exception");
|
fail("Didn't received the expected exception");
|
||||||
} catch (FilterFailedException e) {
|
} catch (FilterFailedException e) {
|
||||||
assertEquals(127, e.getReturnCode());
|
assertEquals(127, e.getReturnCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,18 +264,19 @@ public void testCleanFilterReturning12() throws IOException,
|
||||||
writeTrashFile("a.txt", "foo");
|
writeTrashFile("a.txt", "foo");
|
||||||
File script = writeTempFile("exit 12");
|
File script = writeTempFile("exit 12");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + slashify(script.getPath()));
|
"sh " + slashify(script.getPath()));
|
||||||
config.save();
|
config.save();
|
||||||
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
fail("Didn't received the expected exception");
|
fail("Didn't received the expected exception");
|
||||||
} catch (FilterFailedException e) {
|
} catch (FilterFailedException e) {
|
||||||
assertEquals(12, e.getReturnCode());
|
assertEquals(12, e.getReturnCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,16 +285,18 @@ public void testNotApplicableFilter() throws IOException, GitAPIException {
|
||||||
writeTrashFile("a.txt", "foo");
|
writeTrashFile("a.txt", "foo");
|
||||||
File script = writeTempFile("sed s/o/e/g");
|
File script = writeTempFile("sed s/o/e/g");
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
config.setString("filter", "tstFilter", "something",
|
config.setString("filter", "tstFilter", "something",
|
||||||
"sh " + script.getPath());
|
"sh " + script.getPath());
|
||||||
config.save();
|
config.save();
|
||||||
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
||||||
|
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
assertEquals("[a.txt, mode:100644, content:foo]", indexState(CONTENT));
|
assertEquals("[a.txt, mode:100644, content:foo]",
|
||||||
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File writeTempFile(String body) throws IOException {
|
private File writeTempFile(String body) throws IOException {
|
||||||
|
@ -308,19 +314,20 @@ public void testAddExistingSingleSmallFileWithNewLine() throws IOException,
|
||||||
writer.print("row1\r\nrow2");
|
writer.print("row1\r\nrow2");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
db.getConfig().setString("core", null, "autocrlf", "false");
|
db.getConfig().setString("core", null, "autocrlf", "false");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2]",
|
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
db.getConfig().setString("core", null, "autocrlf", "true");
|
db.getConfig().setString("core", null, "autocrlf", "true");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:row1\nrow2]",
|
assertEquals("[a.txt, mode:100644, content:row1\nrow2]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
db.getConfig().setString("core", null, "autocrlf", "input");
|
db.getConfig().setString("core", null, "autocrlf", "input");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:row1\nrow2]",
|
assertEquals("[a.txt, mode:100644, content:row1\nrow2]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -337,19 +344,20 @@ public void testAddExistingSingleMediumSizeFileWithNewLine()
|
||||||
writer.print(crData);
|
writer.print(crData);
|
||||||
writer.close();
|
writer.close();
|
||||||
String lfData = data.toString().replaceAll("\r", "");
|
String lfData = data.toString().replaceAll("\r", "");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
db.getConfig().setString("core", null, "autocrlf", "false");
|
db.getConfig().setString("core", null, "autocrlf", "false");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:" + data + "]",
|
assertEquals("[a.txt, mode:100644, content:" + data + "]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
db.getConfig().setString("core", null, "autocrlf", "true");
|
db.getConfig().setString("core", null, "autocrlf", "true");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:" + lfData + "]",
|
assertEquals("[a.txt, mode:100644, content:" + lfData + "]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
db.getConfig().setString("core", null, "autocrlf", "input");
|
db.getConfig().setString("core", null, "autocrlf", "input");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:" + lfData + "]",
|
assertEquals("[a.txt, mode:100644, content:" + lfData + "]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -361,19 +369,20 @@ public void testAddExistingSingleBinaryFile() throws IOException,
|
||||||
writer.print("row1\r\nrow2\u0000");
|
writer.print("row1\r\nrow2\u0000");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
db.getConfig().setString("core", null, "autocrlf", "false");
|
db.getConfig().setString("core", null, "autocrlf", "false");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2\u0000]",
|
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2\u0000]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
db.getConfig().setString("core", null, "autocrlf", "true");
|
db.getConfig().setString("core", null, "autocrlf", "true");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2\u0000]",
|
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2\u0000]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
db.getConfig().setString("core", null, "autocrlf", "input");
|
db.getConfig().setString("core", null, "autocrlf", "input");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2\u0000]",
|
assertEquals("[a.txt, mode:100644, content:row1\r\nrow2\u0000]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -386,13 +395,13 @@ public void testAddExistingSingleFileInSubDir() throws IOException,
|
||||||
writer.print("content");
|
writer.print("content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
git.add().addFilepattern("sub/a.txt").call();
|
||||||
|
|
||||||
git.add().addFilepattern("sub/a.txt").call();
|
assertEquals(
|
||||||
|
"[sub/a.txt, mode:100644, content:content]",
|
||||||
assertEquals(
|
indexState(CONTENT));
|
||||||
"[sub/a.txt, mode:100644, content:content]",
|
}
|
||||||
indexState(CONTENT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -404,20 +413,21 @@ public void testAddExistingSingleFileTwice() throws IOException,
|
||||||
writer.print("content");
|
writer.print("content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
DirCache dc = git.add().addFilepattern("a.txt").call();
|
DirCache dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
dc.getEntry(0).getObjectId();
|
dc.getEntry(0).getObjectId();
|
||||||
|
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
writer.print("other content");
|
writer.print("other content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
dc = git.add().addFilepattern("a.txt").call();
|
dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[a.txt, mode:100644, content:other content]",
|
"[a.txt, mode:100644, content:other content]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -428,22 +438,23 @@ public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
|
||||||
writer.print("content");
|
writer.print("content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
DirCache dc = git.add().addFilepattern("a.txt").call();
|
DirCache dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
dc.getEntry(0).getObjectId();
|
dc.getEntry(0).getObjectId();
|
||||||
|
|
||||||
git.commit().setMessage("commit a.txt").call();
|
git.commit().setMessage("commit a.txt").call();
|
||||||
|
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
writer.print("other content");
|
writer.print("other content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
dc = git.add().addFilepattern("a.txt").call();
|
dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[a.txt, mode:100644, content:other content]",
|
"[a.txt, mode:100644, content:other content]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -454,18 +465,19 @@ public void testAddRemovedFile() throws Exception {
|
||||||
writer.print("content");
|
writer.print("content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
DirCache dc = git.add().addFilepattern("a.txt").call();
|
DirCache dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
dc.getEntry(0).getObjectId();
|
dc.getEntry(0).getObjectId();
|
||||||
FileUtils.delete(file);
|
FileUtils.delete(file);
|
||||||
|
|
||||||
// is supposed to do nothing
|
// is supposed to do nothing
|
||||||
dc = git.add().addFilepattern("a.txt").call();
|
dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[a.txt, mode:100644, content:content]",
|
"[a.txt, mode:100644, content:content]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -476,20 +488,21 @@ public void testAddRemovedCommittedFile() throws Exception {
|
||||||
writer.print("content");
|
writer.print("content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
DirCache dc = git.add().addFilepattern("a.txt").call();
|
DirCache dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
git.commit().setMessage("commit a.txt").call();
|
git.commit().setMessage("commit a.txt").call();
|
||||||
|
|
||||||
dc.getEntry(0).getObjectId();
|
dc.getEntry(0).getObjectId();
|
||||||
FileUtils.delete(file);
|
FileUtils.delete(file);
|
||||||
|
|
||||||
// is supposed to do nothing
|
// is supposed to do nothing
|
||||||
dc = git.add().addFilepattern("a.txt").call();
|
dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[a.txt, mode:100644, content:content]",
|
"[a.txt, mode:100644, content:content]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -537,13 +550,14 @@ public void testAddWithConflicts() throws Exception {
|
||||||
|
|
||||||
// now the test begins
|
// now the test begins
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
dc = git.add().addFilepattern("a.txt").call();
|
dc = git.add().addFilepattern("a.txt").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[a.txt, mode:100644, content:our content]" +
|
"[a.txt, mode:100644, content:our content]" +
|
||||||
"[b.txt, mode:100644, content:content b]",
|
"[b.txt, mode:100644, content:content b]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -560,12 +574,13 @@ public void testAddTwoFiles() throws Exception {
|
||||||
writer.print("content b");
|
writer.print("content b");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
|
git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[a.txt, mode:100644, content:content]" +
|
"[a.txt, mode:100644, content:content]" +
|
||||||
"[b.txt, mode:100644, content:content b]",
|
"[b.txt, mode:100644, content:content b]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -583,12 +598,13 @@ public void testAddFolder() throws Exception {
|
||||||
writer.print("content b");
|
writer.print("content b");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern("sub").call();
|
git.add().addFilepattern("sub").call();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:content]" +
|
"[sub/a.txt, mode:100644, content:content]" +
|
||||||
"[sub/b.txt, mode:100644, content:content b]",
|
"[sub/b.txt, mode:100644, content:content b]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -612,12 +628,13 @@ public void testAddIgnoredFile() throws Exception {
|
||||||
writer.print("content b");
|
writer.print("content b");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern("sub").call();
|
git.add().addFilepattern("sub").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:content]",
|
"[sub/a.txt, mode:100644, content:content]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -635,12 +652,13 @@ public void testAddWholeRepo() throws Exception {
|
||||||
writer.print("content b");
|
writer.print("content b");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:content]" +
|
"[sub/a.txt, mode:100644, content:content]" +
|
||||||
"[sub/b.txt, mode:100644, content:content b]",
|
"[sub/b.txt, mode:100644, content:content b]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the same three cases as in testAddWithParameterUpdate
|
// the same three cases as in testAddWithParameterUpdate
|
||||||
|
@ -662,40 +680,41 @@ public void testAddWithoutParameterUpdate() throws Exception {
|
||||||
writer.print("content b");
|
writer.print("content b");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern("sub").call();
|
git.add().addFilepattern("sub").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:content]" +
|
"[sub/a.txt, mode:100644, content:content]" +
|
||||||
"[sub/b.txt, mode:100644, content:content b]",
|
"[sub/b.txt, mode:100644, content:content b]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
|
||||||
git.commit().setMessage("commit").call();
|
git.commit().setMessage("commit").call();
|
||||||
|
|
||||||
// new unstaged file sub/c.txt
|
// new unstaged file sub/c.txt
|
||||||
File file3 = new File(db.getWorkTree(), "sub/c.txt");
|
File file3 = new File(db.getWorkTree(), "sub/c.txt");
|
||||||
FileUtils.createNewFile(file3);
|
FileUtils.createNewFile(file3);
|
||||||
writer = new PrintWriter(file3);
|
writer = new PrintWriter(file3);
|
||||||
writer.print("content c");
|
writer.print("content c");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
// file sub/a.txt is modified
|
// file sub/a.txt is modified
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
writer.print("modified content");
|
writer.print("modified content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
// file sub/b.txt is deleted
|
// file sub/b.txt is deleted
|
||||||
FileUtils.delete(file2);
|
FileUtils.delete(file2);
|
||||||
|
|
||||||
git.add().addFilepattern("sub").call();
|
git.add().addFilepattern("sub").call();
|
||||||
// change in sub/a.txt is staged
|
// change in sub/a.txt is staged
|
||||||
// deletion of sub/b.txt is not staged
|
// deletion of sub/b.txt is not staged
|
||||||
// sub/c.txt is staged
|
// sub/c.txt is staged
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:modified content]" +
|
"[sub/a.txt, mode:100644, content:modified content]" +
|
||||||
"[sub/b.txt, mode:100644, content:content b]" +
|
"[sub/b.txt, mode:100644, content:content b]" +
|
||||||
"[sub/c.txt, mode:100644, content:content c]",
|
"[sub/c.txt, mode:100644, content:content c]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// file a exists in workdir and in index -> added
|
// file a exists in workdir and in index -> added
|
||||||
|
@ -716,71 +735,73 @@ public void testAddWithParameterUpdate() throws Exception {
|
||||||
writer.print("content b");
|
writer.print("content b");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern("sub").call();
|
git.add().addFilepattern("sub").call();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:content]" +
|
"[sub/a.txt, mode:100644, content:content]" +
|
||||||
"[sub/b.txt, mode:100644, content:content b]",
|
"[sub/b.txt, mode:100644, content:content b]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
|
||||||
git.commit().setMessage("commit").call();
|
git.commit().setMessage("commit").call();
|
||||||
|
|
||||||
// new unstaged file sub/c.txt
|
// new unstaged file sub/c.txt
|
||||||
File file3 = new File(db.getWorkTree(), "sub/c.txt");
|
File file3 = new File(db.getWorkTree(), "sub/c.txt");
|
||||||
FileUtils.createNewFile(file3);
|
FileUtils.createNewFile(file3);
|
||||||
writer = new PrintWriter(file3);
|
writer = new PrintWriter(file3);
|
||||||
writer.print("content c");
|
writer.print("content c");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
// file sub/a.txt is modified
|
// file sub/a.txt is modified
|
||||||
writer = new PrintWriter(file);
|
writer = new PrintWriter(file);
|
||||||
writer.print("modified content");
|
writer.print("modified content");
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
FileUtils.delete(file2);
|
FileUtils.delete(file2);
|
||||||
|
|
||||||
// change in sub/a.txt is staged
|
// change in sub/a.txt is staged
|
||||||
// deletion of sub/b.txt is staged
|
// deletion of sub/b.txt is staged
|
||||||
// sub/c.txt is not staged
|
// sub/c.txt is not staged
|
||||||
git.add().addFilepattern("sub").setUpdate(true).call();
|
git.add().addFilepattern("sub").setUpdate(true).call();
|
||||||
// change in sub/a.txt is staged
|
// change in sub/a.txt is staged
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[sub/a.txt, mode:100644, content:modified content]",
|
"[sub/a.txt, mode:100644, content:modified content]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAssumeUnchanged() throws Exception {
|
public void testAssumeUnchanged() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
String path = "a.txt";
|
String path = "a.txt";
|
||||||
writeTrashFile(path, "content");
|
writeTrashFile(path, "content");
|
||||||
git.add().addFilepattern(path).call();
|
git.add().addFilepattern(path).call();
|
||||||
String path2 = "b.txt";
|
String path2 = "b.txt";
|
||||||
writeTrashFile(path2, "content");
|
writeTrashFile(path2, "content");
|
||||||
git.add().addFilepattern(path2).call();
|
git.add().addFilepattern(path2).call();
|
||||||
git.commit().setMessage("commit").call();
|
git.commit().setMessage("commit").call();
|
||||||
assertEquals("[a.txt, mode:100644, content:"
|
assertEquals("[a.txt, mode:100644, content:"
|
||||||
+ "content, assume-unchanged:false]"
|
+ "content, assume-unchanged:false]"
|
||||||
+ "[b.txt, mode:100644, content:content, "
|
+ "[b.txt, mode:100644, content:content, "
|
||||||
+ "assume-unchanged:false]", indexState(CONTENT
|
+ "assume-unchanged:false]", indexState(CONTENT
|
||||||
| ASSUME_UNCHANGED));
|
| ASSUME_UNCHANGED));
|
||||||
assumeUnchanged(path2);
|
assumeUnchanged(path2);
|
||||||
assertEquals("[a.txt, mode:100644, content:content, "
|
assertEquals("[a.txt, mode:100644, content:content, "
|
||||||
+ "assume-unchanged:false][b.txt, mode:100644, "
|
+ "assume-unchanged:false][b.txt, mode:100644, "
|
||||||
+ "content:content, assume-unchanged:true]", indexState(CONTENT
|
+ "content:content, assume-unchanged:true]", indexState(CONTENT
|
||||||
| ASSUME_UNCHANGED));
|
| ASSUME_UNCHANGED));
|
||||||
writeTrashFile(path, "more content");
|
writeTrashFile(path, "more content");
|
||||||
writeTrashFile(path2, "more content");
|
writeTrashFile(path2, "more content");
|
||||||
|
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
|
|
||||||
assertEquals("[a.txt, mode:100644, content:more content,"
|
assertEquals("[a.txt, mode:100644, content:more content,"
|
||||||
+ " assume-unchanged:false][b.txt, mode:100644,"
|
+ " assume-unchanged:false][b.txt, mode:100644,"
|
||||||
+ "" + ""
|
+ "" + ""
|
||||||
+ " content:content, assume-unchanged:true]",
|
+ " content:content, assume-unchanged:true]",
|
||||||
indexState(CONTENT
|
indexState(CONTENT
|
||||||
| ASSUME_UNCHANGED));
|
| ASSUME_UNCHANGED));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue