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

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.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 15 (8 by maintainers)

Most upvoted comments

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.

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?

Solved my problem! Finally