use of com.virtuslab.gitcore.api.IGitCoreHeadSnapshot in project git-machete-intellij-plugin by VirtusLab.
the class GitCoreRepository method deriveHead.
@Override
public IGitCoreHeadSnapshot deriveHead() throws GitCoreException {
Ref ref = Try.of(() -> jgitRepo.getRefDatabase().findRef(Constants.HEAD)).getOrElseThrow(e -> new GitCoreException("Cannot get current branch", e));
if (ref == null) {
throw new GitCoreException("Error occurred while getting current branch ref");
}
val reflog = deriveReflogByRefFullName(Constants.HEAD);
String currentBranchName = null;
if (ref.isSymbolic()) {
currentBranchName = Repository.shortenRefName(ref.getTarget().getName());
} else {
Option<Path> headNamePath = Stream.of("rebase-apply", "rebase-merge").map(dir -> jgitRepo.getDirectory().toPath().resolve(dir).resolve("head-name")).find(path -> path.toFile().isFile());
if (headNamePath.isDefined()) {
currentBranchName = Try.of(() -> Stream.ofAll(Files.readAllLines(headNamePath.get()))).getOrElseThrow(e -> new GitCoreException("Error occurred while getting current branch ref", e)).headOption().map(Repository::shortenRefName).getOrNull();
}
}
IGitCoreLocalBranchSnapshot targetBranch;
if (currentBranchName != null) {
targetBranch = deriveLocalBranchByName(currentBranchName).getOrNull();
} else {
targetBranch = null;
}
return new GitCoreHeadSnapshot(targetBranch, reflog);
}
Aggregations