Git pre-commit hook fails to run because of "No such file or directory"
See original GitHub issueDescribe the bug
I have a .git/hooks/pre-commit
which is exactly the following:
#!/bin/sh
npm test
When I commit via GitHub Desktop, it fails:
/bin/bash: C:/Program Files/nodejs/npm: No such file or directory
It works when committing via git CLI.
Version & OS
Open ‘About GitHub Desktop’ menu to see the Desktop version. Also include what operating system you are using.
Steps to reproduce the behavior
- Create a hook as
.git/hooks/pre-commit
- Commit something
- See error
Expected behavior
It should run the npm command
Actual behavior
It says no such file
Screenshots
Logs
2021-07-09T14:34:12.623Z - info: [ui] [Timing] Action 'create commit' for 'saschanaz/types-web' took 0.292s
2021-07-09T14:35:53.954Z - info: [ui] Executing createCommit: git commit -F - (took 1.372s)
2021-07-09T14:35:53.963Z - error: [ui] `git commit -F -` exited with an unexpected code: 1.
stderr:
/bin/bash: C:/Program Files/nodejs/npm: No such file or directory
Additional context
This had been working but is regressed since a few months ago.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12 (8 by maintainers)
Top Results From Across the Web
git - pre-commit/hook: No such file or directory - Stack Overflow
Go to .git/hooks directory and remove pre-commit file, as its trying to reference to node_modules/pre-commit/hook . It should resolve it.
Read more >Git Push Fails - remote: hooks/pre-receive: line 9: C:\Program
The issue is caused by the presence of a space in the command path. This usually means that there is a space in...
Read more >pre-commit
Git hook scripts are useful for identifying simple issues before submission ... (optional) if true , this hook will run even if there...
Read more >Husky - Git hooks
Hooks not running · Ensure that you don't have a typo in your filename. For example, precommit or pre-commit.sh are invalid names. ·...
Read more >githooks Documentation - Git
If it exits with non-zero status, then the working tree will not be committed ... The default pre-applypatch hook, when enabled, runs the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It works for me. It looks like Github Desktop used the wrong bash command which was provided by wsl.
Symlinks was an idea. I tried changing
npm
tonpm.cmd
(supposing you are on Windows) and got it working finally. Don’t know why but it works. But the problem is that pre-commit hook will not be cross-platform anymore Does it work for you too?