typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
32.35k stars 1.02k forks source link

Husky - pre-commit hook exited with code 127 (error) #1478

Open gwendal-sogeti opened 1 month ago

gwendal-sogeti commented 1 month ago

Describe the bug

WHen I try to commit either from the terminal, intellij IDE, Intellij IDE terminal or even Github Desktop, I get an error and the commit fail.

Version & OS

I am using Windows 11 and my husky version is 8.0.3

Steps to reproduce the behavior

Run git commit from the terminal or Intellij IDEA

Expected behavior

The commit is pushed.

Actual behavior

The commit isn't pushed and it gives an error.

Screenshots

image

Logs

11:17:18.544: [GoldenEye_back_java] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false reset -- package-lock.json
11:17:18.861: [GoldenEye_back_java] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- src/main/java/com/sogeti/goldeneye/controller/ProjectController.java src/main/java/com/sogeti/goldeneye/repository/ProjectRepository.java src/main/java/com/sogeti/goldeneye/service/ProjectService.java src/main/java/com/sogeti/goldeneye/service/impl/ProjectServiceImpl.java
11:17:19.155: [GoldenEye_back_java] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false commit -F C:\Users\gwbreton\AppData\Local\Temp\git-commit-msg-.txt --
.husky/pre-commit: line 4: make: command not found
husky - pre-commit hook exited with code 127 (error)
husky - command not found in PATH=/mingw64/libexec/git-core:/mingw64/bin:/usr/bin:/c/Users/gwbreton/bin:/c/Program Files/Eclipse Adoptium/jdk-21.0.3.9-hotspot/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Program Files/dotnet:/c/Program Files/nodejs:/c/Users/gwbreton/OneDrive - Capgemini/Documents/apache-maven-3.9.8-bin/apache-maven-3.9.8:/c/Users/gwbreton/scoop/shims:/c/Users/gwbreton/AppData/Local/Microsoft/WindowsApps:/c/Users/gwbreton/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/gwbreton/.dotnet/tools:/c/Users/gwbreton/AppData/Local/GitHubDesktop/bin:/c/Program Files/JetBrains/IntelliJ IDEA 2024.1.4/bin
11:17:20.719: [GoldenEye_back_java] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false add --ignore-errors -A -f -- package-lock.json
typicode commented 1 month ago

Not really an issue with husky. It's due to make not being found in PATH.

If you run the content of pre-push manually in your terminal and it works, try displaying PATH and compare it with the one from husky - command not found in PATH=. It may help you find which directory is missing.

You can also start VSCode from the terminal so that it inherits the PATH with the directory containing make.

uniabis commented 1 month ago

Husky 9.1.2 cannot handle PATH with spaces. https://github.com/typicode/husky/blob/35fba846c4a9b83f64a95d8a0bde5aa648fdc449/husky#L16

export PATH="node_modules/.bin:$PATH"
gwendal-sogeti commented 1 month ago

I tried running pre-push in Intellij IDEA and it gave me an error related to /bin/sh :

 C:\Users\gwbreton\OneDrive - Capgemini\Documents\GoldenEye_back_java\.husky> /bin/sh "C:/Users/gwbreton/OneDrive - Capgemini/Documents/GoldenEye_back_java/.husky/pre-push"
/bin/sh : Le terme «/bin/sh» n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou programme exécutable. Vérifiez        
l'orthographe du nom, ou si un chemin d'accès existe, vérifiez que le chemin d'accès est correct et réessayez.
Au caractère Ligne:1 : 1
+ /bin/sh "C:/Users/gwbreton/OneDrive - Capgemini/Documents/GoldenEye_b ...
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (/bin/sh:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

It's written in French but it says that "/bin/sh" is not recognized as a command, function, script file or executable.

Also. Here is the result of my path variable

PS C:\Users\gwbreton\OneDrive - Capgemini\Documents\GoldenEye_back_java\.husky> echo $Env:PATH
C:\Program Files\Eclipse Adoptium\jdk-21.0.3.9-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerS
hell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\nodejs\;C:\Users\gwbreton\OneDrive - Capg
emini\Documents\apache-maven-3.9.8-bin\apache-maven-3.9.8;C:\Program Files\Git\usr\bin\cygpath.exe;C:\Users\gwbreton\scoop\shims;C:\Users\gwbreton\A
ppData\Local\Microsoft\WindowsApps;C:\Users\gwbreton\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\gwbreton\.dotnet\tools;C:\Users\gwbreton\
AppData\Local\GitHubDesktop\bin;C:\Program Files\JetBrains\IntelliJ IDEA 2024.1.4\bin;;C:\Program Files\Git\usr\bin\cygpath.exe;;C:\Users\gwbreton\OneDrive - Capgemini\Documents\GoldenEye_back_java\node_modules\.bin
Fdawgs commented 1 month ago

Also hitting the exact same issue with 9.1.2 when using WSL.

OS: Windows 11 using Ubuntu 22.04.4 via WSL Node: 20.16.0 Husky: 9.1.2

typicode commented 1 month ago

v9.1.3+ should better handle space in path if that's the issue

Fdawgs commented 1 month ago

Brilliant, thanks @typicode!

typicode commented 1 month ago

thanks to @uniabis for pointing it out