use of org.eclipse.jgit.submodule.SubmoduleStatus in project catma by forTEXT.
the class JGitRepoManager method getSubmoduleHeadRevisionHash.
/**
* Gets the HEAD revision hash for the submodule with the name <code>submoduleName</code>.
*
* @param submoduleName the name of the submodule whose HEAD revision hash to get
* @return a revision hash
* @throws IOException if a submodule with the name <code>submoduleName</code> doesn't exist
* or if the operation failed for another reason
*/
@Override
public String getSubmoduleHeadRevisionHash(String submoduleName) throws IOException {
if (!isAttached()) {
throw new IllegalStateException("Can't call `getSubmoduleHeadRevisionHash` on a detached instance");
}
try {
SubmoduleStatusCommand submoduleStatusCommand = this.gitApi.submoduleStatus();
submoduleStatusCommand.addPath(submoduleName);
Map<String, SubmoduleStatus> results = submoduleStatusCommand.call();
if (!results.containsKey(submoduleName)) {
throw new IOException(String.format("Failed to get HEAD revision hash for submodule `%s`. " + "A submodule with that name does not appear to exist.", submoduleName));
}
return results.get(submoduleName).getHeadId().getName();
} catch (GitAPIException e) {
throw new IOException("Failed to get submodule status", e);
}
}
use of org.eclipse.jgit.submodule.SubmoduleStatus in project JGitFS by centic9.
the class JGitHelper method getSubmoduleHead.
/**
* Returns the path where the given submodule is linked.
*
* @param name the name of the Git submodule.
* @return The path where the Git submodule is linked.
* @throws NoSuchElementException if the given name is not known.
* @throws IOException If accessing the Git repository fails
*/
public String getSubmoduleHead(String name) throws IOException {
try {
Map<String, SubmoduleStatus> set = git.submoduleStatus().call();
for (Map.Entry<String, SubmoduleStatus> entry : set.entrySet()) {
if (entry.getKey().equals(name)) {
SubmoduleStatus value = entry.getValue();
SubmoduleStatusType type = value.getType();
if (type == SubmoduleStatusType.MISSING || type == SubmoduleStatusType.UNINITIALIZED) {
throw new NoSuchElementException("Could not read submodule " + name + " because it is in state " + type);
}
return value.getHeadId().getName();
}
}
throw new NoSuchElementException("Could not read submodule " + name);
} catch (GitAPIException e) {
throw new IOException(e);
}
}
use of org.eclipse.jgit.submodule.SubmoduleStatus in project oxygen-git-client-addon by oxygenxml.
the class DiffPresenterTest method testCompareSubmodule.
/**
* <p><b>Description:</b> Checks the URL used in a rebase conflicts.</p>
* <p><b>Bug ID:</b> EXM-45843</p>
*
* @author bogdan_dragici
*
* @throws Exception
*/
@Test
public void testCompareSubmodule() throws Exception {
GitAccess gitAccess = GitAccess.getInstance();
// PARENT repos
String localTestRepositoryP = "target/test-resources/localCS";
String remoteTestRepositoryP = "target/test-resources/remoteCS";
Repository remoteRepoP = createRepository(remoteTestRepositoryP);
Repository localRepoP = createRepository(localTestRepositoryP);
bindLocalToRemote(localRepoP, remoteRepoP);
// SUBMODULE repos
String remoteTestRepositorySubModule = "target/test-resources/remoteCS-SubModule/";
Repository remoteRepoSubModule = createRepository(remoteTestRepositorySubModule);
// Commit (very important)
gitAccess.commit("Commit");
// Set the PARENT repo as the current one, to which we'll add the submodule
gitAccess.setRepositorySynchronously(localTestRepositoryP);
// Add SUBMODULE
SubmoduleAddCommand addCommand = gitAccess.getGit().submoduleAdd();
addCommand.setURI(remoteRepoSubModule.getDirectory().toURI().toString());
addCommand.setPath("modules/submodule");
Repository subRepo = addCommand.call();
subRepo.close();
File parentWorkDir = gitAccess.getRepository().getWorkTree();
assertTrue(new File(parentWorkDir, "modules/submodule").isDirectory());
assertTrue(new File(parentWorkDir, ".gitmodules").isFile());
// Check the SUBMODULE
Map<String, SubmoduleStatus> submodules = gitAccess.getGit().submoduleStatus().call();
assertEquals(1, submodules.size());
SubmoduleStatus status = submodules.get("modules/submodule");
assertNotNull(status);
assertEquals(SubmoduleStatusType.INITIALIZED, status.getType());
// SHOW DIFF
DiffPresenter.showDiff(// The submodule
gitAccess.getStagedFiles().get(1), Mockito.mock(GitControllerBase.class));
assertNotNull(leftDiff);
assertNotNull(rightDiff);
String left = "git://CurrentSubmodule/modules/submodule.txt";
assertEquals(left, leftDiff.toString());
assertTrue(TestUtil.read(new URL(left)).startsWith("Subproject commit "));
String right = "git://PreviousSubmodule/modules/submodule.txt";
assertEquals(right, rightDiff.toString());
assertTrue(TestUtil.read(new URL(right)).startsWith("Subproject commit "));
}
Aggregations