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_GIT_PARAMS not complete at Windows/cygwin #735

Closed
amjmhs opened this issue Jun 9, 2020 · 2 comments
Closed

HUSKY_GIT_PARAMS not complete at Windows/cygwin #735

amjmhs opened this issue Jun 9, 2020 · 2 comments

Comments

@amjmhs
Copy link

amjmhs commented Jun 9, 2020

HUSKY_GIT_PARAMS are not correctly provided to a node-process for prepare-commit-message.

OS: Windows 10
Shell: cygwin
Node: 12.16.1
Husky: 4.2.5

"prepare-commit-msg": "node bin/prepare-commit-msg/git-commit-template.js"

bin/prepare-commit-msg/git-commit-template.js
---------------------------------------------

#!/usr/bin/env node

console.dir(process.env.HUSKY_GIT_PARAMS);

Output:

$ git commit
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG'

$ git commit               (with existing commit.template-setting)
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG'

$ git commit -m "foobar"
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG'

$ git commit --amend
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG'

Expected Output:

$ git commit
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG'

$ git commit               (with existing commit.template-setting)
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG template'

$ git commit -m "foobar"
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG message'

$ git commit --amend
husky > prepare-commit-msg (node v12.16.1)
'.git/COMMIT_EDITMSG commit HEAD'

Am I doing something wrong here?

I think the root-cause is at the .git/hooks/husky.sh - Line 17
"$@" husky-run $hookName "$gitParams"
should be
"$@" husky-run $hookName \"$gitParams\"

@kirkoman
Copy link

I'm having an issue I think is related. In a windows + git bash + npm + husky + lfs environment I was constantly getting "this should be run through git's post-checkout hook" even when I was running lfs through the hook:

C:\my-repo>git checkout develop
Switched to branch 'develop'
Your branch is behind 'origin/develop' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)
husky:debug husky v4.2.5 - post-checkout
husky:debug Current working directory is /c/my-repo
husky > post-checkout (node v12.13.1)
running lfs hook post-checkout
This should be run through Git's post-checkout hook.  Run `git lfs update` to install it.
husky > post-checkout hook failed (cannot be bypassed with --no-verify due to Git specs)
husky:debug npx --no-install husky-run exited with 1 exit code

C:\my-repo>

It completely broke git rebase, causing it to abort mid-rebase in a detached-HEAD state.

I found this was due to not all the HUSKY_GIT_PARAMS were being passed to the hook. Probably the interpretation of quotes is happening different in cygwin or something? I could not do a direct comparison with behavior on a different platform to narrow down the difference, but I must assume this is working correctly on unix platforms.

Rather than adding slash-quoting to the husky.sh (which may break other platforms) I think the correct fix is to stop trying to pass them all in one string. PR to follow.

@typicode
Copy link
Owner

typicode commented Jan 7, 2021

Closing as it was fixed by @kirkoman and new version has been published :)

@typicode typicode closed this as completed Jan 7, 2021
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

3 participants