use of org.eclipse.jgit.api.LsRemoteCommand in project maven-scm by apache.
the class JGitRemoteInfoCommand method executeRemoteInfoCommand.
@Override
public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
GitScmProviderRepository repo = (GitScmProviderRepository) repository;
Git git = null;
try {
git = JGitUtils.openRepo(fileSet.getBasedir());
CredentialsProvider credentials = JGitUtils.getCredentials(repo);
LsRemoteCommand lsCommand = git.lsRemote().setRemote(repo.getPushUrl()).setCredentialsProvider(credentials);
Map<String, String> tag = new HashMap<String, String>();
Collection<Ref> allTags = lsCommand.setHeads(false).setTags(true).call();
for (Ref ref : allTags) {
tag.put(Repository.shortenRefName(ref.getName()), ref.getObjectId().name());
}
Map<String, String> heads = new HashMap<String, String>();
Collection<Ref> allHeads = lsCommand.setHeads(true).setTags(false).call();
for (Ref ref : allHeads) {
heads.put(Repository.shortenRefName(ref.getName()), ref.getObjectId().name());
}
return new RemoteInfoScmResult("JGit remoteinfo", heads, tag);
} catch (Exception e) {
throw new ScmException("JGit remoteinfo failure!", e);
} finally {
JGitUtils.closeRepo(git);
}
}
use of org.eclipse.jgit.api.LsRemoteCommand in project che by eclipse.
the class JGitConnection method lsRemote.
@Override
public List<RemoteReference> lsRemote(String remoteUrl) throws UnauthorizedException, GitException {
LsRemoteCommand lsRemoteCommand = getGit().lsRemote().setRemote(remoteUrl);
Collection<Ref> refs;
try {
refs = lsRemoteCommand.call();
} catch (GitAPIException exception) {
if (exception.getMessage().contains(ERROR_AUTHENTICATION_REQUIRED)) {
throw new UnauthorizedException(format(ERROR_AUTHENTICATION_FAILED, remoteUrl));
} else {
throw new GitException(exception.getMessage(), exception);
}
}
return refs.stream().map(ref -> newDto(RemoteReference.class).withCommitId(ref.getObjectId().name()).withReferenceName(ref.getName())).collect(Collectors.toList());
}
Aggregations