Reputation: 189
I would like to create a "pre-branch" hook that blocks users from creating a branch with a name that matches a given regex expression if another branch already exists with a name that matches that same expression.
Optimally, this could be hosted locally and trigger before the user ever touches the remote repo, but I am open to any method that would prevent a branch with the undesired name from being created on the remote (pre-push or pre-receive hooks maybe?)
Just moving over to git, so please treat my knowledge of git hooks as extremely novice.
Thanks!
Upvotes: 8
Views: 2452
Reputation: 15570
Doing that locally isn't advisable - what a developer does in his own repo is purely his own business.
You can install a server-side hook that checks the reference's names that are being pushed. The first script in this example shows how to get the reference name.
If the developer wants to use any name, he can do it - and then, if it tries to push a bad name, he can still change that to any other name he wants using the git push <remote> <localref>:<remoteref>
notation, as in git push origin badly_named:ok_named
.
Upvotes: 5