husky: Does not work with Github Desktop on Windows

Troubleshoot

If you’re migrating from husky 4, see: https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v7

Context Please describe your issue and provide some context:

I’ve this pre-commit hook:

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

npm test

It works with git command line and Tortoise Git on Windows as expected, but on Github Desktop 3.0.2 I’ve this error message when I commit:

An address incompatible with the requested protocol was used.

husky - pre-commit hook exited with code 1 (error)

A hook file like this works:

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

echo hello

But anything with npm does not.

Please kindly check it out.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Steps to reproduce:

In an empty folder:

  1. git init
  2. Save this file as package.json
{
    "scripts": {
        "prepare": "husky install",
        "test": "echo hello"
    },
    "devDependencies":{
        "husky": "^8.0.1"
    }
}
  1. npm install
  2. npx husky add .husky/pre-commit "npm test"
  3. Open the folder in Github Desktop and try to commit it image

Adding “C:\Program Files\Git\bin” to my PATH environment variable fixed this error at one point, as I described on Stackoverflow. Maybe try that?

Adding “C:\Program Files\Git\bin” to my PATH environment variable fixed this error at one point, as I described on Stackoverflow. Maybe try that?

A combination of this and this https://github.com/desktop/desktop/issues/12586#issuecomment-1223600474 works for me

I used windows with nvm.

I tied to change .husky\pre-commit to

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

npm.cmd test

It works as expected.

However I can’t change the script like this because it won’t work for Mac or Linux users.

I think it would be a bug of Github Desktop, I’ll fire bug report later