SubmoduleAddTest: Open Git in try-with-resource
Change-Id: I1276ce206e891729adfa681e00952ca0ba6ffc53 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
3742946a03
commit
96ff311049
|
@ -119,36 +119,37 @@ public void commandWithEmptyUri() throws GitAPIException {
|
|||
|
||||
@Test
|
||||
public void addSubmodule() throws Exception {
|
||||
Git git = new Git(db);
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
RevCommit commit = git.commit().setMessage("create file").call();
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
RevCommit commit = git.commit().setMessage("create file").call();
|
||||
|
||||
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
|
||||
String path = "sub";
|
||||
command.setPath(path);
|
||||
String uri = db.getDirectory().toURI().toString();
|
||||
command.setURI(uri);
|
||||
Repository repo = command.call();
|
||||
assertNotNull(repo);
|
||||
ObjectId subCommit = repo.resolve(Constants.HEAD);
|
||||
repo.close();
|
||||
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
|
||||
String path = "sub";
|
||||
command.setPath(path);
|
||||
String uri = db.getDirectory().toURI().toString();
|
||||
command.setURI(uri);
|
||||
Repository repo = command.call();
|
||||
assertNotNull(repo);
|
||||
ObjectId subCommit = repo.resolve(Constants.HEAD);
|
||||
repo.close();
|
||||
|
||||
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());
|
||||
Repository subModRepo = generator.getRepository();
|
||||
assertNotNull(subModRepo);
|
||||
assertEquals(subCommit, commit);
|
||||
subModRepo.close();
|
||||
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());
|
||||
Repository subModRepo = generator.getRepository();
|
||||
assertNotNull(subModRepo);
|
||||
assertEquals(subCommit, commit);
|
||||
subModRepo.close();
|
||||
|
||||
Status status = Git.wrap(db).status().call();
|
||||
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
|
||||
assertTrue(status.getAdded().contains(path));
|
||||
Status status = Git.wrap(db).status().call();
|
||||
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
|
||||
assertTrue(status.getAdded().contains(path));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -182,45 +183,47 @@ public void apply(DirCacheEntry ent) {
|
|||
|
||||
@Test
|
||||
public void addSubmoduleWithRelativeUri() throws Exception {
|
||||
Git git = new Git(db);
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
RevCommit commit = git.commit().setMessage("create file").call();
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
RevCommit commit = git.commit().setMessage("create file").call();
|
||||
|
||||
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
|
||||
String path = "sub";
|
||||
String uri = "./.git";
|
||||
command.setPath(path);
|
||||
command.setURI(uri);
|
||||
Repository repo = command.call();
|
||||
assertNotNull(repo);
|
||||
addRepoToClose(repo);
|
||||
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
|
||||
String path = "sub";
|
||||
String uri = "./.git";
|
||||
command.setPath(path);
|
||||
command.setURI(uri);
|
||||
Repository repo = command.call();
|
||||
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());
|
||||
Repository subModRepo = generator.getRepository();
|
||||
assertNotNull(subModRepo);
|
||||
assertEquals(
|
||||
fullUri,
|
||||
subModRepo
|
||||
.getConfig()
|
||||
.getString(ConfigConstants.CONFIG_REMOTE_SECTION,
|
||||
Constants.DEFAULT_REMOTE_NAME,
|
||||
ConfigConstants.CONFIG_KEY_URL));
|
||||
subModRepo.close();
|
||||
assertEquals(commit, repo.resolve(Constants.HEAD));
|
||||
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());
|
||||
Repository subModRepo = generator.getRepository();
|
||||
assertNotNull(subModRepo);
|
||||
assertEquals(
|
||||
fullUri,
|
||||
subModRepo
|
||||
.getConfig()
|
||||
.getString(ConfigConstants.CONFIG_REMOTE_SECTION,
|
||||
Constants.DEFAULT_REMOTE_NAME,
|
||||
ConfigConstants.CONFIG_KEY_URL));
|
||||
subModRepo.close();
|
||||
assertEquals(commit, repo.resolve(Constants.HEAD));
|
||||
|
||||
Status status = Git.wrap(db).status().call();
|
||||
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
|
||||
assertTrue(status.getAdded().contains(path));
|
||||
Status status = Git.wrap(db).status().call();
|
||||
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
|
||||
assertTrue(status.getAdded().contains(path));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -237,31 +240,32 @@ public void addSubmoduleWithExistingSubmoduleDefined() throws Exception {
|
|||
path1, ConfigConstants.CONFIG_KEY_URL, url1);
|
||||
modulesConfig.save();
|
||||
|
||||
Git git = new Git(db);
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
assertNotNull(git.commit().setMessage("create file").call());
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
assertNotNull(git.commit().setMessage("create file").call());
|
||||
|
||||
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
|
||||
command.setPath(path2);
|
||||
String url2 = db.getDirectory().toURI().toString();
|
||||
command.setURI(url2);
|
||||
Repository r = command.call();
|
||||
assertNotNull(r);
|
||||
addRepoToClose(r);
|
||||
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
|
||||
command.setPath(path2);
|
||||
String url2 = db.getDirectory().toURI().toString();
|
||||
command.setURI(url2);
|
||||
Repository r = command.call();
|
||||
assertNotNull(r);
|
||||
addRepoToClose(r);
|
||||
|
||||
modulesConfig.load();
|
||||
assertEquals(path1, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path1,
|
||||
ConfigConstants.CONFIG_KEY_PATH));
|
||||
assertEquals(url1, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path1,
|
||||
ConfigConstants.CONFIG_KEY_URL));
|
||||
assertEquals(path2, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
|
||||
ConfigConstants.CONFIG_KEY_PATH));
|
||||
assertEquals(url2, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
|
||||
ConfigConstants.CONFIG_KEY_URL));
|
||||
modulesConfig.load();
|
||||
assertEquals(path1, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path1,
|
||||
ConfigConstants.CONFIG_KEY_PATH));
|
||||
assertEquals(url1, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path1,
|
||||
ConfigConstants.CONFIG_KEY_URL));
|
||||
assertEquals(path2, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
|
||||
ConfigConstants.CONFIG_KEY_PATH));
|
||||
assertEquals(url2, modulesConfig.getString(
|
||||
ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
|
||||
ConfigConstants.CONFIG_KEY_URL));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue