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.

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.


I tried the above but the line :

import com.onresolve.scriptrunner.canned.stash.events.BlockOutOfDatePullRequests

 Throws an error "unable to resolve class "com.onresolve.scriptrunner.canned.stash.events.BlockOutOfDatePullRequests"

I'm on Bitbucket server 5.12.1 and Scriptrunner 5.4.18

I'm looking for something like this as well. We don't exactly force everyone to re-base / simply merge so I'm rather after a plain information if there are any commits in master that haven't landed in the feature branch - if yes - then merging should be blocked.

Like 1 person likes this

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 ...

1,906 views 7 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