evilmartians / lefthook

Fast and powerful Git hooks manager for any type of projects.
MIT License
5k stars 218 forks source link

pre-commit hook doesnt always run #835

Closed brentgreeff closed 1 month ago

brentgreeff commented 1 month ago

:wrench: Summary

I have a git alias which evaluates to : !git add . && git commit -v

The hooks runs most of the time, but if I commit something, the next commit, there is no hook.

Lefthook version

v1.7.18

Steps to reproduce

pre-commit:
  commands:
    rubocop:
      tags: backend style
      run: bin/rubocop
lefthook install
sync hooks: ✔️ (pre-commit)

Expected results

Hook should always run.

Actual results

Often hook doesnt run, there is not output from lefthook.

Possible Solution

running lefthook install again fixes the issue.

la .git/hooks/ does not have any hooks except samples, - I would expect to see the hook somewhere.

Something else weird. I did try to use Husky before lefthook. I keep deleting the .husky dir. It keeps coming back.

Logs / Screenshots

+ '[' '' = 0 ']'
+ call_lefthook run pre-commit
+ test -n ''
+ lefthook -h
+ lefthook run pre-commit
│ [lefthook] cmd:    [git rev-parse --show-toplevel]
│ [lefthook] stdout: /Users/brent/projects/assessments/confab

│ [lefthook] cmd:    [git rev-parse --git-path hooks]
│ [lefthook] stdout: .husky/_

│ [lefthook] cmd:    [git rev-parse --git-path info]
│ [lefthook] stdout: .git/info

│ [lefthook] cmd:    [git rev-parse --git-dir]
│ [lefthook] stdout: .git

│ [lefthook] cmd:    [git hash-object -t tree /dev/null]
│ [lefthook] stdout: 4b825dc642cb6eb9a060e54bf8d69288fbee4904

╭───────────────────────────────────────╮
│ 🥊 lefthook v1.7.18  hook: pre-commit │
╰───────────────────────────────────────╯
│ [lefthook] cmd:    [git status --short --porcelain]
│ [lefthook] dir:    /Users/brent/projects/assessments/confab
│ [lefthook] stdout: A  .husky/_/pre-commit
A  .husky/_/prepare-commit-msg           
M  Gemfile                               
M  Gemfile.lock                          
M  lefthook.yml                          

│ [lefthook] cmd:    [git diff --name-only --cached --diff-filter=ACMR]
│ [lefthook] dir:    /Users/brent/projects/assessments/confab
│ [lefthook] stdout: .husky/_/pre-commit
.husky/_/prepare-commit-msg           
Gemfile                               
Gemfile.lock                          
lefthook.yml                          

│ [lefthook] files before filters:                                                   
[.husky/_/pre-commit .husky/_/prepare-commit-msg Gemfile Gemfile.lock lefthook.yml]
│ [lefthook] files after filters:                                                    
[.husky/_/pre-commit .husky/_/prepare-commit-msg Gemfile Gemfile.lock lefthook.yml]
┃  rubocop ❯ 

Inspecting 32 files
................................

32 files inspected, no offenses detected

│ [lefthook] cmd:    [git stash list]
│ [lefthook] dir:    /Users/brent/projects/assessments/confab
│ [lefthook] stdout: 

  ────────────────────────────────────
summary: (done in 1.19 seconds)       
✔️  rubocop
+ '[' '' = 0 ']'
+ call_lefthook run prepare-commit-msg .git/COMMIT_EDITMSG
+ test -n ''
+ lefthook -h
+ lefthook run prepare-commit-msg .git/COMMIT_EDITMSG
│ [lefthook] cmd:    [git rev-parse --show-toplevel]
│ [lefthook] stdout: /Users/brent/projects/assessments/confab

│ [lefthook] cmd:    [git rev-parse --git-path hooks]
│ [lefthook] stdout: .husky/_

│ [lefthook] cmd:    [git rev-parse --git-path info]
│ [lefthook] stdout: .git/info

│ [lefthook] cmd:    [git rev-parse --git-dir]
│ [lefthook] stdout: .git

│ [lefthook] cmd:    [git hash-object -t tree /dev/null]
│ [lefthook] stdout: 4b825dc642cb6eb9a060e54bf8d69288fbee4904

╭───────────────────────────────────────────────╮
│ 🥊 lefthook v1.7.18  hook: prepare-commit-msg │
╰───────────────────────────────────────────────╯
│ [lefthook] skip: Hook prepare-commit-msg doesn't exist in the config
hint: Waiting for your editor to close the file...
brentgreeff commented 1 month ago

Hmmm, it seems that my the hook is being saved under .husky - is this project a fork of husky? that dir name is not intuitive.

brentgreeff commented 1 month ago

and - core.hookspath=.husky/_ is set in git config.

mrexox commented 1 month ago

Hey! Lefthook is not a husky fork. It uses git rev-parse --git-path hooks command to detect where you store git hooks and looks like you have .husky/_ configured.

Do you have both lefthook and husky in the project?

brentgreeff commented 1 month ago

Husky was removed - ie I deleted its files in the project.

but I just ran git config --unset core.hooksPath and then lefthook install and now my hooks are in .git/hooks/