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

Hook on branch creation to record 'parent' branch name that new branch was created from?

Mike Rago February 11, 2020

We have a large team working on several releases at once.  We use Bitbucket to create branches, pull requests for merging and auto-merge to merge forward to future release branches.  We need a way to ensure that branches created from a release branch can only be merged to that release branch in a pull request.

One thought is to have a hook on branch creation that adds the 'parent' branch name to the new branch's description.  Then another hook on pull request creation that verifies the destination branch matches the parent branch, or perhaps modifies the destination list to only include the parent release branch.  This would also have to exempt release to release and release to develop merges triggered by the auto-merge

2 answers

1 accepted

0 votes
Answer accepted
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 11, 2020

Hi @Mike Rago,

Welcome to Atlassian Community.

Git does not store the parent a branch was branched off from, to Git branches are just pointers to specific commits. So the closest you can get is to see if pushed commits are ancestors of a commit on the branch you are pushing to. Take a look at How to find the nearest parent of a Git branch? for more information and solutions. 

Mike Rago February 11, 2020

Thanks Mikael for the quick response and the link.  I understand how Git stores branches.  I was wondering if Bitbucket itself could be used to gather the info needed.  When we create a branch in Bitbucket, we have to select the "Branch from" branch.  I am wondering if at this point we can get the "from branch" from Bitbucket and add it to the new branch's description.  We could then use this info in a pull request hook to verify that we are merging into the correct release branch.

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 11, 2020

Bitbucket does not store that information, what the Branch from is used for is to get the latest commit on that branch.

0 votes
Stanislav Seletskiy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2020

Hello @Mike Rago

I'm one of mainteiners of External Hooks Add-on for Bitbucket.

It supports both pre-receive & merge check hooks, so you can implement branch checking logic here easily.

By using merge check you can ensure that target branch is going to be merged into release branch with couple of git commands in bash script.

We will be happy to help you with configuration, just drop us an e-mail at we@reconquest.io.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events