How can I tell with JGit which branches have been merged for mastering?
1 answer
RevWalk::isMergedInto()
can be used to determine if a union has been merged into another. That is, it isMergedInto
returns true if the value passed in the first argument is an ancestor of the second specified commit.
try( RevWalk revWalk = new RevWalk( repository ) ) {
RevCommit masterHead = revWalk.parseCommit( repository.resolve( "refs/heads/master" );
RevCommit otherHead = revWalk.parseCommit( repository.resolve( "refs/heads/other-branch" );
if( revWalk.isMergedInto( otherHead, masterHead ) ) {
...
}
}
To get a list of all branches, use ListBranchesCommand
:
List<Ref> branches = Git.wrap( repository ).listBranches().setListMode( ListMode.ALL ).call();
+5
source to share