Skip to content
Snippets Groups Projects
Commit 79ed570a authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

method for determining the HEAD commit

parent 57b6e52d
No related branches found
No related tags found
No related merge requests found
......@@ -126,6 +126,26 @@ public class Repository {
return revList.map(toCommitList).orElse(Collections.emptyList());
}
/**
* Returns the {@link Commit} currently pointed at by <code>HEAD</code>.
*
* @return the <code>HEAD</code> commit
*/
public Optional<Commit> getCurrentHEAD() {
Optional<ExecRes> revParse = git.exec(dir, "rev-parse", "HEAD");
Function<ExecRes, Commit> toHEAD = res -> {
if (git.failed(res)) {
LOG.warning(() -> "Failed to obtain the current HEAD commit.");
return null;
}
return getCommitUnchecked(res.stdOut);
};
return revParse.map(toHEAD);
}
/**
* Returns a {@link Commit} for the given ID. The caller must ensure that the ID is a full SHA1 hash of a
* commit that exists in this repository.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment