I need the user who last changed/committed a file in our GIT repository.
The project consists of many subfolders, and the master branch has many merged commits.
I tried :
File gitWorkDir = new File("D:/gitfolder/");
Git git = Git.open(gitWorkDir);
RevCommit latestCommit;
String path = "test.txt";
try( RevWalk revWalk = new RevWalk( git.getRepository() ) ) {
Ref headRef = git.getRepository().exactRef( Constants.HEAD );
RevCommit headCommit = revWalk.parseCommit( headRef.getObjectId());
revWalk.markStart( headCommit );
revWalk.sort( RevSort.COMMIT_TIME_DESC );
TreeFilter filter = AndTreeFilter.create( PathFilter.create( path ), TreeFilter.ANY_DIFF );
revWalk.setTreeFilter(filter);
latestCommit = revWalk.next();
git.close();
}
the Repository and HEAD commit are there, but latestCommit
is always null.
Do I have to define the whole path to my file? Is it a problem that the master branch is so "branched out" so maybe the commit cannot be found, or what else could be the problem?