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

Issue with path resolution on Windows #1397

Open
piozygmunt opened this issue Feb 23, 2024 · 10 comments
Open

Issue with path resolution on Windows #1397

piozygmunt opened this issue Feb 23, 2024 · 10 comments

Comments

@piozygmunt
Copy link

Hi. After upgrading to version 9 from 8 hooks on windows stopped working. Based on some quick debugging it seems that path to the actual script is not being resolved correctly. To confirm this i echo'ed script path in h file:

#!/usr/bin/env sh
echo $0
set -x
h="${0##*/}"
s="${0%/*/*}/$h"

[ ! -f "$s" ] && exit 0
...

which gives me this output:

.husky\_/pre-commit
++ h=pre-commit
++ s='.husky\_/pre-commit/pre-commit'
++ '[' '!' -f '.husky\_/pre-commit/pre-commit' ']'
++ exit 0

Notice that path contains both forward and back slashes and because of that s="${0%/*/*}/$h" returns incorrect path.
Could it be something with my setup or the regexp needs to be updated ?

OS: Microsoft Windows [Version 10.0.19045.4046]

@Jxlle
Copy link

Jxlle commented Feb 26, 2024

+1

I have a similar problem. I use GitKraken which uses WSL to execute its git commands, but I selected the Windows installed Git executable. The following script inside all of the default hook files

#!/usr/bin/env sh
. "${0%/*}/h"

works on my Windows terminal but not through GitKraken because it uses the Windows path separator \ in the file path variable 0. For example, the path in the script variable will be .husky\_\post-checkout, and instead of it being modified to .husky\_\h, it will be .husky\_\post-checkout/h and fail.

@QuantumQuin
Copy link

+1 for gitkraken issue

@DVersavel
Copy link

  • 1
    Is there any news on this issue?

@sergei-lobanov
Copy link

sergei-lobanov commented Mar 6, 2024

I have issue like this, when I did upgrade from v8 to v9

According to migration guide paths to husky.sh should be removed

v8:

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

cd desktop && yarn test

v9:
cd desktop && yarn test

But if remove the path, it works on MAC/Unix, but on Windows I can't commit anymore

error: cannot spawn desktop/.husky/pre-commit: No such file or directory

@Jxlle
Copy link

Jxlle commented Mar 6, 2024

I have created a PR that fixes the issue on my end: #1402

@typicode
Copy link
Owner

typicode commented Mar 7, 2024

Thanks for the report.

@hyperupcall do you have any thoughts on this?

I find this behavior surprising as I'm not aware of other Git GUI tools on Windows having this issue?

@siddheshranade
Copy link

siddheshranade commented Mar 7, 2024

But if remove path, it works on MAC/Unix, but on windows I can't commit anymore
error: cannot spawn desktop/.husky/pre-commit: No such file or directory

I'm facing the exact same issue as @sergei-lobanov mentioned above. I'm using Windows 10.

When I restore these two script lines:

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

It works again perfectly as it did, even after keeping the change of "prepare": "husky" from "prepare": "husky install".

Should I update to v9 with these scripts restored? Please advise.

cc @typicode

@DVersavel
Copy link

Any news on this issues?

@DanielRose
Copy link

I have the same problem. It is not working in SourceTree and not in VS Code. When adding the lines back, it works.

@pabloimrik17
Copy link

Same here on Windows 10 with Webstorm

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

9 participants