Accessing the conflicting lines [message #1727944] |
Tue, 29 March 2016 15:30 |
|
Hi,
I am trying to retrieve the conflicting lines of a given merge RevCommit. I have tried by looping in the HunkHeaders (as follows), but it seems that such information is not there.
for (DiffEntry entry : entries) {
FileHeader fileHeader = diffFormatter.toFileHeader(entry);
List<? extends HunkHeader> hunks = fileHeader.getHunks();
for (HunkHeader hunk : hunks) {
EditList eList = hunk.toEditList();
// Do whatever i want....
}
}
I also found the "MergeResult.getConflicts()" method that seems to have the information that i am looking for. However, the i only have the SHA1 of the parents of the merge commit which i managed to retrieve the merge RevCommit. I saw some examples on how to execute a merge with JGit API, but all of them used branches to perform the such action.
My questions are: Can i access the conflicting lines without do the actual merge? If yes, how can i do that? If no, what is the best way to retrieve the branches of each parent commit and perform the merge with the "MergeCommand"?
|
|
|
Re: Accessing the conflicting lines [message #1728342 is a reply to message #1727944] |
Sat, 02 April 2016 10:13 |
|
I decided to go for doing the actual merge, after no success without doing that.
I am trying to run all the merge scenarios in batch (as follows in the snippet), but they execute only the first time. In a second execution, the "getMergeScenarios()" returns a empty list.
List<RevCommit> list = getMergeCommits();
for (RevCommit mergeCommit : list) {
RevCommit leftParent = mergeCommit.getParent(0);
RevCommit rightParent = mergeCommit.getParent(1);
CheckoutCommand ckoutCmd = git.checkout();
ckoutCmd.setName(leftParent.getName());
ckoutCmd.setStartPoint(leftParent);
ckoutCmd.call();
MergeCommand mergeCmd = git.merge();
mergeCmd.setCommit(false);
mergeCmd.include(rightParent);
MergeResult mResult = mergeCmd.call();
if(mResult.getMergeStatus()==MergeStatus.CONFLICTING){
printMergeResult(mResult);
}
// reset the index and work directory to HEAD
Git.wrap( repository ).reset().setMode( ResetType.HARD ).call();
}
Am I missing something important?
|
|
|
Re: Accessing the conflicting lines [message #1732240 is a reply to message #1728342] |
Fri, 13 May 2016 17:23 |
|
The temporary solution was a hard reset to the commit that was being merged. I did this because there is no such "run merge --abort" equivalent implemented in the JGit so far.
Thus,
Git.wrap( repository ).reset().setRef(leftParent().getName()).setMode(ResetType.HARD).call();
instead of
Git.wrap( repository ).reset().setMode( ResetType.HARD ).call();
|
|
|
Powered by
FUDForum. Page generated in 0.03087 seconds