Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

githooks

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!

like image 570
Vishaal Avatar asked Jul 04 '18 17:07

Vishaal


People also ask

How do I get rid of core hooksPath?

If the option is set in your local repository and you want to undo it, then git config --unset core. hooksPath is sufficient to unset it, which will make Git pick the default option.

What is core hooksPath?

The core. hooksPath config allows you to set a directory where the hooks are located for a repository. This is particularly useful if trying to commit your hooks to the repository (e.g. for sharing hooks with the team).

Where are Git hooks stored?

Git hooks are shell scripts found in the hidden . git/hooks directory of a Git repository. These scripts trigger actions in response to specific events, so they can help you automate your development lifecycle. Although you may never have noticed them, every Git repository includes 12 sample scripts.


1 Answers

This will need to be done per hook, but I confirmed it works for prepare-commit-msg.

# run the global prepare-commit-msg if it is present
if [ -e `git config --global core.hookspath`/prepare-commit-msg ]; then
    `git config --global core.hookspath`/prepare-commit-msg "$@"
fi
# otherwise do nothing

I'm using that with Husky 7 in a file at .husky/prepare-commit-msg. Should work as a local hook as well.

like image 81
jcollum Avatar answered Oct 05 '22 03:10

jcollum