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

Changed default hook script to avoid fail on Windows installations #1402

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Jxlle
Copy link

@Jxlle Jxlle commented Mar 6, 2024

Recently in Husky v9, an issue came up on Windows installations using Husky (in my case, wsl on Windows), where the default script used by the hooks fails on some Git GUI's (in my case it was GitKraken using a Windows installed Git executable) because the path variable used in the script has a slash in the other direction (\). This commit changes this base script to the following:

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

instead of:

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

This should work with both types of path separators.

For me, this change in script fixed all my issues but I'm not sure why this problem is even occurring. I saw that some of the hooks (such as pre-commit) DO use a slash in the other direction (/) within GitKraken. Using the hooks via the Git cli on my Windows machine does NOT give problems for the original script.

Note: Paths that contain both slashes might still have problems as the above script can delete two slashes instead of one (if they are different). To avoid this, an if statement can be added but I'm not sure if this is required due to not knowing how common this situation is.

@SoyDiego
Copy link

SoyDiego commented Apr 9, 2024

Recently in Husky v9, an issue came up on Windows installations using Husky (in my case, wsl on Windows), where the default script used by the hooks fails on some Git GUI's (in my case it was GitKraken using a Windows installed Git executable) because the path variable used in the script has a slash in the other direction (\). This commit changes this base script to the following:

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

instead of:

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

This should work with both types of path separators.

For me, this change in script fixed all my issues but I'm not sure why this problem is even occurring. I saw that some of the hooks (such as pre-commit) DO use a slash in the other direction (/) within GitKraken. Using the hooks via the Git cli on my Windows machine does NOT give problems for the original script.

Note: Paths that contain both slashes might still have problems as the above script can delete two slashes instead of one (if they are different). To avoid this, an if statement can be added but I'm not sure if this is required due to not knowing how common this situation is.

Hi, I was watching your PR and I don't know if I have the same problem.
My project is like the documentation:

image

  • I installed husky
  • I did npx husky init
  • Last command, edited my package.json and I replaced the line prepare for "prepare": "cd .. && husky 'My Project/.husky'"

When I do this, only is creating a file pre-commit but I cannot see the folder _

image

I'm doing manually npm run prepare and now I can see the folder _

image

Finally I'm trying to do a commit but always I have the same error:

image

What I'm doing wrong. I'm trying in Linux, Mac and Windows and always I have the same problem or sometimes I'm receiving the message .git not found.

Any help? @Jxlle @typicode

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants