-
Notifications
You must be signed in to change notification settings - Fork 220
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
pre-push
hooks are broken because lefthook does not forward STDIN
#508
Comments
Hey! Have you tried |
I have not - the docs didn't imply they would do what I was looking to do, but I'll give that I try and let you know if it works. |
@mrexox sadly, it does not work. I tried with the following: pre-push:
scripts:
talisman_hook_script:
runner: bash
interactive: true
follow: true Looking at the entry hook that For example, in this snippet within if lefthook -h >/dev/null 2>&1
then
eval lefthook $@ I would have expected conceptually something more like: hookname="$(basename $0)"
if [ 'pre-push' = "$hookname" ]; then
cat - | eval lefthook "$@"
else
eval lefthook "$@"
fi And not to mention any golang code that needs to glue STDIN to each |
@marques-l-GILD, can you please send a link to a test repo where the bug can be reproduced? Or maybe a Lefthook is not supposed to work with pipes (as long as I know, STDIN and pipes have different mechanisms). For example: # lefthook.yml
test:
commands:
read-and-print:
interactive: true
run: |
read line
echo Got: $line
I think if you send your |
@mrexox sure, I might need some time to pull out of a private repo into a public test account with things set up. I probably won't get to that until after my workday, but I'll try to get that done tonight (I'm in pacific time zone). And just to clarify the use case, the behavior I'm looking for is to be non-interactive -- the user doesn't supply any input themselves. It's that That said, you might be right that pipes and STDIN may have different nuances. Pipes aside, this would achieve the same thing without a pipe (assuming your shell is lefthook run test <<< "also doesn't work" To be fully compatible with git's This is the documented behavior: https://git-scm.com/docs/githooks#_pre_push |
@mrexox Ok I created a separate repo with a very simple test case. Instructions are in the README. Do note that you should fork this so you can test the https://github.com/marques-l-GILD/lefthook-pre-push-test Also, please let me know how I can help, whether it's clarifications, or writing code to help implement/fix this (I just might need some direction on where in the lefthook codebase to look). Thanks for your help! |
It's also worth mentioning there a few other hooks that also use STDIN, but probably uncommon (even AFAIK, here are the hooks that receive information from
|
Got it, thank you for the repo example. I have checked how it works, and I could make it work with the following config: # lefthook.yml
---
pre-push:
follow: true
scripts:
# This is an example script, adapted from .git/hooks/pre-push.sample
"pre-push.sh":
runner: sh
# This is the "real" script I want to run on pre-push
talisman_hook_script:
runner: bash However it fails to do |
@mrexox I totally understand you have priorities on top of supporting OSS, so I'm still thankful for the effort of just looking into it. 🙏 |
+1 we need this |
Hey everyone, I found a cause for this bug – lefthook assumes that I am going to add a |
Hey! Please, check out v1.4.11 of lefthook I have recently released. Add |
🔧 Summary
Lefthook
Lefthook version
1.4.3 41b1cf139772b322400bfcb7754b6cb1c220e6be
Steps to reproduce
Add a
pre-push
script that relies on STDIN provided bygit
. For context,git
passes the following information via STDIN topre-push
hooks (per official docs):You can simulate this via CLI by running:
$ echo 'refs/heads/main 3a236f32fd701ffda70dd22ea65e61d2670bc1a9 refs/heads/main 0000000000000000000000000000000000000000' | LEFTHOOK_VERBOSE=true lefthook run pre-push origin [email protected]:<my-org/my-repo>.git
And of course, substitute the SHAs and remote URL above with valid ones.
If your installed
pre-push
hook is reading STDIN for these values, the script will hang indefinitely becauselefthook
does not forward this to each hook.Expected results
pre-push
hooks should receive STDIN. Valid use cases are tools that scan for secrets being pushed in git history (e.g.,talisman
.Actual results
pre-push
hooks that rely on STDIN provided bygit
hang/fail.The text was updated successfully, but these errors were encountered: