Skip to content
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

(Docs) Local setup does not work #3371

Closed
4 tasks
TheKangaroo opened this issue Sep 9, 2022 · 8 comments
Closed
4 tasks

(Docs) Local setup does not work #3371

TheKangaroo opened this issue Sep 9, 2022 · 8 comments

Comments

@TheKangaroo
Copy link
Contributor

I followed the steps described in local setup
https://commitlint.js.org/#/guides-local-setup?id=add-hook
https://github.com/conventional-changelog/commitlint#add-hook

but when I do a commit, it just failes with

.husky/commit-msg: line 3: $(dirname $0)/_/husky.sh: No such file or directory

Expected Behavior

Hook is executed successfully

Current Behavior

The hook cannot be executed

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

I made it work with a shorter command:

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

which could replace the following steps from the docs:

Docs
echo '
#!/bin/sh
. "\$(dirname "\$0")/_/husky.sh"

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

Make hook executable

chmod a+x .husky/commit-msg

I'll happily provide a PR to change this in the docs.
If there is any reason to create this hook by hand it think it need to be changed to

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit

to work correctly. (this is the file npx husky add ... creates for me)

@TheKangaroo
Copy link
Contributor Author

fixed in #3372

@thatryan
Copy link

Hey all,

I have just installed commitlint on OS X 12.6 and following the local setup, when I get to the "test the hook" part I am not getting the husky fail from the hook, just normal git response of "nothing to commit".

When I run the first test npx commitlint --from HEAD~1 --to HEAD --verbose I do get a result so it works, but the hook part appears to not work?

I have installed the hook via npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}' yes, Any idea where I can look? Thank you much.

first-test

All good on first test

CleanShot 2022-10-27 at 08 11 29@2x

Hook test shows nothing

@TheKangaroo
Copy link
Contributor Author

@thatryan it seems like you don't have any changes to commit in your second screenshot and therefore git won't even try to create a commit.

@thatryan
Copy link

@TheKangaroo Wow that was dumb of me, I misunderstood the doc sorry. I thought just running the commit would trigger the lint test I did not get that I had to actually have something committable lol.

Regardless, I staged some files and tried again..

CleanShot 2022-10-27 at 08 30 05@2x

@TheKangaroo
Copy link
Contributor Author

no worries.
Now I think you need to install npx globally, as your output is "npx: command not found".
Did you install it with

npm install -g npx

?
I have npx installed globally:

> which npx
/opt/homebrew/bin/npx

and your husky searched in /opt/homebrew/bin so this should work.

@thatryan
Copy link

Thank you, apologies for adding here when this issue was my fault. Freaking node wasn't running so npx couldn't be found when I ran the command. All fixed, thank you much.

@TheKangaroo
Copy link
Contributor Author

No problem at all, I'm glad that I could help :)

@escapedcat
Copy link
Member

@TheKangaroo thanks for helping out here! ❤️

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

No branches or pull requests

3 participants