]> source.dussan.org Git - jgit.git/commitdiff
Close some Repository instances in tests 69/151369/1
authorThomas Wolf <thomas.wolf@paranor.ch>
Mon, 21 Oct 2019 09:23:48 +0000 (11:23 +0200)
committerThomas Wolf <thomas.wolf@paranor.ch>
Mon, 21 Oct 2019 09:39:46 +0000 (11:39 +0200)
This doesn't yet ensure that _all_ repositories are closed. It only
handles the obvious, local, and easy cases.

Change-Id: I0f9f8607791f0f03ed1f5ad71e9595e78b78892f
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java

index 2f532b4ec47ba3eb3a1edee97c819d51c3af3e28..52a9dfa3e24d74527593830207d0433dd41448af 100644 (file)
@@ -1132,41 +1132,42 @@ public class AddCommandTest extends RepositoryTestCase {
                        }
                };
 
-               Git git = Git.open(db.getDirectory(), executableFs);
                String path = "a.txt";
                String path2 = "a.sh";
                writeTrashFile(path, "content");
                writeTrashFile(path2, "binary: content");
-               git.add().addFilepattern(path).addFilepattern(path2).call();
-               RevCommit commit1 = git.commit().setMessage("commit").call();
-               try (TreeWalk walk = new TreeWalk(db)) {
-                       walk.addTree(commit1.getTree());
-                       walk.next();
-                       assertEquals(path2, walk.getPathString());
-                       assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
-                       walk.next();
-                       assertEquals(path, walk.getPathString());
-                       assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
+               try (Git git = Git.open(db.getDirectory(), executableFs)) {
+                       git.add().addFilepattern(path).addFilepattern(path2).call();
+                       RevCommit commit1 = git.commit().setMessage("commit").call();
+                       try (TreeWalk walk = new TreeWalk(db)) {
+                               walk.addTree(commit1.getTree());
+                               walk.next();
+                               assertEquals(path2, walk.getPathString());
+                               assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
+                               walk.next();
+                               assertEquals(path, walk.getPathString());
+                               assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
+                       }
                }
-
                config = db.getConfig();
                config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
                                ConfigConstants.CONFIG_KEY_FILEMODE, false);
                config.save();
 
-               Git git2 = Git.open(db.getDirectory(), executableFs);
                writeTrashFile(path2, "content2");
                writeTrashFile(path, "binary: content2");
-               git2.add().addFilepattern(path).addFilepattern(path2).call();
-               RevCommit commit2 = git2.commit().setMessage("commit2").call();
-               try (TreeWalk walk = new TreeWalk(db)) {
-                       walk.addTree(commit2.getTree());
-                       walk.next();
-                       assertEquals(path2, walk.getPathString());
-                       assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
-                       walk.next();
-                       assertEquals(path, walk.getPathString());
-                       assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
+               try (Git git2 = Git.open(db.getDirectory(), executableFs)) {
+                       git2.add().addFilepattern(path).addFilepattern(path2).call();
+                       RevCommit commit2 = git2.commit().setMessage("commit2").call();
+                       try (TreeWalk walk = new TreeWalk(db)) {
+                               walk.addTree(commit2.getTree());
+                               walk.next();
+                               assertEquals(path2, walk.getPathString());
+                               assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
+                               walk.next();
+                               assertEquals(path, walk.getPathString());
+                               assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
+                       }
                }
        }
 
@@ -1291,18 +1292,19 @@ public class AddCommandTest extends RepositoryTestCase {
                FileRepositoryBuilder nestedBuilder = new FileRepositoryBuilder();
                nestedBuilder.setWorkTree(gitLinkDir);
 
-               Repository nestedRepo = nestedBuilder.build();
-               nestedRepo.create();
+               try (Repository nestedRepo = nestedBuilder.build()) {
+                       nestedRepo.create();
 
-               writeTrashFile(path, "README1.md", "content");
-               writeTrashFile(path, "README2.md", "content");
+                       writeTrashFile(path, "README1.md", "content");
+                       writeTrashFile(path, "README2.md", "content");
 
-               // Commit these changes in the subrepo
-               try (Git git = new Git(nestedRepo)) {
-                       git.add().addFilepattern(".").call();
-                       git.commit().setMessage("subrepo commit").call();
-               } catch (GitAPIException e) {
-                       throw new RuntimeException(e);
+                       // Commit these changes in the subrepo
+                       try (Git git = new Git(nestedRepo)) {
+                               git.add().addFilepattern(".").call();
+                               git.commit().setMessage("subrepo commit").call();
+                       } catch (GitAPIException e) {
+                               throw new RuntimeException(e);
+                       }
                }
        }
 }
index 6521d866b5b37791325a7a6bdc3aa3b387c64229..3f281c49d2e6e991791f0a98768e03d58187fcf2 100644 (file)
@@ -468,22 +468,22 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
        @Test
        public void testDeltaStatistics() throws Exception {
                config.setDeltaCompress(true);
+               // TestRepository will close repo
                FileRepository repo = createBareRepository();
                ArrayList<RevObject> blobs = new ArrayList<>();
                try (TestRepository<FileRepository> testRepo = new TestRepository<>(
                                repo)) {
                        blobs.add(testRepo.blob(genDeltableData(1000)));
                        blobs.add(testRepo.blob(genDeltableData(1005)));
-               }
-
-               try (PackWriter pw = new PackWriter(repo)) {
-                       NullProgressMonitor m = NullProgressMonitor.INSTANCE;
-                       pw.preparePack(blobs.iterator());
-                       pw.writePack(m, m, os);
-                       PackStatistics stats = pw.getStatistics();
-                       assertEquals(1, stats.getTotalDeltas());
-                       assertTrue("Delta bytes not set.",
-                                       stats.byObjectType(OBJ_BLOB).getDeltaBytes() > 0);
+                       try (PackWriter pw = new PackWriter(repo)) {
+                               NullProgressMonitor m = NullProgressMonitor.INSTANCE;
+                               pw.preparePack(blobs.iterator());
+                               pw.writePack(m, m, os);
+                               PackStatistics stats = pw.getStatistics();
+                               assertEquals(1, stats.getTotalDeltas());
+                               assertTrue("Delta bytes not set.",
+                                               stats.byObjectType(OBJ_BLOB).getDeltaBytes() > 0);
+                       }
                }
        }
 
