Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I check with java api that one branch merged to another

Boris Gorbylev March 4, 2015

How can I check with java api that one branch merged to another?

In pure git I can 

git branch --no-merged master
git branch --merged master

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Boris Gorbylev March 6, 2015
private boolean isMergedBranch(Repository repository, Branch branch, Branch baseBranch) {
    final Integer[] commitsCount = new Integer[1];
    commitsCount[0] = 0;
    CommitCallback commitCallback = new AbstractCommitCallback() {
        @Override
        public boolean onCommit(Commit commit) {
            commitsCount[0]++;
            return true;
        }
    };
    compareService.streamCommits(
            new CompareRequest.Builder()
                    .fromRef(branch.getId(), repository)
                    .toRef(baseBranch.getId(), repository)
                    .build(),
            commitCallback
    );
    return commitsCount[0] == 0;
}
TAGS
AUG Leaders

Atlassian Community Events