Browse Source

Close SubmoduleWalks in tests

Change-Id: If1b9d80830b6b136d4ab33f5c7043b140bd92f85
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
next
Thomas Wolf 5 years ago
parent
commit
5e0eca6943
  1. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
  2. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
  3. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java
  4. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
  5. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java
  6. 42
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java
  7. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
  8. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
  9. 35
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java

@ -646,7 +646,8 @@ public class CloneCommandTest extends RepositoryTestCase {
assertEquals(sub1Head, pathStatus.getHeadId()); assertEquals(sub1Head, pathStatus.getHeadId());
assertEquals(sub1Head, pathStatus.getIndexId()); assertEquals(sub1Head, pathStatus.getIndexId());
SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository()); try (SubmoduleWalk walk = SubmoduleWalk
.forIndex(git2.getRepository())) {
assertTrue(walk.next()); assertTrue(walk.next());
try (Repository clonedSub1 = walk.getRepository()) { try (Repository clonedSub1 = walk.getRepository()) {
assertNotNull(clonedSub1); assertNotNull(clonedSub1);
@ -659,12 +660,13 @@ public class CloneCommandTest extends RepositoryTestCase {
status = new SubmoduleStatusCommand(clonedSub1); status = new SubmoduleStatusCommand(clonedSub1);
statuses = status.call(); statuses = status.call();
} }
assertFalse(walk.next());
}
pathStatus = statuses.get(path); pathStatus = statuses.get(path);
assertNotNull(pathStatus); assertNotNull(pathStatus);
assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType()); assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());
assertEquals(sub2Head, pathStatus.getHeadId()); assertEquals(sub2Head, pathStatus.getHeadId());
assertEquals(sub2Head, pathStatus.getIndexId()); assertEquals(sub2Head, pathStatus.getIndexId());
assertFalse(walk.next());
} }
@Test @Test

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java

@ -148,9 +148,10 @@ public class CommitCommandTest extends RepositoryTestCase {
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
RevCommit commit1 = git.commit().setMessage("commit").call(); RevCommit commit1 = git.commit().setMessage("commit").call();
TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree()); try (TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree())) {
assertNotNull(walk); assertNotNull(walk);
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
}
FS nonExecutableFs = new FS() { FS nonExecutableFs = new FS() {
@ -204,10 +205,11 @@ public class CommitCommandTest extends RepositoryTestCase {
writeTrashFile(path, "content2"); writeTrashFile(path, "content2");
RevCommit commit2 = git2.commit().setOnly(path).setMessage("commit2") RevCommit commit2 = git2.commit().setOnly(path).setMessage("commit2")
.call(); .call();
walk = TreeWalk.forPath(db, path, commit2.getTree()); try (TreeWalk walk = TreeWalk.forPath(db, path, commit2.getTree())) {
assertNotNull(walk); assertNotNull(walk);
assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0)); assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
} }
}
@Test @Test
public void commitNewSubmodule() throws Exception { public void commitNewSubmodule() throws Exception {
@ -225,7 +227,7 @@ public class CommitCommandTest extends RepositoryTestCase {
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); addRepoToClose(repo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId()); assertEquals(commit, generator.getObjectId());
@ -235,6 +237,7 @@ public class CommitCommandTest extends RepositoryTestCase {
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
} }
}
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")
@ -275,7 +278,7 @@ public class CommitCommandTest extends RepositoryTestCase {
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); addRepoToClose(repo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit2, generator.getObjectId()); assertEquals(commit2, generator.getObjectId());
@ -285,6 +288,7 @@ public class CommitCommandTest extends RepositoryTestCase {
try (Repository subModRepo = generator.getRepository()) { try (Repository subModRepo = generator.getRepository()) {
assertNotNull(subModRepo); assertNotNull(subModRepo);
} }
}
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")

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchAndPullCommandsRecurseSubmodulesTest.java

@ -343,19 +343,22 @@ public class FetchAndPullCommandsRecurseSubmodulesTest extends RepositoryTestCas
private void assertSubmoduleFetchHeads(ObjectId expectedHead1, private void assertSubmoduleFetchHeads(ObjectId expectedHead1,
ObjectId expectedHead2) throws Exception { ObjectId expectedHead2) throws Exception {
Object newHead1 = null;
ObjectId newHead2 = null;
try (SubmoduleWalk walk = SubmoduleWalk try (SubmoduleWalk walk = SubmoduleWalk
.forIndex(git2.getRepository())) { .forIndex(git2.getRepository())) {
assertTrue(walk.next()); assertTrue(walk.next());
Repository r = walk.getRepository(); try (Repository r = walk.getRepository()) {
ObjectId newHead1 = r.resolve(Constants.FETCH_HEAD); newHead1 = r.resolve(Constants.FETCH_HEAD);
ObjectId newHead2;
try (SubmoduleWalk walk2 = SubmoduleWalk.forIndex(r)) { try (SubmoduleWalk walk2 = SubmoduleWalk.forIndex(r)) {
assertTrue(walk2.next()); assertTrue(walk2.next());
newHead2 = walk2.getRepository().resolve(Constants.FETCH_HEAD); try (Repository r2 = walk2.getRepository()) {
newHead2 = r2.resolve(Constants.FETCH_HEAD);
}
}
}
} }
assertEquals(expectedHead1, newHead1); assertEquals(expectedHead1, newHead1);
assertEquals(expectedHead2, newHead2); assertEquals(expectedHead2, newHead2);
} }
}
} }

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java

