/** * Find the commit that last changed the given path starting at the commit * that HEAD currently points to * * @param repository * @param path * @return commit */ public static RevCommit getLastCommit(final Repository repository, final String path) { return getLastCommit(repository, HEAD, path); }
private static RevCommit getLastCommit(Git git, String branch, String path) { RevCommit profileRef = null; try { Ref versionRef = git.getRepository().getRefDatabase().getRef(branch); if (versionRef != null) { String revision = versionRef.getObjectId().getName(); // need to force unix style on windows if (path != null) { path = path.replace(File.separatorChar, '/'); } profileRef = CommitUtils.getLastCommit(git.getRepository(), revision, path != null ? path : "."); } } catch (IOException ex) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Failed to get the last commit for " + path + " on branch " + branch, ex); } } return profileRef; }