question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a commit-msg hook following the documentation does not work

See original GitHub issue

Hey 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:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TheKangaroocommented, Sep 28, 2022

Which shell/os are you testing this with? for me (zsh/MacOS) both

npx husky add .husky/commit-msg  'npx --no -- commitlint --edit "${1}"'

and

npx husky add .husky/commit-msg  'npx --no -- commitlint --edit ${1}'

work fine. The single qoutes prevent my shell from expanding the ${1} at the husky add runtime as expected.

1reaction
TheKangaroocommented, Oct 24, 2022

Perfect, I still think this needs to be fixed to single quotes in the docs. I can fix this in another PR. WDYT @escapedcat ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found