Browse Source

DirCacheCheckoutTest: Open Git and TreeWalk in try-with-resource

Change-Id: Icc8eda841e6a437e1acf3438525014e7c46d5eb2
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
06bf69d8ca
  1. 13
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

13
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

@ -140,7 +140,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test
public void testResetHard() throws IOException, NoFilepatternException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("f", "f()");
writeTrashFile("D/g", "g()");
git.add().addFilepattern(".").call();
@ -187,6 +187,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
assertWorkDir(mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h",
"h()", "untracked", "untracked"));
}
}
/**
* Reset hard from unclean condition.
@ -200,7 +201,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test
public void testResetHardFromIndexEntryWithoutFileToTreeWithoutFile()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("x", "x");
git.add().addFilepattern("x").call();
RevCommit id1 = git.commit().setMessage("c1").call();
@ -216,6 +217,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
git.reset().setMode(ResetType.HARD).setRef(id1.getName()).call();
assertIndex(mkmap("x", "x"));
}
}
/**
* Test first checkout in a repo
@ -224,8 +226,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
*/
@Test
public void testInitialCheckout() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
TestRepository<Repository> db_t = new TestRepository<Repository>(db);
BranchBuilder master = db_t.branch("master");
master.commit().add("f", "1").message("m0").create();
@ -233,6 +234,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
git.checkout().setName("master").call();
assertTrue(new File(db.getWorkTree(), "f").exists());
}
}
private DirCacheCheckout resetHard(RevCommit commit)
throws NoWorkTreeException,
@ -1612,7 +1614,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
public void assertWorkDir(Map<String, String> i)
throws CorruptObjectException,
IOException {
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.setRecursive(false);
walk.addTree(new FileTreeIterator(db));
String expectedValue;
@ -1654,4 +1656,5 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
}
assertEquals("WorkDir has not the right size.", i.size(), nrFiles);
}
}
}

Loading…
Cancel
Save