use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method tagCreate.
@Override
public Tag tagCreate(TagCreateParams params) throws GitException {
String commit = params.getCommit();
if (commit == null) {
commit = Constants.HEAD;
}
try {
RevWalk revWalk = new RevWalk(repository);
RevObject revObject;
try {
revObject = revWalk.parseAny(repository.resolve(commit));
} finally {
revWalk.close();
}
TagCommand tagCommand = getGit().tag().setName(params.getName()).setObjectId(revObject).setMessage(params.getMessage()).setForceUpdate(params.isForce());
GitUser tagger = getUser();
if (tagger != null) {
tagCommand.setTagger(new PersonIdent(tagger.getName(), tagger.getEmail()));
}
Ref revTagRef = tagCommand.call();
RevTag revTag = revWalk.parseTag(revTagRef.getLeaf().getObjectId());
return newDto(Tag.class).withName(revTag.getTagName());
} catch (IOException | GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method reset.
@Override
public void reset(ResetParams params) throws GitException {
try {
ResetCommand resetCommand = getGit().reset();
resetCommand.setRef(params.getCommit());
List<String> patterns = params.getFilePattern();
patterns.forEach(resetCommand::addPath);
if (params.getType() != null && patterns.isEmpty()) {
switch(params.getType()) {
case HARD:
resetCommand.setMode(ResetType.HARD);
break;
case KEEP:
resetCommand.setMode(ResetType.KEEP);
break;
case MERGE:
resetCommand.setMode(ResetType.MERGE);
break;
case MIXED:
resetCommand.setMode(ResetType.MIXED);
break;
case SOFT:
resetCommand.setMode(ResetType.SOFT);
break;
}
}
resetCommand.call();
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.api.errors.GitAPIException 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());
}
use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method getCommiters.
@Override
public List<GitUser> getCommiters() throws GitException {
List<GitUser> gitUsers = new ArrayList<>();
try {
LogCommand logCommand = getGit().log();
for (RevCommit commit : logCommand.call()) {
PersonIdent committerIdentity = commit.getCommitterIdent();
GitUser gitUser = newDto(GitUser.class).withName(committerIdentity.getName()).withEmail(committerIdentity.getEmailAddress());
if (!gitUsers.contains(gitUser)) {
gitUsers.add(gitUser);
}
}
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
return gitUsers;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method branchCreate.
@Override
public Branch branchCreate(String name, String startPoint) throws GitException {
CreateBranchCommand createBranchCommand = getGit().branchCreate().setName(name);
if (startPoint != null) {
createBranchCommand.setStartPoint(startPoint);
}
try {
Ref brRef = createBranchCommand.call();
String refName = brRef.getName();
String displayName = Repository.shortenRefName(refName);
return newDto(Branch.class).withName(refName).withDisplayName(displayName).withActive(false).withRemote(false);
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
Aggregations