evilmartians / lefthook

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

lefthook fails git command when run with GIT_TRACE=1 #730

Closed tdesveaux closed 2 months ago

tdesveaux commented 2 months ago

:wrench: Summary

When running a git command that invoke a hook handled by lefthook, the command will fail on the mkdir call here

This fails here, but all git calls should have the same issue.

Lefthook version

1.6.12 e87cc77f7d91893d701ae6dece10c65c32974555

Steps to reproduce

run GIT_TRACE=1 git push

Expected results

Lefthook should not break when GIT_TRACE=1 is set.

Actual results

Lefthook does not correctly handle Stderr on git commands.

Possible Solution

I believe the issue is that git rev-parse --git-path info called above captures Stderr in the same buffer that Stdout is expected.

Logs / Screenshots

GIT_TRACE=1 LEFTHOOK_VERBOSE=1 git push
...
│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: 13:45:15.686852 git.c:460               trace: built-in: git rev-parse --git-path info
.git/info                                                                                             

Error: mkdir 13:45:15.686852 git.c:460               trace: built-in: git rev-parse --git-path info
.git/info: no such file or directory                                                               
mrexox commented 2 months ago

Thank you for creating this issue. I am preparing a refactoring that will cover this case: stderr will be redirected to OS' stderr directly.