Git global hooks and project hooks

旧时模样 提交于 2019-12-06 23:31:46

问题


Currently I'm using

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

to configure global hooks for all my git projects. But if those projects contain hooks, they're not run.

I'd like to run the global hook as well as the project hooks. Thank you!


回答1:


I think the only way is for your global hooks to check if a corresponding local hook exists and run it.

This is not a complete solution because some hooks (pre-push, for example) accepts standard input in addition to command line parameters. If one of the hooks consumes the standard input the other doesn't have a chance.




回答2:


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.



来源:https://stackoverflow.com/questions/51178382/git-global-hooks-and-project-hooks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!