Open ryuran opened 3 years ago
Git always sets working directory to repository root on hooks invocation:
Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository.
See https://git-scm.com/docs/githooks
Because of that lefthook run hook
command behavior is wrong and should be changed to match git behavior.
By the way:
On a real commit:
/gitRootDirectory/packages/sub /gitRootDirectory/packages/sub
@ryuran Isn't it a typo? It should be /gitRootDirectory
for both pwd
and git rev-parse --show-toplevel
I believe
No it's not a typo.
I use root
option for a monorepo.
But I encounter some issue with git diff
or git apply
into the hook.
It seems to mess up because of this working directory change.
Yeah I can confirm monorepo support is messed up. The lefthook.yml
supports the root:
directive but does nothing to propagate it to the git hooks. Because the git hooks avoid doing anything with the root:
directive monorepo support doesn't work.
Have you tested this on latest lefthook versions? Does the issue persist on lefthook 1.7.*
?
Hello,
@arkweid/lefthook@0.7.6
git version2.32.0
I spoted a difference when the script is run by lefthook or during a real commit with this config:
On a
npx lefthook run pre-commit
(I think this one is correct):On a real commit: