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

The package is not working with husky v5 #8

Closed
vinicius91carvalho opened this issue Mar 14, 2021 · 4 comments
Closed

The package is not working with husky v5 #8

vinicius91carvalho opened this issue Mar 14, 2021 · 4 comments

Comments

@vinicius91carvalho
Copy link

The issue #7 was not resolved. I'm trying to use your last solution @legend80s, but I'm receiving the error below:

ℹ No staged files match any configured task.
(node:98010) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
at readFile (fs.js:326:10)
at internal/util.js:297:30
at new Promise ()
at readFile (internal/util.js:296:12)
at main (/Users/viniciuscarvalho/Projects/hub-api/.git/hooks/commit-msg:47:5)
at Object. (/Users/viniciuscarvalho/Projects/hub-api/.git/hooks/commit-msg:56:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
(Use node --trace-warnings ... to show where the warning was created)
(node:98010) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:98010) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[feat/signup 656afe6] asdfsdaf
1 file changed, 6 insertions(+), 6 deletions(-)

@legend80s
Copy link
Owner

1 Can you show the file content of .husky/commit-msg?
2 In the ./.git/hooks/commit-msg add the console log to find out what's in the argv


In my project

  1. cat .husky/commit-msg
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

.git/hooks/commit-msg $1

husky will pass the file path of your commit msg as $1.

2 gcam "test"

> husky-5-not-work-with-gcmsglinter@1.0.0 test /Users/liuchuanzong/workspace/playground/husky-5-not-work-with-gcmsglinter
> echo "Error: no test specified" && exit 0

Error: no test specified
process.argv: [
  '/Users/***/.nvm/versions/node/v12.8.1/bin/node',
  '/Users/***/workspace/playground/husky-5-not-work-with-gcmsglinter/.git/hooks/commit-msg',
  '.git/COMMIT_EDITMSG'
]

The key point here is '.git/COMMIT_EDITMSG' as git store it's commit msg content in this temp file and it is passed as $1 by husky V5.

@vinicius91carvalho
Copy link
Author

I found the error. When I run the command:

npx husky add .husky/commit-msg ".git/hooks/commit-msg \$1"

The file was generated with the content below:

Screen Shot 2021-03-16 at 12 14 45

It was created without the parameter $1. Add this, it solves the problem.

Thanks @legend80s for your help.

@4lessandrodev
Copy link

npx husky add .husky/commit-msg ".git/hooks/commit-msg \$1" the command create file without $1

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

.git/hooks/commit-msg $1

@jeanvcastro
Copy link

jeanvcastro commented Nov 1, 2022

As of the current date, if you add git-commit-msg-linter before adding husky, it will stop working. To fix it, just add it to the dependencies again and it will work fine.

Also, the command described earlier must be run.

npx husky add .husky/commit-msg ".git/hooks/commit-msg \$1"

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

No branches or pull requests

4 participants