Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win 10 Github Desktop pre-commit hook #1072

Closed
JosefBredereck opened this issue Nov 11, 2021 · 24 comments
Closed

Win 10 Github Desktop pre-commit hook #1072

JosefBredereck opened this issue Nov 11, 2021 · 24 comments

Comments

@JosefBredereck
Copy link

JosefBredereck commented Nov 11, 2021

Hello, I have a problem with my pre-commit hook or husky in general when using Github Desktop.
On the first look, it seems to be #1038, but the problem is. It works perfectly fine in VS code.

My environment:
Terminal or GUI client: GitHub Desktop v2.9.4 (x64)
System OS: Windows 10
Node Version: v15.14.0
npm Version: 7.7.6

I followed the following guide
https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v7

After that, I have now "husky": "^7.0.4" in place and get the following error message:

/usr/bin/env: ‘bash’: No such file or directory
husky - pre-commit hook exited with code 127 (error)

grafik

Do I have to configure something in the pre-commit file?

# file .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint-staged-hook
@JosefBredereck JosefBredereck changed the title Win 10 Github Desktop precommit hook Win 10 Github Desktop pre-commit hook Nov 11, 2021
@typicode
Copy link
Owner

typicode commented Nov 11, 2021

Hmm that's weird, nowhere husky is calling bash in husky.sh

@JosefBredereck
Copy link
Author

JosefBredereck commented Nov 12, 2021

It seems that I'm not the only one. Someone else also opened an issue for the desktop app desktop/desktop #13307 & desktop/desktop #12562

@stale
Copy link

stale bot commented Jan 11, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 11, 2022
@KInGATiLLa
Copy link

Same here 😞. I'm using from Github desktop. Vscode is fine. But i like github desktop

My environment

OS: Windows 11 latest
Node: 16.3.2
Npm: 8.3.0
Github desktop: 2.9.6 (x64)

@stale stale bot removed the wontfix label Jan 14, 2022
jamiegluk added a commit to jamiegluk/jamiegl that referenced this issue Jan 28, 2022
This reverts commit d0f3b6d.

- Experiencing issues with commits in GitHub desktop.
- Issues appear to have no non-hacky fix.
- So reverting changes.
- see typicode/husky#1072
- see desktop/desktop#12562
- see desktop/desktop#9351
@VincentVerweij
Copy link

It is not Github Desktop I am using here but Visual Studio 2022 which gives me the exact same error.

image

While Googling, I did come across issue #1038 and there are some suggestions in there.

Did try to change my .husky/commit-msg from

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit 

to

#!/bin/sh
# exit 1 will prevent commit to happen, so you can more easily debug things
echo "it's working" && exit 1 

And Visual Studio 2022 did give me the message it's working with an error symbol (which is normal).

Next I made sure that in my system PATH environment variable I do have C:\Program Files\Git\usr\bin\cygpath.exe included. I do see it when printing out $env:PATH in PowerShell.

Any other suggestions?

@typicode
Copy link
Owner

Hmm I'm not using Windows enough to help here. However I have GitHub Desktop 2.9.8 working. I also have Git installed with Git Bash on my machine.

I don't see what could be done on husky's side in terms of code.

@VincentVerweij
Copy link

I guess it is just Visual Studio which is acting weird here. Currently my workaround is to use Visual Studio Code to commit code which works just fine.
So perhaps it is wrong to post this Visual Studio issue in here, as Husky seems to be working ok.

Still if anyone else knows what is going on here, or has a suggestion of fixing or logging this elsewhere, give a shout.

@typicode
Copy link
Owner

Closing to clean up issues list, but if anyone has fix ideas feel free to add to this thread.

@johannesschobel
Copy link

This issue is still a thing and i can confirm this issue as described the latter.
@JosefBredereck , have you found a solution for this?

@JosefBredereck
Copy link
Author

Not for the issue, only a work around. If you go back to node 14 the issue should not appear.

@johannesschobel
Copy link

hmmmmmmmmmmmmmmmm~ i will try tomorrow (hopefully) and report back!
However, this is a serious issue / roadblock for the development with windows and husky 😟

@johannesschobel
Copy link

maybe @typicode has some more information about this issue in the meantime?! Would it help, if we provide a minimal reproduction repository?

@typicode
Copy link
Owner

typicode commented May 2, 2022

@johannesschobel no more info, sorry :/

@Fariarx
Copy link

Fariarx commented May 5, 2022

image

@johannesschobel
Copy link

@chall2chall4 is the code repository located within a wsl2 distro?

@typicode : would you be willing to help and track down the issue in order to solve this problem?

@marie-hughes
Copy link

marie-hughes commented May 17, 2022

Not for the issue, only a work around. If you go back to node 14 the issue should not appear.

I am using node 14 and I get the issue so I don't think that's a universal solution
Update: was able to get it working with node 14.18.0

@LukeGarrigan
Copy link

I get this running in Github Desktop:
image

It works fine from my current IDE (intellij)

@Fariarx
Copy link

Fariarx commented May 19, 2022

@Fariarx is the code repository located within a wsl2 distro?

No, this is just a deployed repository on my windows 11. Specifically taken from here: https://github.com/electron-react-boilerplate/electron-react-boilerplate
I solved it by changing github desktop to another client. (fork) And there were no more problems with it.

@Yiding-Aya
Copy link

Yiding-Aya commented Jun 2, 2022

Add git bin to Path fixed my issue
image

@DoctorDerek
Copy link
Contributor

DoctorDerek commented Sep 14, 2022

I added C:\Program Files\Git\bin as well long with both of these to my PATH:
C:\Users\derek\AppData\Local\Yarn\bin
C:\Users\derek\AppData\Roaming\npm

Then as a rule I write .husky scripts using yarn ... or npm run ...... that seems to work well for me.

@Secreto31126
Copy link

Leaving my two cents here, I solved the issue by adding .cmd to the npx call in .husky/pre-commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx.cmd lint-staged

Wild guess: I noticed I have both a "npx" and "npx.cmd" files in C:/Program Files/nodejs, and they are ordered alphabetically. IIRC, Windows pathing matchs the first file, which turns out to be the one without extension (probably a Linux binary from WSL). Again, wild guess, but maybe WSL is messing around in the issue.

@monstereat
Copy link

thank you boss

@celstark
Copy link

Leaving my two cents here, I solved the issue by adding .cmd to the npx call in .husky/pre-commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx.cmd lint-staged

OMG thank you!

Here's my variant:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if [[ "$OS" == "Windows_NT" ]]; then
  npx.cmd lint-staged
else
  npx lint-staged
fi  

@PittsGitHub
Copy link

PittsGitHub commented Dec 6, 2023

Leaving my two cents here, I solved the issue by adding .cmd to the npx call in .husky/pre-commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx.cmd lint-staged

OMG thank you!

Here's my variant:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

if [[ "$OS" == "Windows_NT" ]]; then
  npx.cmd lint-staged
else
  npx lint-staged
fi  

This fix so very nearly works for me but I'd been using regex as part of my command for prettier:
npx.cmd prettier --ignore-path .gitignore \"**/*.+(ts|json)\"

Which I can't seem to get to work inside husky for the life of me, so for now at least I've given up trying to make GitHub desktop work and just using the VSCode source control

webfiltered added a commit to Comfy-Org/ComfyUI_frontend that referenced this issue Oct 29, 2024
huchenlei pushed a commit to Comfy-Org/ComfyUI_frontend that referenced this issue Oct 29, 2024
* Fix husky pre-commit on some Windows clients

typicode/husky#1072 (comment)

* Limit commit type check to staged files

Adds tsc-files package (dev only) and its config

* Remove deprecated git add from lint-staged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests