githook to validate newly created branch names

前端 未结 3 672
不思量自难忘°
不思量自难忘° 2021-01-23 07:38

Does anyone know if there\'s a githook that will hook into the creation of a branch in order to reject the branch name before it\'s actually created?

I currently use com

3条回答
  •  感情败类
    2021-01-23 08:22

    Does anyone know if there's a githook that will hook into the creation of a branch in order to reject the branch name before it's actually created?

    The only place you can mandate anything at all is in your own repositories. In your pre-receive exit,

    while read old new ref; do 
        yourtesthere "$ref" || { rc=1; echo "$ref failed yourtesthere's validation"; }
    done
    exit $rc
    

    and no one can push a bad refname to your repository. A command to check a name before passing it along to git is down in alias / oneliner territory.

    You can distribute the yourtesthere command, of course, and anyone that wants can use it to test branch names in their own repositories, but just as your repositories are yours, their repositories are theirs.

提交回复
热议问题