Skip to content

Error with Husky v1.0.0-rc.2 on Windows #319

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

Closed
1 of 4 tasks
typicode opened this issue Apr 27, 2018 · 4 comments · Fixed by #343
Closed
1 of 4 tasks

Error with Husky v1.0.0-rc.2 on Windows #319

typicode opened this issue Apr 27, 2018 · 4 comments · Fixed by #343
Labels

Comments

@typicode
Copy link
Contributor

Hi @marionebl,

In next version of husky, GIT_PARAMS env variable is going to be scoped (mainly to avoid collisions and be more explicit that it's coming from husky) but it creates a bug with commitlint.

https://github.com/typicode/husky/blob/dev/CHANGELOG.md#100-rc1
typicode/husky#268

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

I've checked commitlint code, and I see 2 potential solutions.

Use cross-env

cross-env comes with cross-env-shell which lets you write env variable the linux way with $ and it makes it compatible with Windows.

"commit-msg": "cross-env-shell "commitlint -e $HUSKY_GIT_PARAMS"

Add an option to commitlint CLI

It should be possible also to add, for example, a --env/-E option to commitlint-cli to define which environment variable it should look for in process.env without relying on OS specific syntax.

"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
"commit-msg": "commitlint --env HUSKY_GIT_PARAMS"

I personally like the second one as it doesn't involve downloading another package. Probably you have other ideas as well. Let me know what you think about it and if you want me to make a PR :)

Steps to Reproduce (for bugs)

  1. mkdir test && cd test
  2. git init && npm init -y
  3. npm install --save-dev @commitlint/{config-conventional,cli}
  4. npm install --save-dev husky@next (1.0.0-rc.2 )
  5. Add to package.json
"husky": {
  "hooks": {
    "commit-msg": "commitlint -e $GIT_PARAMS"
  }
}
  1. git add something and git commit -m foo
  2. On Windows it'll throw:
node_modules\@commitlint\cli\lib\cli.js:70
                throw err;
                ^

Error: Received $GIT_PARAMS as value for -e | --edit, but GIT_PARAMS is not available globally.

Your Environment

Executable Version
commitlint --version 6.1.3
git --version 2.7.4
node --version 9.11.1
OS Windows
@marionebl
Copy link
Contributor

Thanks for reporting! I'd like to go with you second option, but fuse it into the existing -e flag. We could add the following logic:

  • Check husky version
    • <1: use GIT_PARAMS if given, warn if HUSKY_GIT_PARAMS found
    • >=1: use HUSKY_GIT_PARAMS if given, warn if GIT_PARAMS found

For win32 handling we can do the same as with GIT_PARAMS before:

https://github.com/marionebl/commitlint/blob/b0bbce39393025d0e366fede8d08ef9eacd6e94a/%40commitlint/cli/src/cli.js#L168-L176

A PR for this would be very welcome ❤️!

What do you think?

@typicode
Copy link
Contributor Author

typicode commented May 7, 2018

I thought about fusing it with -e as well, but I wasn't sure how to distinguish between a file path (.git/COMMIT_EDITMSG) and an environment variable (HUSKY_GIT_PARAMS) in a reliable way?

Also, not sure how to display correct error message in case path or env variable is missing?

@NickyMeuleman
Copy link

Ran into same problem.
Changed the git hook part to "commit-msg": "commitlint -e %HUSKY_GIT_PARAMS%"

Is this correct for Windows?

marionebl pushed a commit that referenced this issue Jun 2, 2018
fixes #319.

additionally fixes some minor typos in docs
@jagannath7775
Copy link

how to write our own custom rule for git commit message?

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

Successfully merging a pull request may close this issue.

4 participants