question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Git pre-commit hook fails to run because of "No such file or directory"

See original GitHub issue

Describe 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

  1. Create a hook as .git/hooks/pre-commit
  2. Commit something
  3. See error

Expected behavior

It should run the npm command

Actual behavior

It says no such file

Screenshots

image

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
Wangyaqicommented, Aug 23, 2022

Insert git bin to PATH and put it before “%SystemRoot%\system32”.

It works for me. It looks like Github Desktop used the wrong bash command which was provided by wsl.

6reactions
ruggi99commented, Aug 4, 2021

Symlinks was an idea. I tried changing npm to npm.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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found