]> source.dussan.org Git - jgit.git/commitdiff
Fix tests on windows by closing repos 76/38076/2
authorChristian Halstrick <christian.halstrick@sap.com>
Thu, 11 Dec 2014 22:25:09 +0000 (23:25 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 12 Dec 2014 13:49:02 +0000 (14:49 +0100)
Without explicitly closing repos we can't delete the test repositories
on windows.

Change-Id: Id5fa17bd764cbf28703c2f21639d7e969289c2d6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

index 56c1201760453ccc5206aa618bebdbd93582442f..de430fc94f9d0bbf4572e6a37cf42c459dacee2e 100644 (file)
@@ -441,10 +441,10 @@ public class CloneCommandTest extends RepositoryTestCase {
                SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository());
                assertTrue(walk.next());
                Repository clonedSub1 = walk.getRepository();
-               addRepoToClose(clonedSub1);
                assertNotNull(clonedSub1);
                status = new SubmoduleStatusCommand(clonedSub1);
                statuses = status.call();
+               clonedSub1.close();
                pathStatus = statuses.get(path);
                assertNotNull(pathStatus);
                assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());
index 0b523f4f3c7f6b15f2ed72d51898c2f05b9ba19b..1f71402879c18dd2c7e0bfd90d8bc881e4f29518 100644 (file)
@@ -205,8 +205,8 @@ public class CommitCommandTest extends RepositoryTestCase {
                assertEquals(path, generator.getModulesPath());
                assertEquals(uri, generator.getConfigUrl());
                Repository subModRepo = generator.getRepository();
-               addRepoToClose(subModRepo);
                assertNotNull(subModRepo);
+               subModRepo.close();
                assertEquals(commit, repo.resolve(Constants.HEAD));
 
                RevCommit submoduleCommit = git.commit().setMessage("submodule add")
@@ -253,8 +253,8 @@ public class CommitCommandTest extends RepositoryTestCase {
                assertEquals(path, generator.getModulesPath());
                assertEquals(uri, generator.getConfigUrl());
                Repository subModRepo = generator.getRepository();
-               addRepoToClose(subModRepo);
                assertNotNull(subModRepo);
+               subModRepo.close();
                assertEquals(commit2, repo.resolve(Constants.HEAD));
 
                RevCommit submoduleAddCommit = git.commit().setMessage("submodule add")
index d24d375cbc9eb1428492d864b6ca23bc3f60c68d..3d86cfd5bb067a1aa647f697b5a90cca0542ec7b 100644 (file)
@@ -90,24 +90,28 @@ public class RepoCommandTest extends RepositoryTestCase {
                JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "master world");
                git.add().addFilepattern("hello.txt").call();
                git.commit().setMessage("Second commit").call();
+               addRepoToClose(defaultDb);
 
                notDefaultDb = createWorkRepository();
                git = new Git(notDefaultDb);
                JGitTestUtil.writeTrashFile(notDefaultDb, "world.txt", "hello");
                git.add().addFilepattern("world.txt").call();
                git.commit().setMessage("Initial commit").call();
+               addRepoToClose(notDefaultDb);
 
                groupADb = createWorkRepository();
                git = new Git(groupADb);
                JGitTestUtil.writeTrashFile(groupADb, "a.txt", "world");
                git.add().addFilepattern("a.txt").call();
                git.commit().setMessage("Initial commit").call();
+               addRepoToClose(groupADb);
 
                groupBDb = createWorkRepository();
                git = new Git(groupBDb);
                JGitTestUtil.writeTrashFile(groupBDb, "b.txt", "world");
                git.add().addFilepattern("b.txt").call();
                git.commit().setMessage("Initial commit").call();
+               addRepoToClose(groupBDb);
 
                resolveRelativeUris();
        }
@@ -239,45 +243,47 @@ public class RepoCommandTest extends RepositoryTestCase {
        public void testBareRepo() throws Exception {
                Repository remoteDb = createBareRepository();
                Repository tempDb = createWorkRepository();
-               StringBuilder xmlContent = new StringBuilder();
-               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-                       .append("<manifest>")
-                       .append("<remote name=\"remote1\" fetch=\".\" />")
-                       .append("<default revision=\"master\" remote=\"remote1\" />")
-                       .append("<project path=\"foo\" name=\"")
-                       .append(defaultUri)
-                       .append("\" />")
-                       .append("</manifest>");
-               JGitTestUtil.writeTrashFile(
-                               tempDb, "manifest.xml", xmlContent.toString());
-               RepoCommand command = new RepoCommand(remoteDb);
-               command
-                       .setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
-                       .setURI(rootUri)
-                       .call();
-               // Clone it
-               File directory = createTempDirectory("testBareRepo");
-               Repository localDb = Git
-                       .cloneRepository()
-                       .setDirectory(directory)
-                       .setURI(remoteDb.getDirectory().toURI().toString())
-                       .call()
-                       .getRepository();
-               // The .gitmodules file should exist
-               File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
-               assertTrue("The .gitmodules file should exist", gitmodules.exists());
-               // The first line of .gitmodules file should be expected
-               BufferedReader reader = new BufferedReader(new FileReader(gitmodules));
-               String content = reader.readLine();
-               reader.close();
-               assertEquals(
-                               "The first line of .gitmodules file should be as expected",
-                               "[submodule \"foo\"]", content);
-               // The gitlink should be the same as remote head sha1
-               String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
-               String remote = defaultDb.resolve(Constants.HEAD).name();
-               assertEquals("The gitlink should be the same as remote head",
-                               remote, gitlink);
+               try {
+                       StringBuilder xmlContent = new StringBuilder();
+                       xmlContent
+                                       .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                                       .append("<manifest>")
+                                       .append("<remote name=\"remote1\" fetch=\".\" />")
+                                       .append("<default revision=\"master\" remote=\"remote1\" />")
+                                       .append("<project path=\"foo\" name=\"").append(defaultUri)
+                                       .append("\" />").append("</manifest>");
+                       JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
+                                       xmlContent.toString());
+                       RepoCommand command = new RepoCommand(remoteDb);
+                       command.setPath(
+                                       tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+                                       .setURI(rootUri).call();
+                       // Clone it
+                       File directory = createTempDirectory("testBareRepo");
+                       Repository localDb = Git.cloneRepository().setDirectory(directory)
+                                       .setURI(remoteDb.getDirectory().toURI().toString()).call()
+                                       .getRepository();
+                       // The .gitmodules file should exist
+                       File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
+                       assertTrue("The .gitmodules file should exist", gitmodules.exists());
+                       // The first line of .gitmodules file should be expected
+                       BufferedReader reader = new BufferedReader(new FileReader(
+                                       gitmodules));
+                       String content = reader.readLine();
+                       reader.close();
+                       assertEquals(
+                                       "The first line of .gitmodules file should be as expected",
+                                       "[submodule \"foo\"]", content);
+                       // The gitlink should be the same as remote head sha1
+                       String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
+                       localDb.close();
+                       String remote = defaultDb.resolve(Constants.HEAD).name();
+                       assertEquals("The gitlink should be the same as remote head",
+                                       remote, gitlink);
+               } finally {
+                       tempDb.close();
+                       remoteDb.close();
+               }
        }
 
        @Test
@@ -362,213 +368,213 @@ public class RepoCommandTest extends RepositoryTestCase {
        public void testRevisionBare() throws Exception {
                Repository remoteDb = createBareRepository();
                Repository tempDb = createWorkRepository();
-               StringBuilder xmlContent = new StringBuilder();
-               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-                       .append("<manifest>")
-                       .append("<remote name=\"remote1\" fetch=\".\" />")
-                       .append("<default revision=\"")
-                       .append(BRANCH)
-                       .append("\" remote=\"remote1\" />")
-                       .append("<project path=\"foo\" name=\"")
-                       .append(defaultUri)
-                       .append("\" />")
-                       .append("</manifest>");
-               JGitTestUtil.writeTrashFile(
-                               tempDb, "manifest.xml", xmlContent.toString());
-               RepoCommand command = new RepoCommand(remoteDb);
-               command
-                       .setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
-                       .setURI(rootUri)
-                       .call();
-               // Clone it
-               File directory = createTempDirectory("testRevisionBare");
-               Repository localDb = Git
-                       .cloneRepository()
-                       .setDirectory(directory)
-                       .setURI(remoteDb.getDirectory().toURI().toString())
-                       .call()
-                       .getRepository();
-               // The gitlink should be the same as oldCommitId
-               String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
-               assertEquals("The gitlink is same as remote head",
-                               oldCommitId.name(), gitlink);
+               try {
+                       StringBuilder xmlContent = new StringBuilder();
+                       xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                                       .append("<manifest>")
+                                       .append("<remote name=\"remote1\" fetch=\".\" />")
+                                       .append("<default revision=\"").append(BRANCH)
+                                       .append("\" remote=\"remote1\" />")
+                                       .append("<project path=\"foo\" name=\"").append(defaultUri)
+                                       .append("\" />").append("</manifest>");
+                       JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
+                                       xmlContent.toString());
+                       RepoCommand command = new RepoCommand(remoteDb);
+                       command.setPath(
+                                       tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+                                       .setURI(rootUri).call();
+                       // Clone it
+                       File directory = createTempDirectory("testRevisionBare");
+                       Repository localDb = Git.cloneRepository().setDirectory(directory)
+                                       .setURI(remoteDb.getDirectory().toURI().toString()).call()
+                                       .getRepository();
+                       // The gitlink should be the same as oldCommitId
+                       String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
+                       localDb.close();
+                       assertEquals("The gitlink is same as remote head",
+                                       oldCommitId.name(), gitlink);
+               } finally {
+                       tempDb.close();
+                       remoteDb.close();
+               }
        }
 
        @Test
        public void testCopyFileBare() throws Exception {
                Repository remoteDb = createBareRepository();
                Repository tempDb = createWorkRepository();
-               StringBuilder xmlContent = new StringBuilder();
-               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-                       .append("<manifest>")
-                       .append("<remote name=\"remote1\" fetch=\".\" />")
-                       .append("<default revision=\"master\" remote=\"remote1\" />")
-                       .append("<project path=\"foo\" name=\"")
-                       .append(defaultUri)
-                       .append("\" revision=\"")
-                       .append(BRANCH)
-                       .append("\" >")
-                       .append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
-                       .append("</project>")
-                       .append("</manifest>");
-               JGitTestUtil.writeTrashFile(
-                               tempDb, "manifest.xml", xmlContent.toString());
-               RepoCommand command = new RepoCommand(remoteDb);
-               command
-                       .setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
-                       .setURI(rootUri)
-                       .call();
-               // Clone it
-               File directory = createTempDirectory("testCopyFileBare");
-               Repository localDb = Git
-                       .cloneRepository()
-                       .setDirectory(directory)
-                       .setURI(remoteDb.getDirectory().toURI().toString())
-                       .call()
-                       .getRepository();
-               // The Hello file should exist
-               File hello = new File(localDb.getWorkTree(), "Hello");
-               assertTrue("The Hello file should exist", hello.exists());
-               // The content of Hello file should be expected
-               BufferedReader reader = new BufferedReader(new FileReader(hello));
-               String content = reader.readLine();
-               reader.close();
-               assertEquals("The Hello file should have expected content",
-                               "branch world", content);
+               try {
+                       StringBuilder xmlContent = new StringBuilder();
+                       xmlContent
+                                       .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                                       .append("<manifest>")
+                                       .append("<remote name=\"remote1\" fetch=\".\" />")
+                                       .append("<default revision=\"master\" remote=\"remote1\" />")
+                                       .append("<project path=\"foo\" name=\"").append(defaultUri)
+                                       .append("\" revision=\"").append(BRANCH).append("\" >")
+                                       .append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
+                                       .append("</project>").append("</manifest>");
+                       JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
+                                       xmlContent.toString());
+                       RepoCommand command = new RepoCommand(remoteDb);
+                       command.setPath(
+                                       tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+                                       .setURI(rootUri).call();
+                       // Clone it
+                       File directory = createTempDirectory("testCopyFileBare");
+                       Repository localDb = Git.cloneRepository().setDirectory(directory)
+                                       .setURI(remoteDb.getDirectory().toURI().toString()).call()
+                                       .getRepository();
+                       // The Hello file should exist
+                       File hello = new File(localDb.getWorkTree(), "Hello");
+                       localDb.close();
+                       assertTrue("The Hello file should exist", hello.exists());
+                       // The content of Hello file should be expected
+                       BufferedReader reader = new BufferedReader(new FileReader(hello));
+                       String content = reader.readLine();
+                       reader.close();
+                       assertEquals("The Hello file should have expected content",
+                                       "branch world", content);
+               } finally {
+                       tempDb.close();
+                       remoteDb.close();
+               }
        }
 
        @Test
        public void testReplaceManifestBare() throws Exception {
                Repository remoteDb = createBareRepository();
                Repository tempDb = createWorkRepository();
-               StringBuilder xmlContent = new StringBuilder();
-               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-                       .append("<manifest>")
-                       .append("<remote name=\"remote1\" fetch=\".\" />")
-                       .append("<default revision=\"master\" remote=\"remote1\" />")
-                       .append("<project path=\"foo\" name=\"")
-                       .append(defaultUri)
-                       .append("\" revision=\"")
-                       .append(BRANCH)
-                       .append("\" >")
-                       .append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
-                       .append("</project>")
-                       .append("</manifest>");
-               JGitTestUtil.writeTrashFile(tempDb, "old.xml", xmlContent.toString());
-               RepoCommand command = new RepoCommand(remoteDb);
-               command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/old.xml")
-                       .setURI(rootUri)
-                       .call();
-               xmlContent = new StringBuilder();
-               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-                       .append("<manifest>")
-                       .append("<remote name=\"remote1\" fetch=\".\" />")
-                       .append("<default revision=\"master\" remote=\"remote1\" />")
-                       .append("<project path=\"bar\" name=\"")
-                       .append(defaultUri)
-                       .append("\" revision=\"")
-                       .append(BRANCH)
-                       .append("\" >")
-                       .append("<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />")
-                       .append("</project>")
-                       .append("</manifest>");
-               JGitTestUtil.writeTrashFile(tempDb, "new.xml", xmlContent.toString());
-               command = new RepoCommand(remoteDb);
-               command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/new.xml")
-                       .setURI(rootUri)
-                       .call();
-               // Clone it
-               File directory = createTempDirectory("testReplaceManifestBare");
-               Repository localDb = Git
-                       .cloneRepository()
-                       .setDirectory(directory)
-                       .setURI(remoteDb.getDirectory().toURI().toString())
-                       .call()
-                       .getRepository();
-               // The Hello file should not exist
-               File hello = new File(localDb.getWorkTree(), "Hello");
-               assertFalse("The Hello file shouldn't exist", hello.exists());
-               // The Hello.txt file should exist
-               File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
-               assertTrue("The Hello.txt file should exist", hellotxt.exists());
-               // The .gitmodules file should have 'submodule "bar"' and shouldn't have
-               // 'submodule "foo"' lines.
-               File dotmodules = new File(localDb.getWorkTree(),
-                               Constants.DOT_GIT_MODULES);
-               BufferedReader reader = new BufferedReader(new FileReader(dotmodules));
-               boolean foo = false;
-               boolean bar = false;
-               while (true) {
-                       String line = reader.readLine();
-                       if (line == null)
-                               break;
-                       if (line.contains("submodule \"foo\""))
-                               foo = true;
-                       if (line.contains("submodule \"bar\""))
-                               bar = true;
+               try {
+                       StringBuilder xmlContent = new StringBuilder();
+                       xmlContent
+                                       .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                                       .append("<manifest>")
+                                       .append("<remote name=\"remote1\" fetch=\".\" />")
+                                       .append("<default revision=\"master\" remote=\"remote1\" />")
+                                       .append("<project path=\"foo\" name=\"").append(defaultUri)
+                                       .append("\" revision=\"").append(BRANCH).append("\" >")
+                                       .append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
+                                       .append("</project>").append("</manifest>");
+                       JGitTestUtil.writeTrashFile(tempDb, "old.xml",
+                                       xmlContent.toString());
+                       RepoCommand command = new RepoCommand(remoteDb);
+                       command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/old.xml")
+                                       .setURI(rootUri).call();
+                       xmlContent = new StringBuilder();
+                       xmlContent
+                                       .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                                       .append("<manifest>")
+                                       .append("<remote name=\"remote1\" fetch=\".\" />")
+                                       .append("<default revision=\"master\" remote=\"remote1\" />")
+                                       .append("<project path=\"bar\" name=\"")
+                                       .append(defaultUri)
+                                       .append("\" revision=\"")
+                                       .append(BRANCH)
+                                       .append("\" >")
+                                       .append("<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />")
+                                       .append("</project>").append("</manifest>");
+                       JGitTestUtil.writeTrashFile(tempDb, "new.xml",
+                                       xmlContent.toString());
+                       command = new RepoCommand(remoteDb);
+                       command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/new.xml")
+                                       .setURI(rootUri).call();
+                       // Clone it
+                       File directory = createTempDirectory("testReplaceManifestBare");
+                       Repository localDb = Git.cloneRepository().setDirectory(directory)
+                                       .setURI(remoteDb.getDirectory().toURI().toString()).call()
+                                       .getRepository();
+                       // The Hello file should not exist
+                       File hello = new File(localDb.getWorkTree(), "Hello");
+                       assertFalse("The Hello file shouldn't exist", hello.exists());
+                       // The Hello.txt file should exist
+                       File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
+                       assertTrue("The Hello.txt file should exist", hellotxt.exists());
+                       // The .gitmodules file should have 'submodule "bar"' and shouldn't
+                       // have
+                       // 'submodule "foo"' lines.
+                       File dotmodules = new File(localDb.getWorkTree(),
+                                       Constants.DOT_GIT_MODULES);
+                       localDb.close();
+                       BufferedReader reader = new BufferedReader(new FileReader(
+                                       dotmodules));
+                       boolean foo = false;
+                       boolean bar = false;
+                       while (true) {
+                               String line = reader.readLine();
+                               if (line == null)
+                                       break;
+                               if (line.contains("submodule \"foo\""))
+                                       foo = true;
+                               if (line.contains("submodule \"bar\""))
+                                       bar = true;
+                       }
+                       reader.close();
+                       assertTrue("The bar submodule should exist", bar);
+                       assertFalse("The foo submodule shouldn't exist", foo);
+               } finally {
+                       tempDb.close();
+                       remoteDb.close();
                }
-               reader.close();
-               assertTrue("The bar submodule should exist", bar);
-               assertFalse("The foo submodule shouldn't exist", foo);
        }
 
        @Test
        public void testRemoveOverlappingBare() throws Exception {
                Repository remoteDb = createBareRepository();
                Repository tempDb = createWorkRepository();
-               StringBuilder xmlContent = new StringBuilder();
-               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
-                       .append("<manifest>")
-                       .append("<remote name=\"remote1\" fetch=\".\" />")
-                       .append("<default revision=\"master\" remote=\"remote1\" />")
-                       .append("<project path=\"foo/bar\" name=\"")
-                       .append(groupBUri)
-                       .append("\" />")
-                       .append("<project path=\"a\" name=\"")
-                       .append(groupAUri)
-                       .append("\" />")
-                       .append("<project path=\"foo\" name=\"")
-                       .append(defaultUri)
-                       .append("\" />")
-                       .append("</manifest>");
-               JGitTestUtil.writeTrashFile(
-                               tempDb, "manifest.xml", xmlContent.toString());
-               RepoCommand command = new RepoCommand(remoteDb);
-               command
-                       .setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
-                       .setURI(rootUri)
-                       .call();
-               // Clone it
-               File directory = createTempDirectory("testRemoveOverlappingBare");
-               Repository localDb = Git
-                       .cloneRepository()
-                       .setDirectory(directory)
-                       .setURI(remoteDb.getDirectory().toURI().toString())
-                       .call()
-                       .getRepository();
-               // The .gitmodules file should have 'submodule "foo"' and shouldn't have
-               // 'submodule "foo/bar"' lines.
-               File dotmodules = new File(localDb.getWorkTree(),
-                               Constants.DOT_GIT_MODULES);
-               BufferedReader reader = new BufferedReader(new FileReader(dotmodules));
-               boolean foo = false;
-               boolean foobar = false;
-               boolean a = false;
-               while (true) {
-                       String line = reader.readLine();
-                       if (line == null)
-                               break;
-                       if (line.contains("submodule \"foo\""))
-                               foo = true;
-                       if (line.contains("submodule \"foo/bar\""))
-                               foobar = true;
-                       if (line.contains("submodule \"a\""))
-                               a = true;
+               try {
+                       StringBuilder xmlContent = new StringBuilder();
+                       xmlContent
+                                       .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                                       .append("<manifest>")
+                                       .append("<remote name=\"remote1\" fetch=\".\" />")
+                                       .append("<default revision=\"master\" remote=\"remote1\" />")
+                                       .append("<project path=\"foo/bar\" name=\"")
+                                       .append(groupBUri).append("\" />")
+                                       .append("<project path=\"a\" name=\"").append(groupAUri)
+                                       .append("\" />").append("<project path=\"foo\" name=\"")
+                                       .append(defaultUri).append("\" />").append("</manifest>");
+                       JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
+                                       xmlContent.toString());
+                       RepoCommand command = new RepoCommand(remoteDb);
+                       command.setPath(
+                                       tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+                                       .setURI(rootUri).call();
+                       // Clone it
+                       File directory = createTempDirectory("testRemoveOverlappingBare");
+                       Repository localDb = Git.cloneRepository().setDirectory(directory)
+                                       .setURI(remoteDb.getDirectory().toURI().toString()).call()
+                                       .getRepository();
+                       // The .gitmodules file should have 'submodule "foo"' and shouldn't
+                       // have
+                       // 'submodule "foo/bar"' lines.
+                       File dotmodules = new File(localDb.getWorkTree(),
+                                       Constants.DOT_GIT_MODULES);
+                       localDb.close();
+                       BufferedReader reader = new BufferedReader(new FileReader(
+                                       dotmodules));
+                       boolean foo = false;
+                       boolean foobar = false;
+                       boolean a = false;
+                       while (true) {
+                               String line = reader.readLine();
+                               if (line == null)
+                                       break;
+                               if (line.contains("submodule \"foo\""))
+                                       foo = true;
+                               if (line.contains("submodule \"foo/bar\""))
+                                       foobar = true;
+                               if (line.contains("submodule \"a\""))
+                                       a = true;
+                       }
+                       reader.close();
+                       assertTrue("The foo submodule should exist", foo);
+                       assertFalse("The foo/bar submodule shouldn't exist", foobar);
+                       assertTrue("The a submodule should exist", a);
+               } finally {
+                       tempDb.close();
+                       remoteDb.close();
                }
-               reader.close();
-               assertTrue("The foo submodule should exist", foo);
-               assertFalse("The foo/bar submodule shouldn't exist", foobar);
-               assertTrue("The a submodule should exist", a);
        }
 
        @Test
index 8003824d4ecc34eeb9742d14ace8839c5826fc2b..863d79ddee5ea9789c87ffb62f38a4175e6133b0 100644 (file)
@@ -90,7 +90,9 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
                                .setPath("submodule")
                                .setURI(submoduleStandalone.getDirectory().toURI().toString())
                                .call();
+               submoduleStandalone.close();
                submodule_trash = submodule_db.getWorkTree();
+               addRepoToClose(submodule_db);
                writeTrashFile("fileInRoot", "root");
                Git rootGit = Git.wrap(db);
                rootGit.add().addFilepattern("fileInRoot").call();
index b17b991addbc388ba20fdf83c40043ee6957ff51..b13c4cd801fcac0ba4a24be25fb6c5c09ae4219b 100644 (file)
@@ -131,7 +131,8 @@ public class SubmoduleAddTest extends RepositoryTestCase {
                command.setURI(uri);
                Repository repo = command.call();
                assertNotNull(repo);
-               addRepoToClose(repo);
+               ObjectId subCommit = repo.resolve(Constants.HEAD);
+               repo.close();
 
                SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
                assertTrue(generator.next());
@@ -141,9 +142,9 @@ public class SubmoduleAddTest extends RepositoryTestCase {
                assertEquals(path, generator.getModulesPath());
                assertEquals(uri, generator.getConfigUrl());
                Repository subModRepo = generator.getRepository();
-               addRepoToClose(subModRepo);
                assertNotNull(subModRepo);
-               assertEquals(commit, repo.resolve(Constants.HEAD));
+               assertEquals(subCommit, commit);
+               subModRepo.close();
 
                Status status = Git.wrap(db).status().call();
                assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
@@ -206,7 +207,6 @@ public class SubmoduleAddTest extends RepositoryTestCase {
                        fullUri = fullUri.replace('\\', '/');
                assertEquals(fullUri, generator.getConfigUrl());
                Repository subModRepo = generator.getRepository();
-               addRepoToClose(subModRepo);
                assertNotNull(subModRepo);
                assertEquals(
                                fullUri,
@@ -215,6 +215,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
                                                .getString(ConfigConstants.CONFIG_REMOTE_SECTION,
                                                                Constants.DEFAULT_REMOTE_NAME,
                                                                ConfigConstants.CONFIG_KEY_URL));
+               subModRepo.close();
                assertEquals(commit, repo.resolve(Constants.HEAD));
 
                Status status = Git.wrap(db).status().call();
index b00d4528756b7bf7f139f68b9671ff2d25a5f958..54a6f77b45c9f6a7da960731c9a430f1f1faa554 100644 (file)
@@ -135,8 +135,8 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
                assertTrue(generator.next());
                assertEquals(url, generator.getConfigUrl());
                Repository subModRepository = generator.getRepository();
-               addRepoToClose(subModRepository);
                StoredConfig submoduleConfig = subModRepository.getConfig();
+               subModRepository.close();
                assertEquals(url, submoduleConfig.getString(
                                ConfigConstants.CONFIG_REMOTE_SECTION,
                                Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
@@ -207,8 +207,8 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
                assertTrue(generator.next());
                assertEquals("git://server/sub.git", generator.getConfigUrl());
                Repository subModRepository1 = generator.getRepository();
-               addRepoToClose(subModRepository1);
                StoredConfig submoduleConfig = subModRepository1.getConfig();
+               subModRepository1.close();
                assertEquals("git://server/sub.git", submoduleConfig.getString(
                                ConfigConstants.CONFIG_REMOTE_SECTION,
                                Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
index eac4c873fb02cde1d2f3168157a94dd6d28d2932..bcdd5e21b6dd26d54a406c2d0d0e92d556ffc6e5 100644 (file)
@@ -121,9 +121,9 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
                SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
                assertTrue(generator.next());
                Repository subRepo = generator.getRepository();
-               addRepoToClose(subRepo);
                assertNotNull(subRepo);
                assertEquals(commit, subRepo.resolve(Constants.HEAD));
+               subRepo.close();
        }
 
        @Test
index 251938fece7916326a5e4d32ee318f7430bd4a77..f7acaa788064c8c0a147172a3f755d903f009f3b 100644 (file)
@@ -175,12 +175,12 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
                assertNull(gen.getModulesUpdate());
                assertNull(gen.getModulesUrl());
                Repository subRepo = gen.getRepository();
-               addRepoToClose(subRepo);
                assertNotNull(subRepo);
                assertEquals(modulesGitDir.getAbsolutePath(),
                                subRepo.getDirectory().getAbsolutePath());
                assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(),
                                subRepo.getWorkTree().getAbsolutePath());
+               subRepo.close();
                assertFalse(gen.next());
        }
 
@@ -227,11 +227,11 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
                assertNull(gen.getModulesUpdate());
                assertNull(gen.getModulesUrl());
                Repository subRepo = gen.getRepository();
-               addRepoToClose(subRepo);
                assertNotNull(subRepo);
                assertEqualsFile(modulesGitDir, subRepo.getDirectory());
                assertEqualsFile(new File(db.getWorkTree(), path),
                                subRepo.getWorkTree());
+               subRepo.close();
                assertFalse(gen.next());
        }
 
index d62b1f58a05975c0cb04e7218881ce4342117dba..1b049f61559303ac414182977623ec85b8467751 100644 (file)
@@ -533,28 +533,35 @@ public class IndexDiff {
                                }
                                Repository subRepo = smw.getRepository();
                                if (subRepo != null) {
-                                       ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$
-                                       if (subHead != null && !subHead.equals(smw.getObjectId()))
-                                               modified.add(smw.getPath());
-                                       else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
-                                               IndexDiff smid = submoduleIndexDiffs.get(smw.getPath());
-                                               if (smid == null) {
-                                                       smid = new IndexDiff(subRepo, smw.getObjectId(),
-                                                                       wTreeIt.getWorkingTreeIterator(subRepo));
-                                                       submoduleIndexDiffs.put(smw.getPath(), smid);
-                                               }
-                                               if (smid.diff()) {
-                                                       if (ignoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED
-                                                                       && smid.getAdded().isEmpty()
-                                                                       && smid.getChanged().isEmpty()
-                                                                       && smid.getConflicting().isEmpty()
-                                                                       && smid.getMissing().isEmpty()
-                                                                       && smid.getModified().isEmpty()
-                                                                       && smid.getRemoved().isEmpty()) {
-                                                               continue;
-                                                       }
+                                       try {
+                                               ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$
+                                               if (subHead != null
+                                                               && !subHead.equals(smw.getObjectId()))
                                                        modified.add(smw.getPath());
+                                               else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
+                                                       IndexDiff smid = submoduleIndexDiffs.get(smw
+                                                                       .getPath());
+                                                       if (smid == null) {
+                                                               smid = new IndexDiff(subRepo,
+                                                                               smw.getObjectId(),
+                                                                               wTreeIt.getWorkingTreeIterator(subRepo));
+                                                               submoduleIndexDiffs.put(smw.getPath(), smid);
+                                                       }
+                                                       if (smid.diff()) {
+                                                               if (ignoreSubmoduleMode == IgnoreSubmoduleMode.UNTRACKED
+                                                                               && smid.getAdded().isEmpty()
+                                                                               && smid.getChanged().isEmpty()
+                                                                               && smid.getConflicting().isEmpty()
+                                                                               && smid.getMissing().isEmpty()
+                                                                               && smid.getModified().isEmpty()
+                                                                               && smid.getRemoved().isEmpty()) {
+                                                                       continue;
+                                                               }
+                                                               modified.add(smw.getPath());
+                                                       }
                                                }
+                                       } finally {
+                                               subRepo.close();
                                        }
                                }
                        }