@ -135,7 +135,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
subCommit = repo.resolve(Constants.HEAD); subCommit = repo.resolve(Constants.HEAD);
} }
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
generator.loadModulesConfig(); generator.loadModulesConfig();
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getModuleName()); assertEquals(path, generator.getModuleName());
@ -148,7 +148,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals(subCommit, commit); assertEquals(subCommit, commit);
} }
}
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));
assertTrue(status.getAdded().contains(path)); assertTrue(status.getAdded().contains(path));
@ -175,7 +175,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
subCommit = repo.resolve(Constants.HEAD); subCommit = repo.resolve(Constants.HEAD);
} }
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
generator.loadModulesConfig(); generator.loadModulesConfig();
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(name, generator.getModuleName()); assertEquals(name, generator.getModuleName());
@ -188,7 +188,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertNotNull(subModRepo); assertNotNull(subModRepo);
assertEquals(subCommit, commit); assertEquals(subCommit, commit);
} }
}
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));
assertTrue(status.getAdded().contains(path)); assertTrue(status.getAdded().contains(path));
@ -269,7 +269,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertNotNull(repo); assertNotNull(repo);
addRepoToClose(repo); addRepoToClose(repo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(path, generator.getPath()); assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId()); assertEquals(commit, generator.getObjectId());
@ -288,6 +288,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
Constants.DEFAULT_REMOTE_NAME, Constants.DEFAULT_REMOTE_NAME,
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
} }
}
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();

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java

@ -107,7 +107,6 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(1, updated.size()); assertEquals(1, updated.size());
File submoduleDir = assertSubmoduleIsInitialized(); File submoduleDir = assertSubmoduleIsInitialized();
SubmoduleWalk generator;
write(new File(submoduleDir, "untracked"), "untracked"); write(new File(submoduleDir, "untracked"), "untracked");
@ -115,8 +114,9 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length); assertNotEquals(0, submoduleDir.list().length);
} }
@ -132,34 +132,37 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(1, updated.size()); assertEquals(1, updated.size());
File submoduleDir = assertSubmoduleIsInitialized(); File submoduleDir = assertSubmoduleIsInitialized();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
generator.next(); generator.next();
//want to create a commit inside the repo... // want to create a commit inside the repo...
try (Repository submoduleLocalRepo = generator.getRepository()) { try (Repository submoduleLocalRepo = generator.getRepository()) {
JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt", JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt",
"new data"); "new data");
Git.wrap(submoduleLocalRepo).commit().setAll(true) Git.wrap(submoduleLocalRepo).commit().setAll(true)
.setMessage("local commit").call(); .setMessage("local commit").call();
} }
}
SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub")); SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length); assertNotEquals(0, submoduleDir.list().length);
} }
private File assertSubmoduleIsInitialized() throws IOException { private File assertSubmoduleIsInitialized() throws IOException {
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
File submoduleDir = new File(db.getWorkTree(), generator.getPath()); File submoduleDir = new File(db.getWorkTree(), generator.getPath());
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length); assertNotEquals(0, submoduleDir.list().length);
return submoduleDir; return submoduleDir;
} }
}
@Test @Test
public void dirtySubmoduleWithForce() throws Exception { public void dirtySubmoduleWithForce() throws Exception {
@ -180,8 +183,9 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.FORCED, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.FORCED, result.getStatus());
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertEquals(0, submoduleDir.list().length); assertEquals(0, submoduleDir.list().length);
} }
@ -202,8 +206,9 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
assertEquals(path, result.getPath()); assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.SUCCESS, result.getStatus()); assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.SUCCESS, result.getStatus());
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
}
assertTrue(submoduleDir.isDirectory()); assertTrue(submoduleDir.isDirectory());
assertEquals(0, submoduleDir.list().length); assertEquals(0, submoduleDir.list().length);
} }

42
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleInitTest.java

@ -86,11 +86,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
ConfigInvalidException, GitAPIException { ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex(); final String path = addSubmoduleToIndex();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -109,11 +109,12 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl()); assertEquals(url, generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
} }
}
@Test @Test
public void resolveSameLevelRelativeUrl() throws Exception { public void resolveSameLevelRelativeUrl() throws Exception {
@ -126,11 +127,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -149,11 +150,13 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/repo.git/sub.git", generator.getConfigUrl()); assertEquals("git://server/repo.git/sub.git",
generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
} }
}
@Test @Test
public void resolveOneLevelHigherRelativeUrl() throws IOException, public void resolveOneLevelHigherRelativeUrl() throws IOException,
@ -167,11 +170,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -190,11 +193,12 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl()); assertEquals("git://server/sub.git", generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
} }
}
@Test @Test
public void resolveTwoLevelHigherRelativeUrl() throws IOException, public void resolveTwoLevelHigherRelativeUrl() throws IOException,
@ -208,11 +212,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -231,11 +235,12 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server2/sub.git", generator.getConfigUrl()); assertEquals("git://server2/sub.git", generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
} }
}
@Test @Test
public void resolveWorkingDirectoryRelativeUrl() throws IOException, public void resolveWorkingDirectoryRelativeUrl() throws IOException,
@ -250,11 +255,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL); Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
@ -273,11 +278,12 @@ public class SubmoduleInitTest extends RepositoryTestCase {
assertEquals(1, modules.size()); assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next()); assertEquals(path, modules.iterator().next());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(base + "/sub.git", generator.getConfigUrl()); assertEquals(base + "/sub.git", generator.getConfigUrl());
assertEquals(update, generator.getConfigUpdate()); assertEquals(update, generator.getConfigUpdate());
} }
}
@Test @Test
public void resolveInvalidParentUrl() throws IOException, public void resolveInvalidParentUrl() throws IOException,
@ -291,11 +297,11 @@ public class SubmoduleInitTest extends RepositoryTestCase {
base); base);
config.save(); config.save();
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertNull(generator.getConfigUpdate()); assertNull(generator.getConfigUpdate());
}
FileBasedConfig modulesConfig = new FileBasedConfig(new File( FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS()); db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java

@ -119,11 +119,11 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
addRepoToClose(subRepo); addRepoToClose(subRepo);
assertNotNull(subRepo); assertNotNull(subRepo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertEquals(url, generator.getModulesUrl()); assertEquals(url, generator.getModulesUrl());
}
SubmoduleSyncCommand command = new SubmoduleSyncCommand(db); SubmoduleSyncCommand command = new SubmoduleSyncCommand(db);
Map<String, String> synced = command.call(); Map<String, String> synced = command.call();
assertNotNull(synced); assertNotNull(synced);
@ -132,7 +132,7 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
assertEquals(path, module.getKey()); assertEquals(path, module.getKey());
assertEquals(url, module.getValue()); assertEquals(url, module.getValue());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl()); assertEquals(url, generator.getConfigUrl());
try (Repository subModRepository = generator.getRepository()) { try (Repository subModRepository = generator.getRepository()) {
@ -144,6 +144,7 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
} }
} }
}
@Test @Test
public void repositoryWithRelativeUriSubmodule() throws Exception { public void repositoryWithRelativeUriSubmodule() throws Exception {
@ -190,11 +191,11 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
assertNotNull(subRepo); assertNotNull(subRepo);
addRepoToClose(subRepo); addRepoToClose(subRepo);
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertNull(generator.getConfigUrl()); assertNull(generator.getConfigUrl());
assertEquals(current, generator.getModulesUrl()); assertEquals(current, generator.getModulesUrl());
}
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
ConfigConstants.CONFIG_KEY_URL, "../sub.git"); ConfigConstants.CONFIG_KEY_URL, "../sub.git");
modulesConfig.save(); modulesConfig.save();
@ -207,7 +208,7 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
assertEquals(path, module.getKey()); assertEquals(path, module.getKey());
assertEquals("git://server/sub.git", module.getValue()); assertEquals("git://server/sub.git", module.getValue());
generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl()); assertEquals("git://server/sub.git", generator.getConfigUrl());
try (Repository subModRepository1 = generator.getRepository()) { try (Repository subModRepository1 = generator.getRepository()) {
@ -219,4 +220,5 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
ConfigConstants.CONFIG_KEY_URL)); ConfigConstants.CONFIG_KEY_URL));
} }
} }
}
} }

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java

@ -119,13 +119,14 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
assertEquals(1, updated.size()); assertEquals(1, updated.size());
assertEquals(path, updated.iterator().next()); assertEquals(path, updated.iterator().next());
SubmoduleWalk generator = SubmoduleWalk.forIndex(db); try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
assertTrue(generator.next()); assertTrue(generator.next());
try (Repository subRepo = generator.getRepository()) { try (Repository subRepo = generator.getRepository()) {
assertNotNull(subRepo); assertNotNull(subRepo);
assertEquals(commit, subRepo.resolve(Constants.HEAD)); assertEquals(commit, subRepo.resolve(Constants.HEAD));
} }
} }
}
@Test @Test
public void repositoryWithUnconfiguredSubmodule() throws IOException, public void repositoryWithUnconfiguredSubmodule() throws IOException,
@ -181,10 +182,11 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
Repository subRepo = Git.init().setBare(false) try (Repository subRepo = Git.init().setBare(false)
.setDirectory(new File(db.getWorkTree(), path)).call() .setDirectory(new File(db.getWorkTree(), path)).call()
.getRepository(); .getRepository()) {
assertNotNull(subRepo); assertNotNull(subRepo);
}
SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db); SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
Collection<String> updated = command.call(); Collection<String> updated = command.call();

35
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java

@ -98,11 +98,12 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
@Test @Test
public void repositoryWithNoSubmodules() throws IOException { public void repositoryWithNoSubmodules() throws IOException {
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertFalse(gen.next()); assertFalse(gen.next());
assertNull(gen.getPath()); assertNull(gen.getPath());
assertEquals(ObjectId.zeroId(), gen.getObjectId()); assertEquals(ObjectId.zeroId(), gen.getObjectId());
} }
}
@Test @Test
public void bareRepositoryWithNoSubmodules() throws IOException { public void bareRepositoryWithNoSubmodules() throws IOException {
@ -129,7 +130,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
@ -140,10 +141,11 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getModulesUpdate()); assertNull(gen.getModulesUpdate());
assertNull(gen.getModulesUrl()); assertNull(gen.getModulesUrl());
assertNull(gen.getRepository()); assertNull(gen.getRepository());
Status status = Git.wrap(db).status().call();
assertTrue(!status.isClean());
assertFalse(gen.next()); assertFalse(gen.next());
} }
Status status = Git.wrap(db).status().call();
assertFalse(status.isClean());
}
@Test @Test
public void repositoryWithRootLevelSubmoduleAbsoluteRef() public void repositoryWithRootLevelSubmoduleAbsoluteRef()
@ -178,7 +180,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
@ -197,6 +199,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
} }
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
@Test @Test
public void repositoryWithRootLevelSubmoduleRelativeRef() public void repositoryWithRootLevelSubmoduleRelativeRef()
@ -232,7 +235,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
@ -251,6 +254,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertFalse(gen.next()); assertFalse(gen.next());
} }
} }
}
@Test @Test
public void repositoryWithNestedSubmodule() throws IOException, public void repositoryWithNestedSubmodule() throws IOException,
@ -270,7 +274,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(id, gen.getObjectId()); assertEquals(id, gen.getObjectId());
@ -283,6 +287,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
@Test @Test
public void generatorFilteredToOneOfTwoSubmodules() throws IOException { public void generatorFilteredToOneOfTwoSubmodules() throws IOException {
@ -312,13 +317,14 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
gen.setFilter(PathFilter.create(path1)); gen.setFilter(PathFilter.create(path1));
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path1, gen.getPath()); assertEquals(path1, gen.getPath());
assertEquals(id1, gen.getObjectId()); assertEquals(id1, gen.getObjectId());
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
@Test @Test
public void indexWithGitmodules() throws Exception { public void indexWithGitmodules() throws Exception {
@ -358,7 +364,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}); });
editor.commit(); editor.commit();
SubmoduleWalk gen = SubmoduleWalk.forIndex(db); try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
assertTrue(gen.next()); assertTrue(gen.next());
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
@ -371,6 +377,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
@Test @Test
public void treeIdWithGitmodules() throws Exception { public void treeIdWithGitmodules() throws Exception {
@ -397,7 +404,8 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
}) })
.create()); .create());
SubmoduleWalk gen = SubmoduleWalk.forPath(db, commit.getTree(), "sub"); try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, commit.getTree(),
"sub")) {
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
@ -409,6 +417,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
@Test @Test
public void testTreeIteratorWithGitmodules() throws Exception { public void testTreeIteratorWithGitmodules() throws Exception {
@ -437,7 +446,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
final CanonicalTreeParser p = new CanonicalTreeParser(); final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree()); p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub"); try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
@ -449,6 +458,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
@Test @Test
public void testTreeIteratorWithGitmodulesNameNotPath() throws Exception { public void testTreeIteratorWithGitmodulesNameNotPath() throws Exception {
@ -477,7 +487,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
final CanonicalTreeParser p = new CanonicalTreeParser(); final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree()); p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub"); try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
assertEquals(path, gen.getPath()); assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId()); assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory()); assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
@ -489,4 +499,5 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getRepository()); assertNull(gen.getRepository());
assertFalse(gen.next()); assertFalse(gen.next());
} }
}
} }

Loading…
Cancel
Save