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

Husky 9 seems to setup .git/config hooksPath incorrectly for Windows #1345

Closed
RoystonS opened this issue Jan 25, 2024 · 0 comments · Fixed by #1346
Closed

Husky 9 seems to setup .git/config hooksPath incorrectly for Windows #1345

RoystonS opened this issue Jan 25, 2024 · 0 comments · Fixed by #1346

Comments

@RoystonS
Copy link

Context

  • Terminal is Windows Command Prompt, using Git for Windows
  • Using husky 9.0.2

When running husky install with v8, the .git/config file was correctly modified with:

hooksPath = .husky

When running husky with v9, the .git/config is being modified - on Windows - with:

hooksPath = .husky\\_

(Note the escaped backslash.)

The result is that none of the hooks actually run. It looks like this path should be .husky/_ instead, even on Windows, because Git, when processing these paths, uses Linux forward-slash separators.

Demo / repro

With a brand new repository, installing husky 9 and running husky init gives me a demonstration pre-commit hook containing npm test:

C:\Dev>mkdir huskyplay

C:\Dev>cd huskyplay

C:\Dev\huskyplay>git init
Initialized empty Git repository in C:/Dev/huskyplay/.git/

C:\Dev\huskyplay>npm init
This utility will walk you through creating a package.json file.
...<npm init output elided>...
C:\Dev\huskyplay>npm i -D husky

added 1 package, and audited 2 packages in 1s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

C:\Dev\huskyplay>npx husky init

C:\Dev\huskyplay>git add package.json
warning: in the working copy of 'package.json', LF will be replaced by CRLF the next time Git touches it

C:\Dev\huskyplay>git commit -m "A commit"
[master (root-commit) 1c74e28] A commit
 1 file changed, 15 insertions(+)
 create mode 100644 package.json

That should have failed, because husky init installs a demonstration pre-commit hook that calls npm test, and by default npm test fails because of the default value of "test": "echo \"Error: no test specified\" && exit 1",.

This shows that the hooks aren't running.

If I modify .git/config to read hooksPath = husky/_ instead of hooksPath = husky\\_, and then try again:


C:\Dev\huskyplay>git add package-lock.json
warning: in the working copy of 'package-lock.json', LF will be replaced by CRLF the next time Git touches it

C:\Dev\huskyplay>git commit -m "Another commit"

> huskyplay@1.0.0 test
> echo "Error: no test specified" && exit 1

"Error: no test specified"
husky - pre-commit script failed (code 1)

This time we see the expected hook fail.

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 a pull request may close this issue.

1 participant