JGit has no direct equivalent for git merge --abort. This piece of code can serve as a starting point:
repository.writeMergeCommitMsg( null );
repository.writeMergeHeads( null );
Git.wrap( repository ).reset().setMode( ResetType.HARD ).call();
It cleans up the merge status files, and then flushes the index and working directory into the contents of the current HEAD commit.
To check if two commits can be merged, you can also use the built-in merge. This will avoid checking for a conflicting commit in the working directory until reset later.
RevCommit parentCommit = mergeCommit.getParent( 0 );
revWalk.parseHeaders( parentCommit );
ResolveMerger merger = ( ResolveMerger )MergeStrategy.RESOLVE.newMerger( repository, true );
merger.setWorkingTreeIterator( new FileTreeIterator( repository ) );
merger.setBase( parentCommit.getTree() );
if( !merger.merge( headCommit, mergeCommit ) ) {
if( merger.failed() {
throw new IllegalStateException( "Should not happen with in-core mergers" );
}
}
source
share