Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lefthook install fails in git worktree with Error: exit status 128 when core.hooksPath doesn't exist #901

Open
technicalpickles opened this issue Dec 20, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@technicalpickles
Copy link
Contributor

🔧 Summary

I'm trying out git worktrees as part of my workflow, and when I try to lefthook install, I get an error like:

❯ lefthook install
Error: exit status 128

Honestly, I'm not positive if hooks are expected to work with worktrees or not 🤔

Lefthook version

❯ lefthook version -f
1.9.3 829cc92

Steps to reproduce

  • from a git checkout
  • git worktree add -B test-branch ~/path/to/worktree/destination
  • cd ~/path/to/worktree/destination
  • lefthook install

Expected results

I'd expect the same results as in a regular git checkout:

❯ lefthook install
sync hooks: ✔️ (fix, post-checkout, post-merge, pre-push, pre-commit)

Actual results

❯ lefthook install
Error: exit status 128

Possible Solution

Logs / Screenshots

❯ LEFTHOOK_VERBOSE=1 lefthook install
│ [lefthook] cmd:    [git version]
│ [lefthook] stdout: git version 2.47.1

│ [lefthook] cmd:    [git rev-parse --path-format=absolute --show-toplevel]
│ [lefthook] stdout: /Users/josh.nichols/workspace/worktrees/myapp/beta

│ [lefthook] cmd:    [git rev-parse --path-format=absolute --git-path hooks]
│ [lefthook] error:  exit status 128
│ [lefthook] stdout:
│ [lefthook] stderr: fatal: Invalid path '/Users/josh.nichols/workspace/worktrees/myapp/beta/.git/hooks': Not a directory

Error: exit status 128

I'm not familiar with git worktrees enough yet, but in practice, .git is a file, not a directory:

❯ cat .git
gitdir: /Users/josh.nichols/workspace/myapp/.git/worktrees/beta
@technicalpickles technicalpickles added the bug Something isn't working label Dec 20, 2024
@mrexox
Copy link
Member

mrexox commented Dec 20, 2024

Wow, thank you for this issue. I am not familiar with Git worktrees yet, but I think this must be fixable.

@mrexox
Copy link
Member

mrexox commented Dec 20, 2024

When you are in a worktree directory, does this command return 0 or 128 exit status?

git rev-parse --path-format=absolute --git-path hooks

I've just tried to reproduce the issue but it successfully installed lefthook hooks 🤔

@technicalpickles technicalpickles changed the title lefthook install fails in git worktree with Error: exit status 128 lefthook install fails in git worktree with Error: exit status 128 when using a relative core.hooksPath Dec 20, 2024
@technicalpickles
Copy link
Contributor Author

For our main application, it returns with an exit code 128 I tried it another repo, and it works 🤔 🤔

Having done that, I just remembered we set git config --local core.hooksPath .git/hooks as part of our setup 🤦🏻 There's some legacy reason for it, but it seems that it works with an absolute path: git config --local core.hooksPath $(pwd)/.git/hooks

@technicalpickles technicalpickles changed the title lefthook install fails in git worktree with Error: exit status 128 when using a relative core.hooksPath lefthook install fails in git worktree with Error: exit status 128 when core.hooksPath doesn't exist Dec 20, 2024
@technicalpickles
Copy link
Contributor Author

Reframing this as "lefthook install" failing when core.hooksPath doesn't exist 😁 I'm not sure how likely someone is to run into this in general though.

@mrexox
Copy link
Member

mrexox commented Dec 21, 2024

Oh, in this case it's good to have this issue as a reference. But I think for lefthook there's no simple fix, since lefthook relies a lot on git configuration. I don't think it's good to check whether core.hooksPath exists and add a fallback to $(pwd)/.git/hooks (I guess this won't work in case of worktrees).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants