Skip to content

fix(cli): add environment variable cli flag #343

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

Merged
merged 1 commit into from
Jun 2, 2018
Merged

fix(cli): add environment variable cli flag #343

merged 1 commit into from
Jun 2, 2018

Conversation

DJMcNab
Copy link
Contributor

@DJMcNab DJMcNab commented May 20, 2018

Description

Add an argument -E | --env to the cli which accepts the name of an environment variable to be used for the path to the commit message file.

This also fixes some minor typos in the docs.

I haven't removed the $GIT_PARAMS handling as that should be a breaking change. However, it could be removed in a later version.

Motivation and Context

Fixes #319.

In the newest/upcoming versions of Husky (1.0.0-rc.1), the environment variable husky uses is renamed to HUSKY_GIT_PARAMS from GIT_PARAMS.

This means that the cross platform support for husky built into the CLI doesn't work for this and subsequent releases.

This implements the second fix suggested in https://github.com/marionebl/commitlint/issues/319#issue-318569827.

The alternative to this would to add a patch to normaliseEdit which detects HUSKY_GIT_PARAMS. However, that would be a hack which doesn't address the issue, that there is no cross-platform way to use environment variables in a command.

Usage examples

echo "fix: fix something" > commit.txt
commitfile=commit.txt commitlint --env commitfile # Passes
// package.json
...
"husky": {
    "hooks":{"pre-commit":"commitlint --env HUSKY_GIT_PARAMS"}
}
...

How Has This Been Tested?

I have added two new tests, one covering a success and one covering a failure case.

Please note that I cannot get all of the tests to pass on my machine, specifically the husky integration tests. However, they pass on Travis.

I believe that this is because my windows username has a space in it, which breaks something due to the combination of husky, commitlint and the temporary directory, because I cannot reproduce this issue within my documents folder.

Note: the failure message for all of them is:

lerna ERR!   Error: Command failed: git commit -m "test: this should work"
lerna ERR!   husky > npm run -s commitmsg (node v8.9.4)
lerna ERR!
lerna ERR!   The filename, directory name, or volume label syntax is incorrect.
lerna ERR!
lerna ERR!   husky > commit-msg hook failed (add --no-verify to bypass)

Because of this I haven't ticked All new and existing tests passed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

EDIT: In first line, I put --edit. I meant --env.

fixes #319.

additionally fixes some minor typos in docs
@marionebl
Copy link
Contributor

Thank you, this PR is 👍 <3

@marionebl marionebl merged commit 458f24c into conventional-changelog:master Jun 2, 2018
@DJMcNab
Copy link
Contributor Author

DJMcNab commented Jun 2, 2018

Thanks! Obviously the custom handling of GIT_PARAMS can be removed upon the next major release (one major release with it deprecated is probably enough)

@typicode you might want to update the husky documentation to take this into account.

@DJMcNab DJMcNab deleted the enviroment-cli branch June 2, 2018 13:30
@jotatoledo
Copy link

Thanks for the clear explanation. Made debugging my local issue really quick and easy

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

Successfully merging this pull request may close these issues.

Error with Husky v1.0.0-rc.2 on Windows
3 participants