githook to validate newly created branch names

前端 未结 3 667
不思量自难忘°
不思量自难忘° 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:18

    There is not (and to some extent it can't be controlled: branch names are transferred across the network during fetch and push, via refspecs, and refspecs are somewhat limited).

    There is a git command, git check-ref-format; its documentation describes what Git allows. (Branch names are simply any reference that starts with refs/heads/.)

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-23 08:34

    Seems like you are referring to placing a policy for commits or branch creation. There is a git config command which helps in putting some template in place eg:

    $ git config --global commit.template ~/.template.txt $ git commit

    subject line

    what happened

    [ticket: X]

    # Please enter the commit message .......
    #
    # modified:   lib/test.rb
    #
    ~
    ~
    ".git/COMMIT_EDITMSG"
    

    Sorry if this did not help. Thanks.

    0 讨论(0)
提交回复
热议问题