use of org.eclipse.che.api.git.exception.GitException 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.che.api.git.exception.GitException in project che by eclipse.
the class JGitConfigImpl method unset.
@Override
public Config unset(String name) throws GitException {
ConfigKey key = parseName(name);
repository.getConfig().unset(key.section, key.subsection, key.name);
try {
this.repository.getConfig().save();
} catch (IOException e) {
throw new GitException(e.getMessage(), e);
}
return this;
}
use of org.eclipse.che.api.git.exception.GitException 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.che.api.git.exception.GitException in project che by eclipse.
the class JGitConnection method showFileContent.
@Override
public ShowFileContentResponse showFileContent(String file, String version) throws GitException {
String content;
ObjectId revision;
try {
revision = getRepository().resolve(version);
try (RevWalk revWalk = new RevWalk(getRepository())) {
RevCommit revCommit = revWalk.parseCommit(revision);
RevTree tree = revCommit.getTree();
try (TreeWalk treeWalk = new TreeWalk(getRepository())) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(file));
if (!treeWalk.next()) {
throw new GitException("fatal: Path '" + file + "' does not exist in '" + version + "'" + lineSeparator());
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
content = new String(loader.getBytes());
}
}
} catch (IOException exception) {
throw new GitException(exception.getMessage());
}
return newDto(ShowFileContentResponse.class).withContent(content);
}
use of org.eclipse.che.api.git.exception.GitException 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