Browse Source

IndexDiffTest: Open Git instances in try-with-resources

Change-Id: I7fa2d16561982ddfde053f2fe78135c114b66b1d
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
f23b0fd7e6
  1. 46
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

46
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

@ -148,8 +148,9 @@ public class IndexDiffTest extends RepositoryTestCase {
writeTrashFile("file2", "file2"); writeTrashFile("file2", "file2");
writeTrashFile("dir/file3", "dir/file3"); writeTrashFile("dir/file3", "dir/file3");
Git git = new Git(db); try (Git git = new Git(db)) {
git.add().addFilepattern("file2").addFilepattern("dir/file3").call(); git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
}
writeTrashFile("dir/file3", "changed"); writeTrashFile("dir/file3", "changed");
@ -177,8 +178,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testConflicting() throws Exception { public void testConflicting() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -202,6 +202,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId()) MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -221,8 +222,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testConflictingDeletedAndModified() throws Exception { public void testConflictingDeletedAndModified() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -244,6 +244,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId()) MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -262,8 +263,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testConflictingFromMultipleCreations() throws Exception { public void testConflictingFromMultipleCreations() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call(); RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -284,6 +284,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId()) MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -304,11 +305,12 @@ public class IndexDiffTest extends RepositoryTestCase {
writeTrashFile("a.c", "a.c"); writeTrashFile("a.c", "a.c");
writeTrashFile("a=c", "a=c"); writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d"); writeTrashFile("a=d", "a=d");
Git git = new Git(db); try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").call(); git.add().addFilepattern("a.b").call();
git.add().addFilepattern("a.c").call(); git.add().addFilepattern("a.c").call();
git.add().addFilepattern("a=c").call(); git.add().addFilepattern("a=c").call();
git.add().addFilepattern("a=d").call(); git.add().addFilepattern("a=d").call();
}
TreeFormatter tree = new TreeFormatter(); TreeFormatter tree = new TreeFormatter();
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
@ -338,7 +340,6 @@ public class IndexDiffTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testUnchangedComplex() throws IOException, GitAPIException { public void testUnchangedComplex() throws IOException, GitAPIException {
Git git = new Git(db);
writeTrashFile("a.b", "a.b"); writeTrashFile("a.b", "a.b");
writeTrashFile("a.c", "a.c"); writeTrashFile("a.c", "a.c");
writeTrashFile("a/b.b/b", "a/b.b/b"); writeTrashFile("a/b.b/b", "a/b.b/b");
@ -346,10 +347,12 @@ public class IndexDiffTest extends RepositoryTestCase {
writeTrashFile("a/c", "a/c"); writeTrashFile("a/c", "a/c");
writeTrashFile("a=c", "a=c"); writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d"); writeTrashFile("a=d", "a=d");
try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").addFilepattern("a.c") git.add().addFilepattern("a.b").addFilepattern("a.c")
.addFilepattern("a/b.b/b").addFilepattern("a/b") .addFilepattern("a/b.b/b").addFilepattern("a/b")
.addFilepattern("a/c").addFilepattern("a=c") .addFilepattern("a/c").addFilepattern("a=c")
.addFilepattern("a=d").call(); .addFilepattern("a=d").call();
}
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
@ -397,11 +400,12 @@ public class IndexDiffTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testRemovedUntracked() throws Exception{ public void testRemovedUntracked() throws Exception{
Git git = new Git(db);
String path = "file"; String path = "file";
try (Git git = new Git(db)) {
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
git.commit().setMessage("commit").call(); git.commit().setMessage("commit").call();
}
removeFromIndex(path); removeFromIndex(path);
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -417,8 +421,7 @@ public class IndexDiffTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testUntrackedFolders() throws Exception { public void testUntrackedFolders() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db)); new FileTreeIterator(db));
diff.diff(); diff.diff();
@ -463,6 +466,7 @@ public class IndexDiffTest extends RepositoryTestCase {
"target")), "target")),
diff.getUntrackedFolders()); diff.getUntrackedFolders());
} }
}
/** /**
* Test that ignored folders aren't listed as untracked * Test that ignored folders aren't listed as untracked
@ -471,8 +475,7 @@ public class IndexDiffTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testUntrackedNotIgnoredFolders() throws Exception { public void testUntrackedNotIgnoredFolders() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db)); new FileTreeIterator(db));
diff.diff(); diff.diff();
@ -510,10 +513,11 @@ public class IndexDiffTest extends RepositoryTestCase {
"target")), "target")),
diff.getUntrackedFolders()); diff.getUntrackedFolders());
} }
}
@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 = "file"; String path = "file";
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
@ -551,6 +555,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertTrue(diff.getChanged().contains("file")); assertTrue(diff.getChanged().contains("file"));
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
} }
}
@Test @Test
public void testStageState() throws IOException { public void testStageState() throws IOException {
@ -575,8 +580,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testStageState_mergeAndReset_bug() throws Exception { public void testStageState_mergeAndReset_bug() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "content"); writeTrashFile("a", "content");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -635,11 +639,11 @@ public class IndexDiffTest extends RepositoryTestCase {
.get("b")); .get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty()); assertTrue(diff.getUntrackedFolders().isEmpty());
} }
}
@Test @Test
public void testStageState_simulated_bug() throws Exception { public void testStageState_simulated_bug() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "content"); writeTrashFile("a", "content");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -688,10 +692,11 @@ public class IndexDiffTest extends RepositoryTestCase {
.get("b")); .get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty()); assertTrue(diff.getUntrackedFolders().isEmpty());
} }
}
@Test @Test
public void testAutoCRLFInput() throws Exception { public void testAutoCRLFInput() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
FileBasedConfig config = db.getConfig(); FileBasedConfig config = db.getConfig();
// Make sure core.autocrlf is false before adding // Make sure core.autocrlf is false before adding
@ -717,6 +722,7 @@ public class IndexDiffTest extends RepositoryTestCase {
"Expected no modified files, but there were: " "Expected no modified files, but there were: "
+ diff.getModified(), diff.getModified().isEmpty()); + diff.getModified(), diff.getModified().isEmpty());
} }
}
private void verifyStageState(StageState expected, int... stages) private void verifyStageState(StageState expected, int... stages)
throws IOException { throws IOException {

Loading…
Cancel
Save