I am trying to perform with JGit all the merge scenarios from a project that had conflicts.
Is it possible to get the conflicts prior to the actual merge? In other words, is it possible to simulate a merge with JGit?
My goal is to access the conflicting lines of each file for all the merge scenarios of a project.
You can use one of the ThreeWayMergers to determine if two commits can be merged.
By default JGit's MergeCommand uses the recursive merge strategy. Therefore you would probably want to use this merger.
Make sure to create an in core merger (set the second parameter of newMerger to true). While in this mode, the merger does not touch the work directory.
ThreeWayMerger merger = MergeStrategy.RECURSIVE.newMerger(repository, true);
boolean canMerge = merger.merge(headCommit, commitToMerge);
The merge method returns true if the given commits can be merged and false otherwise.
The base commit can either be explicitly set with setBase or the common ancestor is used.
The ResolveMerger and RecursiveMerger also provide methods to query which file(s) cannot be merged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With