@@ -535,6 +535,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
 
        @Test
        public void testExclude() throws Exception {
+               // TestRepository closes repo
                FileRepository repo = createBareRepository();
 
                try (TestRepository<FileRepository> testRepo = new TestRepository<>(
@@ -568,98 +569,102 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
 
        @Test
        public void testShallowIsMinimalDepth1() throws Exception {
-               FileRepository repo = setupRepoForShallowFetch();
-
-               PackIndex idx = writeShallowPack(repo, 1, wants(c2), NONE, NONE);
-               assertContent(idx, Arrays.asList(c2.getId(), c2.getTree().getId(),
-                               contentA.getId(), contentB.getId()));
-
-               // Client already has blobs A and B, verify those are not packed.
-               idx = writeShallowPack(repo, 1, wants(c5), haves(c2), shallows(c2));
-               assertContent(idx, Arrays.asList(c5.getId(), c5.getTree().getId(),
-                               contentC.getId(), contentD.getId(), contentE.getId()));
+               try (FileRepository repo = setupRepoForShallowFetch()) {
+                       PackIndex idx = writeShallowPack(repo, 1, wants(c2), NONE, NONE);
+                       assertContent(idx, Arrays.asList(c2.getId(), c2.getTree().getId(),
+                                       contentA.getId(), contentB.getId()));
+
+                       // Client already has blobs A and B, verify those are not packed.
+                       idx = writeShallowPack(repo, 1, wants(c5), haves(c2), shallows(c2));
+                       assertContent(idx, Arrays.asList(c5.getId(), c5.getTree().getId(),
+                                       contentC.getId(), contentD.getId(), contentE.getId()));
+               }
        }
 
        @Test
        public void testShallowIsMinimalDepth2() throws Exception {
-               FileRepository repo = setupRepoForShallowFetch();
-
-               PackIndex idx = writeShallowPack(repo, 2, wants(c2), NONE, NONE);
-               assertContent(idx,
-                               Arrays.asList(c1.getId(), c2.getId(), c1.getTree().getId(),
-                                               c2.getTree().getId(), contentA.getId(),
-                                               contentB.getId()));
-
-               // Client already has blobs A and B, verify those are not packed.
-               idx = writeShallowPack(repo, 2, wants(c5), haves(c1, c2), shallows(c1));
-               assertContent(idx,
-                               Arrays.asList(c4.getId(), c5.getId(), c4.getTree().getId(),
-                                               c5.getTree().getId(), contentC.getId(),
-                                               contentD.getId(), contentE.getId()));
+               try (FileRepository repo = setupRepoForShallowFetch()) {
+                       PackIndex idx = writeShallowPack(repo, 2, wants(c2), NONE, NONE);
+                       assertContent(idx,
+                                       Arrays.asList(c1.getId(), c2.getId(), c1.getTree().getId(),
+                                                       c2.getTree().getId(), contentA.getId(),
+                                                       contentB.getId()));
+
+                       // Client already has blobs A and B, verify those are not packed.
+                       idx = writeShallowPack(repo, 2, wants(c5), haves(c1, c2),
+                                       shallows(c1));
+                       assertContent(idx,
+                                       Arrays.asList(c4.getId(), c5.getId(), c4.getTree().getId(),
+                                                       c5.getTree().getId(), contentC.getId(),
+                                                       contentD.getId(), contentE.getId()));
+               }
        }
 
        @Test
        public void testShallowFetchShallowParentDepth1() throws Exception {
-               FileRepository repo = setupRepoForShallowFetch();
-
-               PackIndex idx = writeShallowPack(repo, 1, wants(c5), NONE, NONE);
-               assertContent(idx,
-                               Arrays.asList(c5.getId(), c5.getTree().getId(),
-                                               contentA.getId(), contentB.getId(), contentC.getId(),
-                                               contentD.getId(), contentE.getId()));
-
-               idx = writeShallowPack(repo, 1, wants(c4), haves(c5), shallows(c5));
-               assertContent(idx, Arrays.asList(c4.getId(), c4.getTree().getId()));
+               try (FileRepository repo = setupRepoForShallowFetch()) {
+                       PackIndex idx = writeShallowPack(repo, 1, wants(c5), NONE, NONE);
+                       assertContent(idx, Arrays.asList(c5.getId(), c5.getTree().getId(),
+                                       contentA.getId(), contentB.getId(), contentC.getId(),
+                                       contentD.getId(), contentE.getId()));
+
+                       idx = writeShallowPack(repo, 1, wants(c4), haves(c5), shallows(c5));
+                       assertContent(idx, Arrays.asList(c4.getId(), c4.getTree().getId()));
+               }
        }
 
        @Test
        public void testShallowFetchShallowParentDepth2() throws Exception {
-               FileRepository repo = setupRepoForShallowFetch();
-
-               PackIndex idx = writeShallowPack(repo, 2, wants(c5), NONE, NONE);
-               assertContent(idx,
-                               Arrays.asList(c4.getId(), c5.getId(), c4.getTree().getId(),
-                                               c5.getTree().getId(), contentA.getId(),
-                                               contentB.getId(), contentC.getId(), contentD.getId(),
-                                               contentE.getId()));
-
-               idx = writeShallowPack(repo, 2, wants(c3), haves(c4, c5), shallows(c4));
-               assertContent(idx, Arrays.asList(c2.getId(), c3.getId(),
-                               c2.getTree().getId(), c3.getTree().getId()));
+               try (FileRepository repo = setupRepoForShallowFetch()) {
+                       PackIndex idx = writeShallowPack(repo, 2, wants(c5), NONE, NONE);
+                       assertContent(idx,
+                                       Arrays.asList(c4.getId(), c5.getId(), c4.getTree().getId(),
+                                                       c5.getTree().getId(), contentA.getId(),
+                                                       contentB.getId(), contentC.getId(),
+                                                       contentD.getId(), contentE.getId()));
+
+                       idx = writeShallowPack(repo, 2, wants(c3), haves(c4, c5),
+                                       shallows(c4));
+                       assertContent(idx, Arrays.asList(c2.getId(), c3.getId(),
+                                       c2.getTree().getId(), c3.getTree().getId()));
+               }
        }
 
        @Test
        public void testShallowFetchShallowAncestorDepth1() throws Exception {
-               FileRepository repo = setupRepoForShallowFetch();
-
-               PackIndex idx = writeShallowPack(repo, 1, wants(c5), NONE, NONE);
-               assertContent(idx,
-                               Arrays.asList(c5.getId(), c5.getTree().getId(),
-                                               contentA.getId(), contentB.getId(), contentC.getId(),
-                                               contentD.getId(), contentE.getId()));
-
-               idx = writeShallowPack(repo, 1, wants(c3), haves(c5), shallows(c5));
-               assertContent(idx, Arrays.asList(c3.getId(), c3.getTree().getId()));
+               try (FileRepository repo = setupRepoForShallowFetch()) {
+                       PackIndex idx = writeShallowPack(repo, 1, wants(c5), NONE, NONE);
+                       assertContent(idx, Arrays.asList(c5.getId(), c5.getTree().getId(),
+                                       contentA.getId(), contentB.getId(), contentC.getId(),
+                                       contentD.getId(), contentE.getId()));
+
+                       idx = writeShallowPack(repo, 1, wants(c3), haves(c5), shallows(c5));
+                       assertContent(idx, Arrays.asList(c3.getId(), c3.getTree().getId()));
+               }
        }
 
        @Test
        public void testShallowFetchShallowAncestorDepth2() throws Exception {
-               FileRepository repo = setupRepoForShallowFetch();
-
-               PackIndex idx = writeShallowPack(repo, 2, wants(c5), NONE, NONE);
-               assertContent(idx,
-                               Arrays.asList(c4.getId(), c5.getId(), c4.getTree().getId(),
-                                               c5.getTree().getId(), contentA.getId(),
-                                               contentB.getId(), contentC.getId(), contentD.getId(),
-                                               contentE.getId()));
-
-               idx = writeShallowPack(repo, 2, wants(c2), haves(c4, c5), shallows(c4));
-               assertContent(idx, Arrays.asList(c1.getId(), c2.getId(),
-                               c1.getTree().getId(), c2.getTree().getId()));
+               try (FileRepository repo = setupRepoForShallowFetch()) {
+                       PackIndex idx = writeShallowPack(repo, 2, wants(c5), NONE, NONE);
+                       assertContent(idx,
+                                       Arrays.asList(c4.getId(), c5.getId(), c4.getTree().getId(),
+                                                       c5.getTree().getId(), contentA.getId(),
+                                                       contentB.getId(), contentC.getId(),
+                                                       contentD.getId(), contentE.getId()));
+
+                       idx = writeShallowPack(repo, 2, wants(c2), haves(c4, c5),
+                                       shallows(c4));
+                       assertContent(idx, Arrays.asList(c1.getId(), c2.getId(),
+                                       c1.getTree().getId(), c2.getTree().getId()));
+               }
        }
 
        private FileRepository setupRepoForShallowFetch() throws Exception {
                FileRepository repo = createBareRepository();
+               // TestRepository will close the repo, but we need to return an open
+               // one!
+               repo.incrementOpen();
                try (TestRepository<Repository> r = new TestRepository<>(repo)) {
                        BranchBuilder bb = r.branch("refs/heads/master");
                        contentA = r.blob("A");
index 43f30d8ca89471232ff0ecaf75b97214d75d1357..5100c1ce29b18abfb198ca41c26a0cd40a53496c 100644 (file)
@@ -145,13 +145,14 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                }
 
                File theDir = new File(repo1Parent, Constants.DOT_GIT);
-               FileRepository r = (FileRepository) new FileRepositoryBuilder()
-                               .setGitDir(theDir).build();
-               assertEqualsPath(theDir, r.getDirectory());
-               assertEqualsPath(repo1Parent, r.getWorkTree());
-               assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
-               assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
-                               .getDirectory());
+               try (FileRepository r = (FileRepository) new FileRepositoryBuilder()
+                               .setGitDir(theDir).build()) {
+                       assertEqualsPath(theDir, r.getDirectory());
+                       assertEqualsPath(repo1Parent, r.getWorkTree());
+                       assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+                       assertEqualsPath(new File(theDir, Constants.OBJECTS),
+                                       r.getObjectDatabase().getDirectory());
+               }
        }
 
        /**
@@ -170,14 +171,15 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                }
 
                File theDir = new File(repo1Parent, Constants.DOT_GIT);
-               FileRepository r = (FileRepository) new FileRepositoryBuilder()
+               try (FileRepository r = (FileRepository) new FileRepositoryBuilder()
                                .setGitDir(theDir).setWorkTree(repo1Parent.getParentFile())
-                               .build();
-               assertEqualsPath(theDir, r.getDirectory());
-               assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
-               assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
-               assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
-                               .getDirectory());
+                               .build()) {
+                       assertEqualsPath(theDir, r.getDirectory());
+                       assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
+                       assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+                       assertEqualsPath(new File(theDir, Constants.OBJECTS),
+                                       r.getObjectDatabase().getDirectory());
+               }
        }
 
        /**
@@ -195,13 +197,14 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                }
 
                File theDir = new File(repo1Parent, Constants.DOT_GIT);
-               FileRepository r = (FileRepository) new FileRepositoryBuilder()
-                               .setWorkTree(repo1Parent).build();
-               assertEqualsPath(theDir, r.getDirectory());
-               assertEqualsPath(repo1Parent, r.getWorkTree());
-               assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
-               assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
-                               .getDirectory());
+               try (FileRepository r = (FileRepository) new FileRepositoryBuilder()
+                               .setWorkTree(repo1Parent).build()) {
+                       assertEqualsPath(theDir, r.getDirectory());
+                       assertEqualsPath(repo1Parent, r.getWorkTree());
+                       assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+                       assertEqualsPath(new File(theDir, Constants.OBJECTS),
+                                       r.getObjectDatabase().getDirectory());
+               }
        }
 
        /**
@@ -224,13 +227,14 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                }
 
                File theDir = new File(repo1Parent, Constants.DOT_GIT);
-               FileRepository r = (FileRepository) new FileRepositoryBuilder()
-                               .setGitDir(theDir).build();
-               assertEqualsPath(theDir, r.getDirectory());
-               assertEqualsPath(workdir, r.getWorkTree());
-               assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
-               assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
-                               .getDirectory());
+               try (FileRepository r = (FileRepository) new FileRepositoryBuilder()
+                               .setGitDir(theDir).build()) {
+                       assertEqualsPath(theDir, r.getDirectory());
+                       assertEqualsPath(workdir, r.getWorkTree());
+                       assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+                       assertEqualsPath(new File(theDir, Constants.OBJECTS),
+                                       r.getObjectDatabase().getDirectory());
+               }
        }
 
        /**
@@ -253,13 +257,14 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                }
 
                File theDir = new File(repo1Parent, Constants.DOT_GIT);
-               FileRepository r = (FileRepository) new FileRepositoryBuilder()
-                               .setGitDir(theDir).build();
-               assertEqualsPath(theDir, r.getDirectory());
-               assertEqualsPath(workdir, r.getWorkTree());
-               assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
-               assertEqualsPath(new File(theDir, Constants.OBJECTS), r.getObjectDatabase()
-                               .getDirectory());
+               try (FileRepository r = (FileRepository) new FileRepositoryBuilder()
+                               .setGitDir(theDir).build()) {
+                       assertEqualsPath(theDir, r.getDirectory());
+                       assertEqualsPath(workdir, r.getWorkTree());
+                       assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
+                       assertEqualsPath(new File(theDir, Constants.OBJECTS),
+                                       r.getObjectDatabase().getDirectory());
+               }
        }
 
        /**
@@ -306,17 +311,20 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
                // open when we create it we won't write the object file out as a loose
                // object (as it already exists in the pack).
                //
-               final Repository newdb = createBareRepository();
-               try (ObjectInserter oi = newdb.newObjectInserter()) {
-                       final ObjectId treeId = oi.insert(new TreeFormatter());
-                       assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904",
-                                       treeId.name());
+               try (Repository newdb = createBareRepository()) {
+                       try (ObjectInserter oi = newdb.newObjectInserter()) {
+                               final ObjectId treeId = oi.insert(new TreeFormatter());
+                               assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904",
+                                               treeId.name());
+                       }
+
+                       final File o = new File(
+                                       new File(new File(newdb.getDirectory(), Constants.OBJECTS),
+                                                       "4b"),
+                                       "825dc642cb6eb9a060e54bf8d69288fbee4904");
+                       assertTrue("Exists " + o, o.isFile());
+                       assertTrue("Read-only " + o, !o.canWrite());
                }
-
-               final File o = new File(new File(new File(newdb.getDirectory(),
-                               Constants.OBJECTS), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
-               assertTrue("Exists " + o, o.isFile());
-               assertTrue("Read-only " + o, !o.canWrite());
        }
 
        @Test
index 785daf60584f913466ff51f4388ba6e309d17741..cf954070e05aaa10df87011f349c47d1eedec64e 100644 (file)
@@ -124,9 +124,11 @@ public class IndexDiffTest extends RepositoryTestCase {
        public void testMissing() throws Exception {
                File file2 = writeTrashFile("file2", "file2");
                File file3 = writeTrashFile("dir/file3", "dir/file3");
-               Git git = Git.wrap(db);
-               git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
-               git.commit().setMessage("commit").call();
+               try (Git git = new Git(db)) {
+                       git.add().addFilepattern("file2").addFilepattern("dir/file3")
+                                       .call();
+                       git.commit().setMessage("commit").call();
+               }
                assertTrue(file2.delete());
                assertTrue(file3.delete());
                IndexDiff diff = new IndexDiff(db, Constants.HEAD,
index 62495fb023bb317147c0a9eef90e0b4f1a2a3cc0..3379a253776befc555db6def171f0ef76ed4ce90 100644 (file)
@@ -1365,8 +1365,8 @@ public class MergerTest extends RepositoryTestCase {
        }
 
        private String readBlob(ObjectId treeish, String path) throws Exception {
-               try (TestRepository<?> tr = new TestRepository<>(db)) {
-                       RevWalk rw = tr.getRevWalk();
+               try (TestRepository<?> tr = new TestRepository<>(db);
+                               RevWalk rw = tr.getRevWalk()) {
                        RevTree tree = rw.parseTree(treeish);
                        RevObject obj = tr.get(tree, path);
                        if (obj == null) {
index c6de2ceac9e9a1efaa936319015801dea84845e7..3a54ad5b6dcb9ac7e3a2e01462e1e4f697d98255 100644 (file)
@@ -625,9 +625,8 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
 
        @Test
        public void testCustomFileModeStrategy() throws Exception {
-               Repository nestedRepo = createNestedRepo();
-
-               try (Git git = new Git(nestedRepo)) {
+               try (Repository nestedRepo = createNestedRepo();
+                               Git git = new Git(nestedRepo)) {
                        // validate that our custom strategy is honored
                        WorkingTreeIterator customIterator = new FileTreeIterator(
                                        nestedRepo, NO_GITLINKS_STRATEGY);
@@ -642,9 +641,8 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
 
        @Test
        public void testCustomFileModeStrategyFromParentIterator() throws Exception {
-               Repository nestedRepo = createNestedRepo();
-
-               try (Git git = new Git(nestedRepo)) {
+               try (Repository nestedRepo = createNestedRepo();
+                               Git git = new Git(nestedRepo)) {
                        FileTreeIterator customIterator = new FileTreeIterator(nestedRepo,
                                        NO_GITLINKS_STRATEGY);
                        File r = new File(nestedRepo.getWorkTree(), "sub");