Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Accessing the conflicting lines(Given a conflicting merge RevCommit or its parents, how to retrieve the conflicting lines?)
icon5.gif  Accessing the conflicting lines [message #1727944] Tue, 29 March 2016 15:30 Go to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

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 Go to previous messageGo to next message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

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 Go to previous message
Alcemir Santos is currently offline Alcemir SantosFriend
Messages: 23
Registered: July 2012
Junior Member

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();
Previous Topic:aborting a conflicted merge
Next Topic:Can't switch branches after last upgrade
Goto Forum:
  


Current Time: Tue Apr 16 11:00:38 GMT 2024

Powered by FUDForum. Page generated in 0.05474 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top