When creating a pull request, how do you ensure the source branch is branched from destination head?

Our workflow requires us to rebase our branches, before we create a pull request, in order to preserve the linear merge graph. It would be useful to be able to automatically decline a pull request (or as a minimum present some sort of warning, or notification) if a pull request has been accepted to upstream, since your original branch or last rebase. Is there any built in feature or plugin via the marketplace that supports this?

 

2 answers

@Mark Ingram - there is a paid add-on in the Marketplace called ScriptRunner for Stash that supports this. The documentation outlines how to block the creation of out of date Pull Requests. I think that might meet your needs.

Thanks, that's nearly exactly what I need, except we would like to be able to add multiple pull requests, but just block the merging if the request is out of date. With the solution you provided, you can only create 1 pull request at once. Is this possible?

I'm not really sure what you mean... you can always only create one PR per source and target branch combination. I would recommend using this policy, along with my answer. It's better to get people to rebase at the time they try to create the PR, otherwise they may well not even notice it's out of date. But also you need the merge check in my answer because it can go out of date. Ideally you want to notify them when it becomes out of date, as the person merging is probably not the person that can rebase it.

1 votes

Hi Mark... you want a mergecheck. I'm surprised this isn't already in the plugin, but it doesn't seem to be.

You can add a custom merge check with the following script:

import com.onresolve.scriptrunner.canned.stash.events.BlockOutOfDatePullRequests
 
def pullRequest = mergeRequest.pullRequest
def aheadBehindInfo = new BlockOutOfDatePullRequests().isPullRequestUpToDate(pullRequest)
 
if (! aheadBehindInfo.alreadyRebased) {
    mergeRequest.veto("Can't merge because out of date", "Please rebase then have another go...")
}

which looks like:

image2015-9-18 17:3:10.png

It can be difficult though to rebase if you've already merged to your feature branch from the target. But I guess once people have been bitten once they'll rebase rather than merge...

There is more chat about this kind of thing here: http://www.adaptavist.com/w/inside-adaptavists-stash-pull-request-workflow/

 

 

 

I think this is exactly what I'm after! I'll check it out and accept the answer if it works. Thanks.

No worries, get in touch with us via https://productsupport.adaptavist.com/servicedesk/customer/portal/3 if you need some hands-on help making it work.

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

646 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot