protected ObjectId getHeadObject() throws GitRepositoryException {
if (this.headObject == null) {
try {
this.headObject = this.repository.resolve(this.headRef);
} catch (AmbiguousObjectException e) {
throw new GitRepositoryException(
String.format("Ref \"%s\" is ambiguous.", this.headRef),
e);
} catch (IOException e) {
throw new GitRepositoryException(
String.format("Ref \"%s\" could not be resolved.", this.headRef),
e);
}
}
if (this.headObject == null) {
if (this.headRef.equals("HEAD")) {
throw new GitRepositoryException(
"HEAD could not be resolved. You're probably on an unborn branch.");
}
throw new GitRepositoryException(
String.format("Ref \"%s\" is invalid.", this.headRef));
}
return this.headObject;
}