use of com.virtuslab.gitcore.api.GitCoreException in project git-machete-intellij-plugin by VirtusLab.
the class GitCoreRepository method deriveAllLocalBranches.
@Override
public List<IGitCoreLocalBranchSnapshot> deriveAllLocalBranches() throws GitCoreException {
LOG.debug(() -> "Entering: this = ${this}");
LOG.debug("List of local branches:");
List<Try<GitCoreLocalBranchSnapshot>> result = Try.of(() -> jgitRepo.getRefDatabase().getRefsByPrefix(Constants.R_HEADS)).getOrElseThrow(e -> new GitCoreException("Error while getting list of local branches", e)).stream().filter(branch -> !branch.getName().equals(Constants.HEAD)).map(ref -> Try.of(() -> {
String localBranchFullName = ref.getName();
LOG.debug(() -> "* " + localBranchFullName);
String localBranchName = localBranchFullName.replace(Constants.R_HEADS, /* replacement */
"");
val objectId = ref.getObjectId();
if (objectId == null) {
throw new GitCoreException("Cannot access git object id corresponding to ${localBranchFullName}");
}
val pointedCommit = convertObjectIdToGitCoreCommit(objectId);
val reflog = deriveReflogByRefFullName(localBranchFullName);
val remoteBranch = deriveRemoteBranchForLocalBranch(localBranchName).getOrNull();
return new GitCoreLocalBranchSnapshot(localBranchName, pointedCommit, reflog, remoteBranch);
})).collect(List.collector());
return List.narrow(Try.sequence(result).getOrElseThrow(GitCoreException::getOrWrap).toList().sortBy(b -> b.getName()));
}
Aggregations