BitBucket Plugin Development For updating commit message on SQUASH Merge

I have developed a plugin to update the bitbucket commit message on (SQUASH MERGE ) 

The problem is if I create 2 Pull Request from Master :

Upon 1st Pull request Merge commit message is getting updated as I wanted But

the 2nd pull request Im not ablet to merge it is giving the following error.

"You are attempting to modify a pull request based on out-of-date information."


Java code from Bitbucket plugin any suggestion would be helpfull:

public void onMergeEvent(PullRequestMergedEvent mergeEvent)

Repository Repo = mergeEvent.getRepository();
String repoName = Repo.toString();
if (repoName.equals("VI/fabric[192]"))


String message = mergeEvent.getMessage();

File repo_dir = application_properties_service.getRepositoryDir(Repo);
String commitID = mergeEvent.getCommit().getId();

org.eclipse.jgit.lib.Repository jgit_repo = new FileRepositoryBuilder().setGitDir(repo_dir).build();
ObjectId objectID = ObjectId.fromString(commitID);
RevWalk revWalk = new RevWalk(jgit_repo);
RevCommit oldCommit = revWalk.parseCommit(objectID);

PersonIdent author = oldCommit.getAuthorIdent();
PersonIdent committer = oldCommit.getCommitterIdent();
int prentPosition = oldCommit.getParentCount();
RevCommit parent = oldCommit.getParent(prentPosition-1);
Charset encoding = oldCommit.getEncoding();
RevTree indexTreeId = oldCommit.getTree();
ObjectId headId = jgit_repo.resolve(Constants.HEAD + "^{commit}");

CommitBuilder commit = new CommitBuilder();
ObjectInserter odi = jgit_repo.newObjectInserter();
ObjectId objCommitId = odi.insert(commit);

RevCommit revCommit = revWalk.parseCommit(objCommitId);
RefUpdate ru = jgit_repo.updateRef(Constants.HEAD);
catch (Exception ie) {



catch (Exception ie) {


1 answer

0 votes
Adam Ahmed Atlassian Team May 17, 2018

Sorry for the late response on this - just found it and I think it deserves at least some answer.

The main issue I think is that you're updating a merge commit after-the-fact. While you can certainly do this, the experience won't be great. For example the activity for the PR will say it was merged via the old commit hash, not your new one. While there are ways to do it beforehand (e.g. a repository pre-hook on PR merges), I believe they still wouldn't quite fit with the rest of the PR experience. I can't think of a good way to create a custom merge commit with our current API, but I'd be interested in hearing what you want to change about the commit. It's possible our Merge Strategies feature (which supports rebases, squashes, fast-forward, etc) will cover your requirements already, or perhaps I could find a dev who can help a bit more if I know what you're trying to acheive.

In your Java code, it also looks like you're using JGit. Just a heads up that JGit is great, but we've had issues using it in Bitbucket Server before from a performance and stability POV. You probably don't need to add that external dependency anyway - we have built-in APIs that should be helpful for crafting Git commands. This file has a few examples of using the very generic CLI builder. You start with a GitCommandBuilderFactory and can create, for example, a builder for creating a commit

private GitCommandBuildFactory builderFactory;


GitCommitBuilder commitBuilder = builderFactory.builder(repository).commit();
GitCommand<Void> commitCommand = commitBuilder.message("Hello").all(true).committer("Pegasus", "").build();;



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

891 views 5 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you