Skip to content

$1 necessity with husky #3048

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

Closed
privatenumber opened this issue Feb 25, 2022 · 2 comments
Closed

$1 necessity with husky #3048

privatenumber opened this issue Feb 25, 2022 · 2 comments
Labels

Comments

@privatenumber
Copy link

privatenumber commented Feb 25, 2022

This is more of a question than a bug report, but can be actionable depending on discussion.

The README provides instructions on how to setup commitlint with husky. I'm curious if passing in $1 is actually necessary here:

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

Upon testing, $1 always seems to evaluate to .git/COMMIT_EDITMSG (which is also the default value for commitlint -e). Although I have read sources that say $1 evaluates to the commit message itself (rather than a file path containing it), I have not found that to be the case, which I confirmed with the Git hooks docs:

It takes a single parameter, the name of the file that holds the proposed commit log message.

Is there an edge case where $1 evaluates to a different path that this is trying to handle? Or can it be safely omitted?


Also, I don't think this recommended command will work in Bash because string interpolation isn't supported in single-quotes:

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

I'm wondering if this appears to work because it silently falls back to using .git/COMMIT_EDITMSG.

I made a test with the following commit hook to confirm:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "$1"
echo '$1'
echo $1

Result:

$ git commit -am test
.git/COMMIT_EDITMSG
$1
.git/COMMIT_EDITMSG

Is this for a specific non-Bash environment?

@escapedcat
Copy link
Member

Hey @privatenumber good question. I'm not able to answer this unfortunately.

$1 seems to been have introduced with #2340
Maybe @Manubi knows the exact reason for this?

@privatenumber
Copy link
Author

I found that it's safe to assume .git/COMMIT_EDITMSG as long as you're not changing the .git directory.

I investigated this behavior in the git source code here if anyone is interested:
typicode/husky#1108 (comment)

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

No branches or pull requests

2 participants