Adding a commit-msg hook following the documentation does not work
See original GitHub issueHey maintainers 👋 . If follow the instructions in the “Getting started” document to add a commit-msg hook using husky
npx husky add .husky/commit-msg "npx --no -- commitlint --edit ${1}"
The result in .husky/commit-msg
will be
npx --no -- commitlint --edit
I think the reason is that the $
sign is mistaken for a variable in shell script. Even if I manually type the command, linting will always complain
✖ Please add rules to your `commitlint.config.js`
- Getting started guide: https://commitlint.js.org/#/?id=getting-started
- Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js [empty-rules]
✖ found 1 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
Possible Solution
The workaround I’m using is to have a command in package.json
"commitlint": "npx --no -- commitlint --edit ${1}"
and call it in commit-msg
npm run commitlint
Your Environment
Executable | Version |
---|---|
commitlint --version |
17.1.2 |
git --version |
2.37.0 |
node --version |
14.20.0 |
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
commit-msg Hook - gerrit-review
A Git hook automatically invoked by git commit , and most other commit creation tools such as git citool or git gui ....
Read more >Git Hooks - Git SCM
The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created. It lets you...
Read more >(Docs) Local setup does not work · Issue #3371 - GitHub
I have just installed commitlint on OS X 12.6 and following the local setup, when I get to the "test the hook" part...
Read more >Git Hooks | Atlassian Git Tutorial
Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository. Learn what they do and how...
Read more >git - pre-commit/hook: No such file or directory - Stack Overflow
You have a pre-commit hook defined (in .git/hooks/pre-commit ) and it is trying to reference ./node_modules/pre-commit/hook which doesn't ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Which shell/os are you testing this with? for me (zsh/MacOS) both
and
work fine. The single qoutes prevent my shell from expanding the ${1} at the
husky add
runtime as expected.Perfect, I still think this needs to be fixed to single quotes in the docs. I can fix this in another PR. WDYT @escapedcat ?