Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

Implementing Git flow branching model

Suyash Khandwe
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 9, 2017

Here's my problem - We migrated from SVN to GIT a while back, but it has been hard to get my team avoiding merge to master before something goes to production.

As a result, I want to set up something which would force the user to merge to master only from a release/* or a hotfix/* branch. Is there any way (event a custom hook would help), that I can restrict the source branch to release/* and hotfix/* when the target branch is the master.

 

Please pardon my lack of knowledge on writing the hooks and  I'd really appreciate if someone could actually give me a hint on how to write this hook.

 

The model I am trying to implement is something like this - https://namethattech.wordpress.com/2014/11/26/bamboo-gitflow/

1 answer

0 votes
G__Sylvie_Davies__bit-booster_com_
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.
March 9, 2017


Here's a snippet from my Foxtrot Merge Blocker to help get you started:

public class MyHook implements RepositoryMergeRequestCheck {

@Override
public void check(@Nonnull RepositoryMergeRequestCheckContext context) {
    MergeRequest mr = context.getMergeRequest();
    PullRequest pr = mr.getPullRequest();
    PullRequestRef fromRef = pr.getFromRef();
    PullRequestRef toRef = pr.getToRef();
    Repository tR = toRef.getRepository();
    Repository fR = fromRef.getRepository();
    String fromBranch = fromRef.getDisplayId();
    String toBranch = toRef.getDisplayId();

    // etc... your logic goes here.
    // keep an eye out for PR's coming in from forks, though! 

    mr.veto("bad-source-branch", "THOU SHALL NOT MERGE");
}
 
}

 

Setting up your pom.xml and atlassian-plugin.xml is also a pain, but the atlassian hook tutorial should help get you started, or study some of the open source hooks out there (e.g., yacc).

 

p.s.  I'm the original author of the add-on Bit-Booster for Bitbucket Server.

Suyash Khandwe
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2017

Thanks a lot for the headstart. I would play around with this and see where I land.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events