evilmartians / lefthook

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

"lefthook run pre-push" hangs waiting for stdin when git-lfs is active #836

Closed indrat closed 1 month ago

indrat commented 1 month ago

:wrench: Summary

When manually running lefthook run pre-push when git lfs is active/installed lefthook stalls until a new-line is entered.

Lefthook version

› lefthook version -f     
1.7.18

Steps to reproduce

in a new git repo

$ git lfs install
Updated Git hooks.
Git LFS initialized.
$ lefthook install
$ cat <<EOF > lefthook.yml 
pre-push:                   
  commands:
    cat-stdin:
      run: cat
      use_stdin: true
EOF
# stalls on git-lfs, until new-line
$ lefthook run pre-push

Expected results

No stall when running pre-push when git lfs is active.

Actual results

lefthook stalls until a new-line is entered before running the commands.

Possible Solution

Possibly the git-lfs pre-push hooks shouldn't be run when running manually via lefthook run pre-push?

Logs / Screenshots

$ LEFTHOOK_VERBOSE=true lefthook run pre-push
│ [lefthook] cmd:    [git rev-parse --show-toplevel]
│ [lefthook] stdout: /Users/indra/foo

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

│ [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-push │
╰─────────────────────────────────────╯
│ [git-lfs] executing hook: git lfs pre-push 
│ [lefthook] cmd:    [git lfs pre-push]
<<<<< STALLS HERE UNTIL NEW-LINE >>>>>>
│ [lefthook] error:  exit status 1
│ [git-lfs] stdout: This should be run through Git's pre-push hook.  Run `git lfs update` to install it.
│ [git-lfs] error:  exit status 1
│ [lefthook] cmd:    [git diff --name-only HEAD @{push}]
│ [lefthook] error:  exit status 128
mrexox commented 1 month ago

Hey @indrat! Thank you for submitting the PR! I will try to ignore lfs hook when pre-push is being run manually. But I believe that for consistency lefthook should behave the same way regardless of the execution environment.

pjjw commented 1 month ago

subscribe