We have many repo components. And we would like to execute a pre-commit
hook for a local repo when git commit
, without affecting other repos.
Currently the core.hooksPath is set to a global directory for everyone, say: C:/uers/userName/git-hooks
folder which contains quite a few global hooks that will run when git commit
.
And there is only one pre-commit
file in a local repo’s .git/hooks
folder and it’s expected to run when git commit only for this repo.
However, to make the local pre-commit work, It needs to set git config --local core.hooksPath
to .git/hooks
which will overwrite the default global setting and influence other devs who only need to use global core.hooksPath
.
I found a way to create a symlink mapping C:/uers/userName/git-hooks/pre-commit
to d:/project1/.git/hooks/pre-commit
It works for the current project, but when it comes to other projects, when 'git commit'
other repos also ran this pre-commit
file, which is not as expected.
Something I have tried:
-
Mapping
C:/uers/userName/git-hooks/**project1/pre-commit**
to
d:/project1/.git/hooks/pre-commit
but it don’t work, git commit can’t reach the real hook file; -
Mapping
C:/uers/userName/git-hooks/**project1-pre-commit**
tod:/project1/.git/hooks/pre-commit
same result as above
Question:
does anyone have experience how to correctly symlink the path so that the symlink can only work for to read the local repo’s .git/hooks folder, and other repos don’t have to read this special pre-commit
hook designed for that repo only?