ReflogReader reflogReader = repository.getReflogReader(Constants.HEAD);
if (reflogReader != null) {
List<ReflogEntry> lastEntry = reflogReader.getReverseEntries();
for (ReflogEntry entry : lastEntry) {
if (entry.getNewId().name().equals(commitId)) {
CheckoutEntry checkoutEntry = entry.parseCheckout();
if (checkoutEntry != null) {
Ref ref = repository.getRef(checkoutEntry.getToBranch());
if (ref != null) {
if (ref.getObjectId().getName()
.equals(commitId))
return checkoutEntry.getToBranch();
ref = repository.peel(ref);
}
if (ref != null) {
ObjectId id = ref.getPeeledObjectId();
if (id != null && id.getName().equals(commitId))
return checkoutEntry.getToBranch();
}
}
}
}
}