Get a list of modified files after pulling out with JGit

I would like to know how I can get a list of modified files after a transfer request.

I use this to get all merged commits, but I want to know all the modified files.

Git git = new Git(localRepo); PullCommand pullCmd = git.pull(); PullResult pullResult = pullCmd.call(); MergeResult mergeResult = pullResult.getMergeResult(); ObjectId[] mergedCommits = mergeResult.getMergedCommits(); for (ObjectId mergedCommit : mergedCommits) { // And now? } 
+2
java git jgit
source share
2 answers

Based on previous comments / questions:

Get current head before :

 ObjectId oldHead = repository.resolve("HEAD^{tree}"); 

And then pull it out again:

 ObjectId head = repository.resolve("HEAD^{tree}"); 

Then you should be able to run diff in the same way as in How to make the equivalent of "git diff -name-status" with jgit? :

 ObjectReader reader = repository.newObjectReader(); CanonicalTreeParser oldTreeIter = new CanonicalTreeParser(); oldTreeIter.reset(reader, oldHead); CanonicalTreeParser newTreeIter = new CanonicalTreeParser(); newTreeIter.reset(reader, head); List<DiffEntry> diffs= git.diff() .setNewTree(newTreeIter) .setOldTree(oldTreeIter) .call(); 
+2
source share


$git diff-tree --no-renames --no-commit-id --name-only -r

My approach that works for me:
1. Put all the hashes in the file (say tempfile1)
2.xargs -n1 git diff-tree --no-renames --no-commit-id --name-only -r <tempfile1 → tempfile2
3. Sort tempfile2 | uniq -> final (To remove duplicate entries)

the final file will have all modified files

-one
source share

All Articles