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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bitbucket does not store that information, what the Branch from is used for is to get the latest commit on that branch.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.