How to run local Git project hooks in addition to core.hooksPath global hooks?

后端 未结 2 867
暗喜
暗喜 2021-01-11 17:44

Currently I\'m using

git config --global core.hooksPath ~/.git/hooks

to configure global hooks for all my git projects. But if those proje

2条回答
  •  有刺的猬
    2021-01-11 18:27

    In order to execute the local hook from within the global one the following script snipped can be used:

    if [ -e ./.git/hooks/commit-msg ]; then
        ./.git/hooks/commit-msg "$@"
    fi
    

    The global hook runs within the repo directory where the commit is made and can therefore check if a local hook exists in it's .git directory.

    Note that you have to adopt the hook name if you are using something different than a commit message hook.

提交回复
热议问题