Git remote/shared pre-commit hook

后端 未结 6 1368
失恋的感觉
失恋的感觉 2020-11-28 06:42

With a one official repository as the remote, and multiple local repositories cloned from it, can a pre-commit hook be scripted on that main repository and be enforced on al

6条回答
  •  -上瘾入骨i
    2020-11-28 07:15

    You can not have the pre-commit hook forced on peoples local repositories, but in your central repo you can still run a pre-receive hook.

    F. ex I needed to be sure the commit messages obeyed certain rules (for trac integration etc) so I used following pre-receive hook, which checks every commit messages being pushed to the central repository, and will deny the push if it is not welformed.

    #!/bin/sh
    while read rev_old rev_new ref
    do
        MALFORMED="$(git rev-list --oneline $rev_old..$rev_new | egrep -v '#[0-9]+' |  awk '{print $1}' )"
        if [ x"$MALFORMED" != x ]
        then
            echo Invallid commit message on $MALFORMED
            exit 1
        fi
    done
    
    

    for more info see f.ex https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

提交回复
热议问题