conventional-changelog / commitlint

📓 Lint commit messages

Home Page:https://commitlint.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix: creating husky hook with echo fails

Felipellira opened this issue · comments

Expected Behavior

run
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
to create a git hook

Current Behavior

when i run this
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
it creates the file but when husky tries to run it i get the error

.husky/commit-msg: .husky/commit-msg: cannot execute binary file
husky - commit-msg script failed (code 126)

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

just create the file manually

Steps to Reproduce

1. Install commitlint locally npm install --save-dev @commitlint/config-conventional @commitlint/cli
2. Add configuration file echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js 
3. Install Husky npm install --save-dev husky
4. Initialize Husky npx husky init
5. Create hook echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
6. Try commit something

Context

No response

commitlint --version

@commitlint/cli@18.6.0

git --version

git version 2.43.0.windows.1

node --version

v20.11.0

This
echo "module.exports = { extends: ['@commitlint/config-conventional'] };"
create a problematic file too

Might be this husky error?: typicode/husky#1372

My computer is Windows 11, and I found that the files created using 'echo' have the UTF-16 LE encoding. After changing the file encoding to UTF-8, I was able to execute them successfully. I believe the issue was related to the file encoding.
image

image

Maybe a warning could be added to the docs?

The best way is to create file directly using editor interface.