Merge "Fix tests on windows by closing repos" into stable-3.6

This commit is contained in:
Matthias Sohn 2014-12-12 08:50:20 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit ca7c928eae
9 changed files with 274 additions and 258 deletions

View File

@ -441,10 +441,10 @@ public void testCloneRepositoryWithNestedSubmodules() throws Exception {
SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository()); SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository());
assertTrue(walk.next()); assertTrue(walk.next());
Repository clonedSub1 = walk.getRepository(); Repository clonedSub1 = walk.getRepository();
addRepoToClose(clonedSub1);
assertNotNull(clonedSub1); assertNotNull(clonedSub1);
status = new SubmoduleStatusCommand(clonedSub1); status = new SubmoduleStatusCommand(clonedSub1);
statuses = status.call(); statuses = status.call();
clonedSub1.close();
pathStatus = statuses.get(path); pathStatus = statuses.get(path);
assertNotNull(pathStatus); assertNotNull(pathStatus);
assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType()); assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());

View File

@ -205,8 +205,8 @@ public void commitNewSubmodule() throws Exception {
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
Repository subModRepo = generator.getRepository(); Repository subModRepo = generator.getRepository();
addRepoToClose(subModRepo);
assertNotNull(subModRepo); assertNotNull(subModRepo);
subModRepo.close();
assertEquals(commit, repo.resolve(Constants.HEAD)); assertEquals(commit, repo.resolve(Constants.HEAD));
RevCommit submoduleCommit = git.commit().setMessage("submodule add") RevCommit submoduleCommit = git.commit().setMessage("submodule add")
@ -253,8 +253,8 @@ public void commitSubmoduleUpdate() throws Exception {
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
Repository subModRepo = generator.getRepository(); Repository subModRepo = generator.getRepository();
addRepoToClose(subModRepo);
assertNotNull(subModRepo); assertNotNull(subModRepo);
subModRepo.close();
assertEquals(commit2, repo.resolve(Constants.HEAD)); assertEquals(commit2, repo.resolve(Constants.HEAD));
RevCommit submoduleAddCommit = git.commit().setMessage("submodule add") RevCommit submoduleAddCommit = git.commit().setMessage("submodule add")

View File

@ -90,24 +90,28 @@ public void setUp() throws Exception {
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "master world"); JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "master world");
git.add().addFilepattern("hello.txt").call(); git.add().addFilepattern("hello.txt").call();
git.commit().setMessage("Second commit").call(); git.commit().setMessage("Second commit").call();
addRepoToClose(defaultDb);
notDefaultDb = createWorkRepository(); notDefaultDb = createWorkRepository();
git = new Git(notDefaultDb); git = new Git(notDefaultDb);
JGitTestUtil.writeTrashFile(notDefaultDb, "world.txt", "hello"); JGitTestUtil.writeTrashFile(notDefaultDb, "world.txt", "hello");
git.add().addFilepattern("world.txt").call(); git.add().addFilepattern("world.txt").call();
git.commit().setMessage("Initial commit").call(); git.commit().setMessage("Initial commit").call();
addRepoToClose(notDefaultDb);
groupADb = createWorkRepository(); groupADb = createWorkRepository();
git = new Git(groupADb); git = new Git(groupADb);
JGitTestUtil.writeTrashFile(groupADb, "a.txt", "world"); JGitTestUtil.writeTrashFile(groupADb, "a.txt", "world");
git.add().addFilepattern("a.txt").call(); git.add().addFilepattern("a.txt").call();
git.commit().setMessage("Initial commit").call(); git.commit().setMessage("Initial commit").call();
addRepoToClose(groupADb);
groupBDb = createWorkRepository(); groupBDb = createWorkRepository();
git = new Git(groupBDb); git = new Git(groupBDb);
JGitTestUtil.writeTrashFile(groupBDb, "b.txt", "world"); JGitTestUtil.writeTrashFile(groupBDb, "b.txt", "world");
git.add().addFilepattern("b.txt").call(); git.add().addFilepattern("b.txt").call();
git.commit().setMessage("Initial commit").call(); git.commit().setMessage("Initial commit").call();
addRepoToClose(groupBDb);
resolveRelativeUris(); resolveRelativeUris();
} }
@ -239,35 +243,32 @@ public void testRepoManifestCopyFile() throws Exception {
public void testBareRepo() throws Exception { public void testBareRepo() throws Exception {
Repository remoteDb = createBareRepository(); Repository remoteDb = createBareRepository();
Repository tempDb = createWorkRepository(); Repository tempDb = createWorkRepository();
try {
StringBuilder xmlContent = new StringBuilder(); StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>") .append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />") .append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />") .append("<default revision=\"master\" remote=\"remote1\" />")
.append("<project path=\"foo\" name=\"") .append("<project path=\"foo\" name=\"").append(defaultUri)
.append(defaultUri) .append("\" />").append("</manifest>");
.append("\" />") JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
.append("</manifest>"); xmlContent.toString());
JGitTestUtil.writeTrashFile(
tempDb, "manifest.xml", xmlContent.toString());
RepoCommand command = new RepoCommand(remoteDb); RepoCommand command = new RepoCommand(remoteDb);
command command.setPath(
.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
.setURI(rootUri) .setURI(rootUri).call();
.call();
// Clone it // Clone it
File directory = createTempDirectory("testBareRepo"); File directory = createTempDirectory("testBareRepo");
Repository localDb = Git Repository localDb = Git.cloneRepository().setDirectory(directory)
.cloneRepository() .setURI(remoteDb.getDirectory().toURI().toString()).call()
.setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString())
.call()
.getRepository(); .getRepository();
// The .gitmodules file should exist // The .gitmodules file should exist
File gitmodules = new File(localDb.getWorkTree(), ".gitmodules"); File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
assertTrue("The .gitmodules file should exist", gitmodules.exists()); assertTrue("The .gitmodules file should exist", gitmodules.exists());
// The first line of .gitmodules file should be expected // The first line of .gitmodules file should be expected
BufferedReader reader = new BufferedReader(new FileReader(gitmodules)); BufferedReader reader = new BufferedReader(new FileReader(
gitmodules));
String content = reader.readLine(); String content = reader.readLine();
reader.close(); reader.close();
assertEquals( assertEquals(
@ -275,9 +276,14 @@ public void testBareRepo() throws Exception {
"[submodule \"foo\"]", content); "[submodule \"foo\"]", content);
// The gitlink should be the same as remote head sha1 // The gitlink should be the same as remote head sha1
String gitlink = localDb.resolve(Constants.HEAD + ":foo").name(); String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
localDb.close();
String remote = defaultDb.resolve(Constants.HEAD).name(); String remote = defaultDb.resolve(Constants.HEAD).name();
assertEquals("The gitlink should be the same as remote head", assertEquals("The gitlink should be the same as remote head",
remote, gitlink); remote, gitlink);
} finally {
tempDb.close();
remoteDb.close();
}
} }
@Test @Test
@ -362,72 +368,66 @@ public void testRevisionTag() throws Exception {
public void testRevisionBare() throws Exception { public void testRevisionBare() throws Exception {
Repository remoteDb = createBareRepository(); Repository remoteDb = createBareRepository();
Repository tempDb = createWorkRepository(); Repository tempDb = createWorkRepository();
try {
StringBuilder xmlContent = new StringBuilder(); StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>") .append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />") .append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"") .append("<default revision=\"").append(BRANCH)
.append(BRANCH)
.append("\" remote=\"remote1\" />") .append("\" remote=\"remote1\" />")
.append("<project path=\"foo\" name=\"") .append("<project path=\"foo\" name=\"").append(defaultUri)
.append(defaultUri) .append("\" />").append("</manifest>");
.append("\" />") JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
.append("</manifest>"); xmlContent.toString());
JGitTestUtil.writeTrashFile(
tempDb, "manifest.xml", xmlContent.toString());
RepoCommand command = new RepoCommand(remoteDb); RepoCommand command = new RepoCommand(remoteDb);
command command.setPath(
.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
.setURI(rootUri) .setURI(rootUri).call();
.call();
// Clone it // Clone it
File directory = createTempDirectory("testRevisionBare"); File directory = createTempDirectory("testRevisionBare");
Repository localDb = Git Repository localDb = Git.cloneRepository().setDirectory(directory)
.cloneRepository() .setURI(remoteDb.getDirectory().toURI().toString()).call()
.setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString())
.call()
.getRepository(); .getRepository();
// The gitlink should be the same as oldCommitId // The gitlink should be the same as oldCommitId
String gitlink = localDb.resolve(Constants.HEAD + ":foo").name(); String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
localDb.close();
assertEquals("The gitlink is same as remote head", assertEquals("The gitlink is same as remote head",
oldCommitId.name(), gitlink); oldCommitId.name(), gitlink);
} finally {
tempDb.close();
remoteDb.close();
}
} }
@Test @Test
public void testCopyFileBare() throws Exception { public void testCopyFileBare() throws Exception {
Repository remoteDb = createBareRepository(); Repository remoteDb = createBareRepository();
Repository tempDb = createWorkRepository(); Repository tempDb = createWorkRepository();
try {
StringBuilder xmlContent = new StringBuilder(); StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>") .append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />") .append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />") .append("<default revision=\"master\" remote=\"remote1\" />")
.append("<project path=\"foo\" name=\"") .append("<project path=\"foo\" name=\"").append(defaultUri)
.append(defaultUri) .append("\" revision=\"").append(BRANCH).append("\" >")
.append("\" revision=\"")
.append(BRANCH)
.append("\" >")
.append("<copyfile src=\"hello.txt\" dest=\"Hello\" />") .append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
.append("</project>") .append("</project>").append("</manifest>");
.append("</manifest>"); JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
JGitTestUtil.writeTrashFile( xmlContent.toString());
tempDb, "manifest.xml", xmlContent.toString());
RepoCommand command = new RepoCommand(remoteDb); RepoCommand command = new RepoCommand(remoteDb);
command command.setPath(
.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
.setURI(rootUri) .setURI(rootUri).call();
.call();
// Clone it // Clone it
File directory = createTempDirectory("testCopyFileBare"); File directory = createTempDirectory("testCopyFileBare");
Repository localDb = Git Repository localDb = Git.cloneRepository().setDirectory(directory)
.cloneRepository() .setURI(remoteDb.getDirectory().toURI().toString()).call()
.setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString())
.call()
.getRepository(); .getRepository();
// The Hello file should exist // The Hello file should exist
File hello = new File(localDb.getWorkTree(), "Hello"); File hello = new File(localDb.getWorkTree(), "Hello");
localDb.close();
assertTrue("The Hello file should exist", hello.exists()); assertTrue("The Hello file should exist", hello.exists());
// The content of Hello file should be expected // The content of Hello file should be expected
BufferedReader reader = new BufferedReader(new FileReader(hello)); BufferedReader reader = new BufferedReader(new FileReader(hello));
@ -435,32 +435,35 @@ public void testCopyFileBare() throws Exception {
reader.close(); reader.close();
assertEquals("The Hello file should have expected content", assertEquals("The Hello file should have expected content",
"branch world", content); "branch world", content);
} finally {
tempDb.close();
remoteDb.close();
}
} }
@Test @Test
public void testReplaceManifestBare() throws Exception { public void testReplaceManifestBare() throws Exception {
Repository remoteDb = createBareRepository(); Repository remoteDb = createBareRepository();
Repository tempDb = createWorkRepository(); Repository tempDb = createWorkRepository();
try {
StringBuilder xmlContent = new StringBuilder(); StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>") .append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />") .append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />") .append("<default revision=\"master\" remote=\"remote1\" />")
.append("<project path=\"foo\" name=\"") .append("<project path=\"foo\" name=\"").append(defaultUri)
.append(defaultUri) .append("\" revision=\"").append(BRANCH).append("\" >")
.append("\" revision=\"")
.append(BRANCH)
.append("\" >")
.append("<copyfile src=\"hello.txt\" dest=\"Hello\" />") .append("<copyfile src=\"hello.txt\" dest=\"Hello\" />")
.append("</project>") .append("</project>").append("</manifest>");
.append("</manifest>"); JGitTestUtil.writeTrashFile(tempDb, "old.xml",
JGitTestUtil.writeTrashFile(tempDb, "old.xml", xmlContent.toString()); xmlContent.toString());
RepoCommand command = new RepoCommand(remoteDb); RepoCommand command = new RepoCommand(remoteDb);
command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/old.xml") command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/old.xml")
.setURI(rootUri) .setURI(rootUri).call();
.call();
xmlContent = new StringBuilder(); xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>") .append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />") .append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />") .append("<default revision=\"master\" remote=\"remote1\" />")
@ -470,20 +473,16 @@ public void testReplaceManifestBare() throws Exception {
.append(BRANCH) .append(BRANCH)
.append("\" >") .append("\" >")
.append("<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />") .append("<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />")
.append("</project>") .append("</project>").append("</manifest>");
.append("</manifest>"); JGitTestUtil.writeTrashFile(tempDb, "new.xml",
JGitTestUtil.writeTrashFile(tempDb, "new.xml", xmlContent.toString()); xmlContent.toString());
command = new RepoCommand(remoteDb); command = new RepoCommand(remoteDb);
command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/new.xml") command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/new.xml")
.setURI(rootUri) .setURI(rootUri).call();
.call();
// Clone it // Clone it
File directory = createTempDirectory("testReplaceManifestBare"); File directory = createTempDirectory("testReplaceManifestBare");
Repository localDb = Git Repository localDb = Git.cloneRepository().setDirectory(directory)
.cloneRepository() .setURI(remoteDb.getDirectory().toURI().toString()).call()
.setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString())
.call()
.getRepository(); .getRepository();
// The Hello file should not exist // The Hello file should not exist
File hello = new File(localDb.getWorkTree(), "Hello"); File hello = new File(localDb.getWorkTree(), "Hello");
@ -491,11 +490,14 @@ public void testReplaceManifestBare() throws Exception {
// The Hello.txt file should exist // The Hello.txt file should exist
File hellotxt = new File(localDb.getWorkTree(), "Hello.txt"); File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
assertTrue("The Hello.txt file should exist", hellotxt.exists()); assertTrue("The Hello.txt file should exist", hellotxt.exists());
// The .gitmodules file should have 'submodule "bar"' and shouldn't have // The .gitmodules file should have 'submodule "bar"' and shouldn't
// have
// 'submodule "foo"' lines. // 'submodule "foo"' lines.
File dotmodules = new File(localDb.getWorkTree(), File dotmodules = new File(localDb.getWorkTree(),
Constants.DOT_GIT_MODULES); Constants.DOT_GIT_MODULES);
BufferedReader reader = new BufferedReader(new FileReader(dotmodules)); localDb.close();
BufferedReader reader = new BufferedReader(new FileReader(
dotmodules));
boolean foo = false; boolean foo = false;
boolean bar = false; boolean bar = false;
while (true) { while (true) {
@ -510,47 +512,47 @@ public void testReplaceManifestBare() throws Exception {
reader.close(); reader.close();
assertTrue("The bar submodule should exist", bar); assertTrue("The bar submodule should exist", bar);
assertFalse("The foo submodule shouldn't exist", foo); assertFalse("The foo submodule shouldn't exist", foo);
} finally {
tempDb.close();
remoteDb.close();
}
} }
@Test @Test
public void testRemoveOverlappingBare() throws Exception { public void testRemoveOverlappingBare() throws Exception {
Repository remoteDb = createBareRepository(); Repository remoteDb = createBareRepository();
Repository tempDb = createWorkRepository(); Repository tempDb = createWorkRepository();
try {
StringBuilder xmlContent = new StringBuilder(); StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>") .append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />") .append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />") .append("<default revision=\"master\" remote=\"remote1\" />")
.append("<project path=\"foo/bar\" name=\"") .append("<project path=\"foo/bar\" name=\"")
.append(groupBUri) .append(groupBUri).append("\" />")
.append("\" />") .append("<project path=\"a\" name=\"").append(groupAUri)
.append("<project path=\"a\" name=\"") .append("\" />").append("<project path=\"foo\" name=\"")
.append(groupAUri) .append(defaultUri).append("\" />").append("</manifest>");
.append("\" />") JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
.append("<project path=\"foo\" name=\"") xmlContent.toString());
.append(defaultUri)
.append("\" />")
.append("</manifest>");
JGitTestUtil.writeTrashFile(
tempDb, "manifest.xml", xmlContent.toString());
RepoCommand command = new RepoCommand(remoteDb); RepoCommand command = new RepoCommand(remoteDb);
command command.setPath(
.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
.setURI(rootUri) .setURI(rootUri).call();
.call();
// Clone it // Clone it
File directory = createTempDirectory("testRemoveOverlappingBare"); File directory = createTempDirectory("testRemoveOverlappingBare");
Repository localDb = Git Repository localDb = Git.cloneRepository().setDirectory(directory)
.cloneRepository() .setURI(remoteDb.getDirectory().toURI().toString()).call()
.setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString())
.call()
.getRepository(); .getRepository();
// The .gitmodules file should have 'submodule "foo"' and shouldn't have // The .gitmodules file should have 'submodule "foo"' and shouldn't
// have
// 'submodule "foo/bar"' lines. // 'submodule "foo/bar"' lines.
File dotmodules = new File(localDb.getWorkTree(), File dotmodules = new File(localDb.getWorkTree(),
Constants.DOT_GIT_MODULES); Constants.DOT_GIT_MODULES);
BufferedReader reader = new BufferedReader(new FileReader(dotmodules)); localDb.close();
BufferedReader reader = new BufferedReader(new FileReader(
dotmodules));
boolean foo = false; boolean foo = false;
boolean foobar = false; boolean foobar = false;
boolean a = false; boolean a = false;
@ -569,6 +571,10 @@ public void testRemoveOverlappingBare() throws Exception {
assertTrue("The foo submodule should exist", foo); assertTrue("The foo submodule should exist", foo);
assertFalse("The foo/bar submodule shouldn't exist", foobar); assertFalse("The foo/bar submodule shouldn't exist", foobar);
assertTrue("The a submodule should exist", a); assertTrue("The a submodule should exist", a);
} finally {
tempDb.close();
remoteDb.close();
}
} }
@Test @Test

