Skip to content

Improve Windows / GitHub Desktop support? #950

Closed

Description

@DoctorDerek

I either have to add C:/Program Files/Git/bin to PATH manually using Windows environment variables, or alternatively I had to install Git for Windows using something other than the recommended setting:
image

Recommended setting when installing Git for Windows:

  • "Git from the command line and also from 3rd-party software"

Necessary setting for husky / GitHub Desktop compatibility:

  • "Use Git and optional Unix tools from the command prompt."

Of course, the latter simply makes a similar PATH change automatically for me, specifically by adding the following to the PATH in my system variables:

C:\Program Files\Git\cmd
C:\Program Files\Git\mingw64\bin
C:\Program Files\Git\usr\bin

This is basically a known issue, in that GitHub Desktop doesn't package Git for Windows and thereby doesn't directly support running node via bash, just sh: #228 (comment)

Indeed, that particular bug report resulted in @typicode/husky using just sh internally, per desktop/desktop#3860 (comment)

That means that a pre-commit husky script that doesn't rely on node or npm will work without requiring bash in PATH for GitHub Desktop users on Windows:

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

notepad

image

However, the majority of husky hooks are going to be more along the lines of @okonet/lint-staged

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

npx lint-staged

It would seem more reasonable for husky to include a "Windows compatibility" section in the docs than to ask GitHub Desktop to bundle all of Git for Windows into their Electron app.

That section could read simply:

Husky Hooks and Windows Compatibility with GitHub Desktop

If you're using a third-party GUI like GitHub Desktop for managing Git commits in Windows, you may get an error that `bash` is a command not found.

This error commonly occurs when trying to run package manager based scripts, like the "npx lint-staged" command, as part of your husky pre-commit hooks.

To fix this error, you'll need to add the Git for Windows tools to your PATH by either:
1. Choosing "Use Git and optional Unix tools from the command prompt" in the Git for Windows installer, or
2. Adding "C:/Program Files/Git/bin" [or your appropriate installation location] to the PATH manually as an Environmental Variable in Windows.

Similar issues have been reported for the Node Version Manager program nvm on *nix systems, but those issues are addressed in the "command not found" section of the docs, which explains using a ~/.huskyrc file.

Activity

  1. DoctorDerek commented on Apr 16, 2021

    @DoctorDerek
    ContributorAuthor

    I'm going to close the issue because I can't quite reproduce the compatibility problems II was having to verify.

    I had been seeing command not found error 127 citing bash in GitHub Desktop when trying to run the npx lint-staged pre-commit hook, but I'm not seeing it now.

    It may have been associated with NVM for Windows, which doesn't support .nvrmc files; while trying to debug this issue I uninstalled that and installed latest node (15.14.0) and npm (7.10.0).

    Now I can run the husky pre-commit hooks using the "recommended settings" when installing Git for Windows (which do in fact include C:\Program Files\Git\bin as a user variable and C:\Program Files\Git\cmd as a system variable but neither C:\Program Files\Git\mingw64\bin nor C:\Program Files\Git\usr\bin as system variables).

    So there was definitely a transient PATH issue, probably leftover from the nvm installation.

    image

  2. DindoLeonard commented on Nov 11, 2021

    @DindoLeonard

    Thanks man! really helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions