assertEquals(sub1Head, pathStatus.getHeadId());
assertEquals(sub1Head, pathStatus.getIndexId());
- SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository());
- assertTrue(walk.next());
- try (Repository clonedSub1 = walk.getRepository()) {
- assertNotNull(clonedSub1);
- assertEquals(new File(git2.getRepository().getWorkTree(),
- walk.getPath()), clonedSub1.getWorkTree());
- assertEquals(
- new File(new File(git2.getRepository().getDirectory(),
- "modules"), walk.getPath()),
- clonedSub1.getDirectory());
- status = new SubmoduleStatusCommand(clonedSub1);
- statuses = status.call();
+ try (SubmoduleWalk walk = SubmoduleWalk
+ .forIndex(git2.getRepository())) {
+ assertTrue(walk.next());
+ try (Repository clonedSub1 = walk.getRepository()) {
+ assertNotNull(clonedSub1);
+ assertEquals(new File(git2.getRepository().getWorkTree(),
+ walk.getPath()), clonedSub1.getWorkTree());
+ assertEquals(
+ new File(new File(git2.getRepository().getDirectory(),
+ "modules"), walk.getPath()),
+ clonedSub1.getDirectory());
+ status = new SubmoduleStatusCommand(clonedSub1);
+ statuses = status.call();
+ }
+ assertFalse(walk.next());
}
pathStatus = statuses.get(path);
assertNotNull(pathStatus);
assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType());
assertEquals(sub2Head, pathStatus.getHeadId());
assertEquals(sub2Head, pathStatus.getIndexId());
- assertFalse(walk.next());
}
@Test
writeTrashFile(path, "content");
git.add().addFilepattern(path).call();
RevCommit commit1 = git.commit().setMessage("commit").call();
- TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree());
- assertNotNull(walk);
- assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
+ try (TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree())) {
+ assertNotNull(walk);
+ assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
+ }
FS nonExecutableFs = new FS() {
writeTrashFile(path, "content2");
RevCommit commit2 = git2.commit().setOnly(path).setMessage("commit2")
.call();
- walk = TreeWalk.forPath(db, path, commit2.getTree());
- assertNotNull(walk);
- assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
+ try (TreeWalk walk = TreeWalk.forPath(db, path, commit2.getTree())) {
+ assertNotNull(walk);
+ assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));
+ }
}
@Test
assertNotNull(repo);
addRepoToClose(repo);
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals(path, generator.getPath());
- assertEquals(commit, generator.getObjectId());
- assertEquals(uri, generator.getModulesUrl());
- assertEquals(path, generator.getModulesPath());
- assertEquals(uri, generator.getConfigUrl());
- try (Repository subModRepo = generator.getRepository()) {
- assertNotNull(subModRepo);
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals(path, generator.getPath());
+ assertEquals(commit, generator.getObjectId());
+ assertEquals(uri, generator.getModulesUrl());
+ assertEquals(path, generator.getModulesPath());
+ assertEquals(uri, generator.getConfigUrl());
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ }
}
assertEquals(commit, repo.resolve(Constants.HEAD));
assertNotNull(repo);
addRepoToClose(repo);
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals(path, generator.getPath());
- assertEquals(commit2, generator.getObjectId());
- assertEquals(uri, generator.getModulesUrl());
- assertEquals(path, generator.getModulesPath());
- assertEquals(uri, generator.getConfigUrl());
- try (Repository subModRepo = generator.getRepository()) {
- assertNotNull(subModRepo);
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals(path, generator.getPath());
+ assertEquals(commit2, generator.getObjectId());
+ assertEquals(uri, generator.getModulesUrl());
+ assertEquals(path, generator.getModulesPath());
+ assertEquals(uri, generator.getConfigUrl());
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ }
}
assertEquals(commit2, repo.resolve(Constants.HEAD));
private void assertSubmoduleFetchHeads(ObjectId expectedHead1,
ObjectId expectedHead2) throws Exception {
+ Object newHead1 = null;
+ ObjectId newHead2 = null;
try (SubmoduleWalk walk = SubmoduleWalk
.forIndex(git2.getRepository())) {
assertTrue(walk.next());
- Repository r = walk.getRepository();
- ObjectId newHead1 = r.resolve(Constants.FETCH_HEAD);
- ObjectId newHead2;
- try (SubmoduleWalk walk2 = SubmoduleWalk.forIndex(r)) {
- assertTrue(walk2.next());
- newHead2 = walk2.getRepository().resolve(Constants.FETCH_HEAD);
+ try (Repository r = walk.getRepository()) {
+ newHead1 = r.resolve(Constants.FETCH_HEAD);
+ try (SubmoduleWalk walk2 = SubmoduleWalk.forIndex(r)) {
+ assertTrue(walk2.next());
+ try (Repository r2 = walk2.getRepository()) {
+ newHead2 = r2.resolve(Constants.FETCH_HEAD);
+ }
+ }
}
-
- assertEquals(expectedHead1, newHead1);
- assertEquals(expectedHead2, newHead2);
}
+ assertEquals(expectedHead1, newHead1);
+ assertEquals(expectedHead2, newHead2);
}
}
subCommit = repo.resolve(Constants.HEAD);
}
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- generator.loadModulesConfig();
- assertTrue(generator.next());
- assertEquals(path, generator.getModuleName());
- assertEquals(path, generator.getPath());
- assertEquals(commit, generator.getObjectId());
- assertEquals(uri, generator.getModulesUrl());
- assertEquals(path, generator.getModulesPath());
- assertEquals(uri, generator.getConfigUrl());
- try (Repository subModRepo = generator.getRepository()) {
- assertNotNull(subModRepo);
- assertEquals(subCommit, commit);
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ generator.loadModulesConfig();
+ assertTrue(generator.next());
+ assertEquals(path, generator.getModuleName());
+ assertEquals(path, generator.getPath());
+ assertEquals(commit, generator.getObjectId());
+ assertEquals(uri, generator.getModulesUrl());
+ assertEquals(path, generator.getModulesPath());
+ assertEquals(uri, generator.getConfigUrl());
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(subCommit, commit);
+ }
}
-
Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
assertTrue(status.getAdded().contains(path));
subCommit = repo.resolve(Constants.HEAD);
}
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- generator.loadModulesConfig();
- assertTrue(generator.next());
- assertEquals(name, generator.getModuleName());
- assertEquals(path, generator.getPath());
- assertEquals(commit, generator.getObjectId());
- assertEquals(uri, generator.getModulesUrl());
- assertEquals(path, generator.getModulesPath());
- assertEquals(uri, generator.getConfigUrl());
- try (Repository subModRepo = generator.getRepository()) {
- assertNotNull(subModRepo);
- assertEquals(subCommit, commit);
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ generator.loadModulesConfig();
+ assertTrue(generator.next());
+ assertEquals(name, generator.getModuleName());
+ assertEquals(path, generator.getPath());
+ assertEquals(commit, generator.getObjectId());
+ assertEquals(uri, generator.getModulesUrl());
+ assertEquals(path, generator.getModulesPath());
+ assertEquals(uri, generator.getConfigUrl());
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(subCommit, commit);
+ }
}
-
Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
assertTrue(status.getAdded().contains(path));
assertNotNull(repo);
addRepoToClose(repo);
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals(path, generator.getPath());
- assertEquals(commit, generator.getObjectId());
- assertEquals(uri, generator.getModulesUrl());
- assertEquals(path, generator.getModulesPath());
- String fullUri = db.getDirectory().getAbsolutePath();
- if (File.separatorChar == '\\') {
- fullUri = fullUri.replace('\\', '/');
- }
- assertEquals(fullUri, generator.getConfigUrl());
- try (Repository subModRepo = generator.getRepository()) {
- assertNotNull(subModRepo);
- assertEquals(fullUri,
- subModRepo.getConfig().getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME,
- ConfigConstants.CONFIG_KEY_URL));
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals(path, generator.getPath());
+ assertEquals(commit, generator.getObjectId());
+ assertEquals(uri, generator.getModulesUrl());
+ assertEquals(path, generator.getModulesPath());
+ String fullUri = db.getDirectory().getAbsolutePath();
+ if (File.separatorChar == '\\') {
+ fullUri = fullUri.replace('\\', '/');
+ }
+ assertEquals(fullUri, generator.getConfigUrl());
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(fullUri,
+ subModRepo.getConfig().getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
assertEquals(commit, repo.resolve(Constants.HEAD));
assertEquals(1, updated.size());
File submoduleDir = assertSubmoduleIsInitialized();
- SubmoduleWalk generator;
write(new File(submoduleDir, "untracked"), "untracked");
assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ }
assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length);
}
assertEquals(1, updated.size());
File submoduleDir = assertSubmoduleIsInitialized();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- generator.next();
-
- //want to create a commit inside the repo...
- try (Repository submoduleLocalRepo = generator.getRepository()) {
- JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt",
- "new data");
- Git.wrap(submoduleLocalRepo).commit().setAll(true)
- .setMessage("local commit").call();
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ generator.next();
+
+ // want to create a commit inside the repo...
+ try (Repository submoduleLocalRepo = generator.getRepository()) {
+ JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt",
+ "new data");
+ Git.wrap(submoduleLocalRepo).commit().setAll(true)
+ .setMessage("local commit").call();
+ }
}
SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ }
assertTrue(submoduleDir.isDirectory());
assertNotEquals(0, submoduleDir.list().length);
}
private File assertSubmoduleIsInitialized() throws IOException {
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- File submoduleDir = new File(db.getWorkTree(), generator.getPath());
- assertTrue(submoduleDir.isDirectory());
- assertNotEquals(0, submoduleDir.list().length);
- return submoduleDir;
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ File submoduleDir = new File(db.getWorkTree(), generator.getPath());
+ assertTrue(submoduleDir.isDirectory());
+ assertNotEquals(0, submoduleDir.list().length);
+ return submoduleDir;
+ }
}
@Test
assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.FORCED, result.getStatus());
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ }
assertTrue(submoduleDir.isDirectory());
assertEquals(0, submoduleDir.list().length);
}
assertEquals(path, result.getPath());
assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.SUCCESS, result.getStatus());
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ }
assertTrue(submoduleDir.isDirectory());
assertEquals(0, submoduleDir.list().length);
}
ConfigInvalidException, GitAPIException {
final String path = addSubmoduleToIndex();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertNull(generator.getConfigUpdate());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertNull(generator.getConfigUpdate());
+ }
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals(url, generator.getConfigUrl());
- assertEquals(update, generator.getConfigUpdate());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals(url, generator.getConfigUrl());
+ assertEquals(update, generator.getConfigUpdate());
+ }
}
@Test
base);
config.save();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertNull(generator.getConfigUpdate());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertNull(generator.getConfigUpdate());
+ }
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals("git://server/repo.git/sub.git", generator.getConfigUrl());
- assertEquals(update, generator.getConfigUpdate());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals("git://server/repo.git/sub.git",
+ generator.getConfigUrl());
+ assertEquals(update, generator.getConfigUpdate());
+ }
}
@Test
base);
config.save();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertNull(generator.getConfigUpdate());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertNull(generator.getConfigUpdate());
+ }
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals("git://server/sub.git", generator.getConfigUrl());
- assertEquals(update, generator.getConfigUpdate());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals("git://server/sub.git", generator.getConfigUrl());
+ assertEquals(update, generator.getConfigUpdate());
+ }
}
@Test
base);
config.save();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertNull(generator.getConfigUpdate());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertNull(generator.getConfigUpdate());
+ }
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals("git://server2/sub.git", generator.getConfigUrl());
- assertEquals(update, generator.getConfigUpdate());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals("git://server2/sub.git", generator.getConfigUrl());
+ assertEquals(update, generator.getConfigUpdate());
+ }
}
@Test
Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL);
config.save();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertNull(generator.getConfigUpdate());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertNull(generator.getConfigUpdate());
+ }
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
assertEquals(1, modules.size());
assertEquals(path, modules.iterator().next());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals(base + "/sub.git", generator.getConfigUrl());
- assertEquals(update, generator.getConfigUpdate());
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals(base + "/sub.git", generator.getConfigUrl());
+ assertEquals(update, generator.getConfigUpdate());
+ }
}
@Test
base);
config.save();
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertNull(generator.getConfigUpdate());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertNull(generator.getConfigUpdate());
+ }
FileBasedConfig modulesConfig = new FileBasedConfig(new File(
db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
addRepoToClose(subRepo);
assertNotNull(subRepo);
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertEquals(url, generator.getModulesUrl());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertEquals(url, generator.getModulesUrl());
+ }
SubmoduleSyncCommand command = new SubmoduleSyncCommand(db);
Map<String, String> synced = command.call();
assertNotNull(synced);
assertEquals(path, module.getKey());
assertEquals(url, module.getValue());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals(url, generator.getConfigUrl());
- try (Repository subModRepository = generator.getRepository()) {
- StoredConfig submoduleConfig = subModRepository.getConfig();
- assertEquals(url,
- submoduleConfig.getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME,
- ConfigConstants.CONFIG_KEY_URL));
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals(url, generator.getConfigUrl());
+ try (Repository subModRepository = generator.getRepository()) {
+ StoredConfig submoduleConfig = subModRepository.getConfig();
+ assertEquals(url,
+ submoduleConfig.getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
}
assertNotNull(subRepo);
addRepoToClose(subRepo);
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertNull(generator.getConfigUrl());
- assertEquals(current, generator.getModulesUrl());
-
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertNull(generator.getConfigUrl());
+ assertEquals(current, generator.getModulesUrl());
+ }
modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
ConfigConstants.CONFIG_KEY_URL, "../sub.git");
modulesConfig.save();
assertEquals(path, module.getKey());
assertEquals("git://server/sub.git", module.getValue());
- generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- assertEquals("git://server/sub.git", generator.getConfigUrl());
- try (Repository subModRepository1 = generator.getRepository()) {
- StoredConfig submoduleConfig = subModRepository1.getConfig();
- assertEquals("git://server/sub.git",
- submoduleConfig.getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME,
- ConfigConstants.CONFIG_KEY_URL));
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ assertEquals("git://server/sub.git", generator.getConfigUrl());
+ try (Repository subModRepository1 = generator.getRepository()) {
+ StoredConfig submoduleConfig = subModRepository1.getConfig();
+ assertEquals("git://server/sub.git",
+ submoduleConfig.getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
}
}
assertEquals(1, updated.size());
assertEquals(path, updated.iterator().next());
- SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
- assertTrue(generator.next());
- try (Repository subRepo = generator.getRepository()) {
- assertNotNull(subRepo);
- assertEquals(commit, subRepo.resolve(Constants.HEAD));
+ try (SubmoduleWalk generator = SubmoduleWalk.forIndex(db)) {
+ assertTrue(generator.next());
+ try (Repository subRepo = generator.getRepository()) {
+ assertNotNull(subRepo);
+ assertEquals(commit, subRepo.resolve(Constants.HEAD));
+ }
}
}
});
editor.commit();
- Repository subRepo = Git.init().setBare(false)
+ try (Repository subRepo = Git.init().setBare(false)
.setDirectory(new File(db.getWorkTree(), path)).call()
- .getRepository();
- assertNotNull(subRepo);
+ .getRepository()) {
+ assertNotNull(subRepo);
+ }
SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
Collection<String> updated = command.call();
@Test
public void repositoryWithNoSubmodules() throws IOException {
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- assertFalse(gen.next());
- assertNull(gen.getPath());
- assertEquals(ObjectId.zeroId(), gen.getObjectId());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ assertFalse(gen.next());
+ assertNull(gen.getPath());
+ assertEquals(ObjectId.zeroId(), gen.getObjectId());
+ }
}
@Test
});
editor.commit();
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- assertTrue(gen.next());
- assertEquals(path, gen.getPath());
- assertEquals(id, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertNull(gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertNull(gen.getModulesUrl());
- assertNull(gen.getRepository());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ assertTrue(gen.next());
+ assertEquals(path, gen.getPath());
+ assertEquals(id, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertNull(gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertNull(gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
Status status = Git.wrap(db).status().call();
- assertTrue(!status.isClean());
- assertFalse(gen.next());
+ assertFalse(status.isClean());
}
@Test
});
editor.commit();
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- assertTrue(gen.next());
- assertEquals(path, gen.getPath());
- assertEquals(id, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertNull(gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertNull(gen.getModulesUrl());
- try (Repository subRepo = gen.getRepository()) {
- assertNotNull(subRepo);
- assertEquals(modulesGitDir.getAbsolutePath(),
- subRepo.getDirectory().getAbsolutePath());
- assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(),
- subRepo.getWorkTree().getAbsolutePath());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ assertTrue(gen.next());
+ assertEquals(path, gen.getPath());
+ assertEquals(id, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertNull(gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertNull(gen.getModulesUrl());
+ try (Repository subRepo = gen.getRepository()) {
+ assertNotNull(subRepo);
+ assertEquals(modulesGitDir.getAbsolutePath(),
+ subRepo.getDirectory().getAbsolutePath());
+ assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(),
+ subRepo.getWorkTree().getAbsolutePath());
+ }
+ assertFalse(gen.next());
}
- assertFalse(gen.next());
}
@Test
});
editor.commit();
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- assertTrue(gen.next());
- assertEquals(path, gen.getPath());
- assertEquals(id, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertNull(gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertNull(gen.getModulesUrl());
- try (Repository subRepo = gen.getRepository()) {
- assertNotNull(subRepo);
- assertEqualsFile(modulesGitDir, subRepo.getDirectory());
- assertEqualsFile(new File(db.getWorkTree(), path),
- subRepo.getWorkTree());
- subRepo.close();
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ assertTrue(gen.next());
+ assertEquals(path, gen.getPath());
+ assertEquals(id, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertNull(gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertNull(gen.getModulesUrl());
+ try (Repository subRepo = gen.getRepository()) {
+ assertNotNull(subRepo);
+ assertEqualsFile(modulesGitDir, subRepo.getDirectory());
+ assertEqualsFile(new File(db.getWorkTree(), path),
+ subRepo.getWorkTree());
+ subRepo.close();
+ assertFalse(gen.next());
+ }
}
}
});
editor.commit();
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- assertTrue(gen.next());
- assertEquals(path, gen.getPath());
- assertEquals(id, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertNull(gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertNull(gen.getModulesUrl());
- assertNull(gen.getRepository());
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ assertTrue(gen.next());
+ assertEquals(path, gen.getPath());
+ assertEquals(id, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertNull(gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertNull(gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
}
@Test
});
editor.commit();
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- gen.setFilter(PathFilter.create(path1));
- assertTrue(gen.next());
- assertEquals(path1, gen.getPath());
- assertEquals(id1, gen.getObjectId());
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ gen.setFilter(PathFilter.create(path1));
+ assertTrue(gen.next());
+ assertEquals(path1, gen.getPath());
+ assertEquals(id1, gen.getObjectId());
+ assertFalse(gen.next());
+ }
}
@Test
});
editor.commit();
- SubmoduleWalk gen = SubmoduleWalk.forIndex(db);
- assertTrue(gen.next());
- assertEquals(path, gen.getPath());
- assertEquals(subId, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertEquals("sub", gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertEquals("git://example.com/sub", gen.getModulesUrl());
- assertNull(gen.getRepository());
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forIndex(db)) {
+ assertTrue(gen.next());
+ assertEquals(path, gen.getPath());
+ assertEquals(subId, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertEquals("sub", gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertEquals("git://example.com/sub", gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
}
@Test
})
.create());
- SubmoduleWalk gen = SubmoduleWalk.forPath(db, commit.getTree(), "sub");
- assertEquals(path, gen.getPath());
- assertEquals(subId, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertEquals("sub", gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertEquals("git://example.com/sub", gen.getModulesUrl());
- assertNull(gen.getRepository());
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, commit.getTree(),
+ "sub")) {
+ assertEquals(path, gen.getPath());
+ assertEquals(subId, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertEquals("sub", gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertEquals("git://example.com/sub", gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
}
@Test
final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
- SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub");
- assertEquals(path, gen.getPath());
- assertEquals(subId, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertEquals("sub", gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertEquals("git://example.com/sub", gen.getModulesUrl());
- assertNull(gen.getRepository());
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
+ assertEquals(path, gen.getPath());
+ assertEquals(subId, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertEquals("sub", gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertEquals("git://example.com/sub", gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
}
@Test
final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
- SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub");
- assertEquals(path, gen.getPath());
- assertEquals(subId, gen.getObjectId());
- assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
- assertNull(gen.getConfigUpdate());
- assertNull(gen.getConfigUrl());
- assertEquals("sub", gen.getModulesPath());
- assertNull(gen.getModulesUpdate());
- assertEquals("git://example.com/sub", gen.getModulesUrl());
- assertNull(gen.getRepository());
- assertFalse(gen.next());
+ try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
+ assertEquals(path, gen.getPath());
+ assertEquals(subId, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertEquals("sub", gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertEquals("git://example.com/sub", gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
}
}