View File

@ -90,7 +90,9 @@ public void setUp() throws Exception {
.setPath("submodule") .setPath("submodule")
.setURI(submoduleStandalone.getDirectory().toURI().toString()) .setURI(submoduleStandalone.getDirectory().toURI().toString())
.call(); .call();
submoduleStandalone.close();
submodule_trash = submodule_db.getWorkTree(); submodule_trash = submodule_db.getWorkTree();
addRepoToClose(submodule_db);
writeTrashFile("fileInRoot", "root"); writeTrashFile("fileInRoot", "root");
Git rootGit = Git.wrap(db); Git rootGit = Git.wrap(db);
rootGit.add().addFilepattern("fileInRoot").call(); rootGit.add().addFilepattern("fileInRoot").call();

View File

@ -131,7 +131,8 @@ public void addSubmodule() throws Exception {
command.setURI(uri); command.setURI(uri);
Repository repo = command.call(); Repository repo = command.call();
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); ObjectId subCommit = repo.resolve(Constants.HEAD);
repo.close();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next()); assertTrue(generator.next());
@ -141,9 +142,9 @@ public void addSubmodule() throws Exception {
assertEquals(path, generator.getModulesPath()); assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl()); assertEquals(uri, generator.getConfigUrl());
Repository subModRepo = generator.getRepository(); Repository subModRepo = generator.getRepository();
addRepoToClose(subModRepo);
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals(commit, repo.resolve(Constants.HEAD)); assertEquals(subCommit, commit);
subModRepo.close();
Status status = Git.wrap(db).status().call(); Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES)); assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
@ -206,7 +207,6 @@ public void addSubmoduleWithRelativeUri() throws Exception {
fullUri = fullUri.replace('\\', '/'); fullUri = fullUri.replace('\\', '/');
assertEquals(fullUri, generator.getConfigUrl()); assertEquals(fullUri, generator.getConfigUrl());
Repository subModRepo = generator.getRepository(); Repository subModRepo = generator.getRepository();
addRepoToClose(subModRepo);
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals( assertEquals(
fullUri, fullUri,
@ -215,6 +215,7 @@ public void addSubmoduleWithRelativeUri() throws Exception {
.getString(ConfigConstants.CONFIG_REMOTE_SECTION, .getString(ConfigConstants.CONFIG_REMOTE_SECTION,
Constants.DEFAULT_REMOTE_NAME, Constants.DEFAULT_REMOTE_NAME,
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
subModRepo.close();
assertEquals(commit, repo.resolve(Constants.HEAD)); assertEquals(commit, repo.resolve(Constants.HEAD));
Status status = Git.wrap(db).status().call(); Status status = Git.wrap(db).status().call();

View File

@ -135,8 +135,8 @@ public void apply(DirCacheEntry ent) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl()); assertEquals(url, generator.getConfigUrl());
Repository subModRepository = generator.getRepository(); Repository subModRepository = generator.getRepository();
addRepoToClose(subModRepository);
StoredConfig submoduleConfig = subModRepository.getConfig(); StoredConfig submoduleConfig = subModRepository.getConfig();
subModRepository.close();
assertEquals(url, submoduleConfig.getString( assertEquals(url, submoduleConfig.getString(
ConfigConstants.CONFIG_REMOTE_SECTION, ConfigConstants.CONFIG_REMOTE_SECTION,
Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
@ -207,8 +207,8 @@ public void apply(DirCacheEntry ent) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl()); assertEquals("git://server/sub.git", generator.getConfigUrl());
Repository subModRepository1 = generator.getRepository(); Repository subModRepository1 = generator.getRepository();
addRepoToClose(subModRepository1);
StoredConfig submoduleConfig = subModRepository1.getConfig(); StoredConfig submoduleConfig = subModRepository1.getConfig();
subModRepository1.close();
assertEquals("git://server/sub.git", submoduleConfig.getString( assertEquals("git://server/sub.git", submoduleConfig.getString(
ConfigConstants.CONFIG_REMOTE_SECTION, ConfigConstants.CONFIG_REMOTE_SECTION,
Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL)); Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));

View File

@ -121,9 +121,9 @@ public void apply(DirCacheEntry ent) {
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next()); assertTrue(generator.next());
Repository subRepo = generator.getRepository(); Repository subRepo = generator.getRepository();
addRepoToClose(subRepo);
assertNotNull(subRepo); assertNotNull(subRepo);
assertEquals(commit, subRepo.resolve(Constants.HEAD)); assertEquals(commit, subRepo.resolve(Constants.HEAD));
subRepo.close();
} }
@Test @Test

View File

@ -175,12 +175,12 @@ public void apply(DirCacheEntry ent) {
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
Repository subRepo = gen.getRepository(); Repository subRepo = gen.getRepository();
addRepoToClose(subRepo);
assertNotNull(subRepo); assertNotNull(subRepo);
assertEquals(modulesGitDir.getAbsolutePath(), assertEquals(modulesGitDir.getAbsolutePath(),
subRepo.getDirectory().getAbsolutePath()); subRepo.getDirectory().getAbsolutePath());
assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(), assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(),
subRepo.getWorkTree().getAbsolutePath()); subRepo.getWorkTree().getAbsolutePath());
subRepo.close();
assertFalse(gen.next()); assertFalse(gen.next());
} }
@ -227,11 +227,11 @@ public void apply(DirCacheEntry ent) {
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
Repository subRepo = gen.getRepository(); Repository subRepo = gen.getRepository();
addRepoToClose(subRepo);
assertNotNull(subRepo); assertNotNull(subRepo);
assertEqualsFile(modulesGitDir, subRepo.getDirectory()); assertEqualsFile(modulesGitDir, subRepo.getDirectory());
assertEqualsFile(new File(db.getWorkTree(), path), assertEqualsFile(new File(db.getWorkTree(), path),
subRepo.getWorkTree()); subRepo.getWorkTree());
subRepo.close();
assertFalse(gen.next()); assertFalse(gen.next());
} }

View File

@ -533,13 +533,17 @@ public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize,
} }
Repository subRepo = smw.getRepository(); Repository subRepo = smw.getRepository();
if (subRepo != null) { if (subRepo != null) {
try {
ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$ ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$
if (subHead != null && !subHead.equals(smw.getObjectId())) if (subHead != null
&& !subHead.equals(smw.getObjectId()))
modified.add(smw.getPath()); modified.add(smw.getPath());
else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) { else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
IndexDiff smid = submoduleIndexDiffs.get(smw.getPath()); IndexDiff smid = submoduleIndexDiffs.get(smw
.getPath());
if (smid == null) { if (smid == null) {
smid = new IndexDiff(subRepo, smw.getObjectId(), smid = new IndexDiff(subRepo,
smw.getObjectId(),
wTreeIt.getWorkingTreeIterator(subRepo)); wTreeIt.getWorkingTreeIterator(subRepo));
submoduleIndexDiffs.put(smw.getPath(), smid); submoduleIndexDiffs.put(smw.getPath(), smid);
} }
@ -556,6 +560,9 @@ else if (ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY) {
modified.add(smw.getPath()); modified.add(smw.getPath());
} }
} }
} finally {
subRepo.close();
}
} }
} }