1

The requirement is to set the restrictions such that any new branches pushed to Stash from a developer's machine must follow our naming convention of

"feature/PPT-", "bugfix/PPT-", "hotfix/PPT-", "feature/QC", "bugfix/QC*", or "hotfix/QC*".

We have Yet Another Commit Checker pre-receive hook enabled and it has an option to restrict using

Branch Regex -

If present, pushes to branches that don't match this regex will be blocked. What is the format to be used here, to meet my requirement here? Branch Name Regex

If present, only branches with names that match this regex will be allowed to be created. This affects both new branches being pushed and branches created within the Bitbucket Server UI.

For example, master|(?:(?:bugfix|hotfix|feature)/[A-Z]+-\d+-.+) would enforce that pushes should be done to branches that follow the Bitbucket Server Branching Model naming convention.

https://github.com/sford/yet-another-commit-checker

Anyone using this already?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sumant
  • 127
  • 1
  • 3
  • 11
  • Can you be more clear? I read this question twice and now I am confused what do you actually want to know. Yet another commit checker plugin says 'If present, only branches with names that match this regex will be allowed to be created. This affects both new branches being pushed and branches created within the Stash UI.' Why are you looking for two separate regex? – binarymemoir Feb 05 '16 at 19:07
  • Here is what happens: 1. There is no restrictions with the branch name creation with the branch regex. 2. With this entry in the hook - master|(?:(?:bugfix|hotfix|feature)/QC|PPT), it allows only the push to branch feature/QC, hotfix/QC, bugfix/QC but fails to consider feature/PPT or hotfix/PPT as a valid branch name. – sumant Feb 09 '16 at 01:37

2 Answers2

1

master|develop|(?:(?:bugfix/QC.|hotfix/QC.|feature/QC.)), master|develop|(?:(?:bugfix/PPT|hotfix/PPT|feature/PPT-.))

This is the entry that needs to go to the Pre-receive hook for branch regex.

This will restrict the push from the developer Stash/Atlassian Sourcetree to branches which doesn't match this requirement.

Example:

Try to push to a branch feature/PPT-Test from the local Atlassian Source tree repo and it works.

However, to push to a branch feature/PPTRandom from the local Atlassian Source tree repo will fail as the regex doesn't match.

It's (dotstar) for wildcard

sumant
  • 127
  • 1
  • 3
  • 11
0

We need a regex expression to enforce the branch name to a certain pattern, I updated it to the following regex and it worked good for me.

feature/([a-zA-Z0-9_-]*)|bugfix/([a-zA-Z0-9_-]*)|hotfix/([.a-zA-Z0-9_-]*)|release/([.a-zA-Z0-9_-]*)
Imran
  • 5,542
  • 3
  • 23
  • 46
Arc
  • 1
  • 2