git_template icon indicating copy to clipboard operation
git_template copied to clipboard

Branch naming validation

Open vv12131415 opened this issue 4 years ago • 6 comments

I'm in love at first sight with this repo :heart:

My idea is to validate branch name against some pattern

so for example, as I personally mostly use git flow.

Plus I want to see ticket number as a part of the branch so I write this regex

^(feature|hotfix|bugfix|release)\/(ABC\-)\d{1,}\-[a-zA-Z]+

which will match this one

feature/ABC-3-asddas

vv12131415 avatar Jun 24 '20 18:06 vv12131415

Oh wow thanks that's humbling, really!

Regarding the branch naming validation, when should it be performed? On creation, before push, something else? Maybe it should be configurable?

greg0ire avatar Jun 25 '20 06:06 greg0ire

I think, before push is the right one. Because if it's incorrect, you can easily change the name with

git checkout -b new-branch-name

vv12131415 avatar Jun 25 '20 08:06 vv12131415

I think it would be better to check on creation

Edo78 avatar Jun 25 '20 11:06 Edo78

git checkout -b new-branch-name

Or git branch -m

Anyway, both things can be done, and we can let the user choose on what event they want the check to happen, maybe?

greg0ire avatar Jun 25 '20 11:06 greg0ire

@greg0ire yes.

I just don't want to over engeneer

vv12131415 avatar Jun 25 '20 12:06 vv12131415

Here is how it's done for make in case you are wondering:

https://github.com/greg0ire/git_template/blob/820f947e371ea8025b65490c19ae20306b110425/template/hooks/make/pre-push#L6-L8

https://github.com/greg0ire/git_template/blob/820f947e371ea8025b65490c19ae20306b110425/template/hooks/make/pre-commit#L6-L8

greg0ire avatar Jun 25 '20 16:06 greg0ire