legend80s/git-commit-msg-linter

The package is not working with husky v5

matheus-silva-gaivota opened this issue · 11 comments

I'm trying to use commit-msg-linter and Husky v5, if I have husky installed the commit-msg-linter doesn't work, but if I uninstall husky, everything works.

We will look into it.

I have the same problem. When I installed husky v5 commit-message-linter no longer works.

Same problem here

It is as expected because the commit-msg hook is executed after husky commit finished successfully.

  1. npm install git-commit-msg-linter --save-dev
  2. npm install husky@4 --save-dev

So It have the configuration in my package.json.

{
  "name": "husky-not-work-with-gcmsglinter",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 0"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "git-commit-msg-linter": "^3.0.2",
    "husky": "^4.3.8"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm test"
    }
  }
}

When npm test exit with 0, the commit-msg-linter will continue to do its work as expected:

➜  husky-not-work-with-gcmsglinter git:(master) ✗ gcam "install husky"
husky > pre-commit (node v12.8.1)

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

Error: no test specified

  ************* Invalid Git Commit Message **************
  commit message: install husky
  correct format: <type>[scope]: <subject>
  example: docs: update README to add developer tips

  type:
    feat     A new feature.
    fix      A bug fix.
    docs     Documentation only changes.
    style    Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc).
    refactor A code change that neither fixes a bug nor adds a feature.
    test     Adding missing tests or correcting existing ones.
    chore    Changes to the build process or auxiliary tools and libraries such as documentation generation.
    perf     A code change that improves performance.
    ci       Changes to your CI configuration files and scripts.
    build    Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm).
    temp     Temporary commit that won't be included in your CHANGELOG.

  scope:
    Optional, can be anything specifying the scope of the commit change.
    For example $location, $browser, $compile, $rootScope, ngHref, ngClick, ngView, etc.
    In App Development, scope can be a page, a module or a component.

  subject:
    Brief summary of the change in present tense. Not capitalized. No period at the end.

But when the test failed

-  "test": "echo \"Error: no test specified\" && exit 0"
+  "test": "echo \"Error: no test specified\" && exit 1"

the commit-msg-linter did not do its validation. It's reasonable.

➜  husky-not-work-with-gcmsglinter git:(master) ✗ gcam "install husky"
husky > pre-commit (node v12.8.1)

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

Error: no test specified
npm ERR! Test failed.  See above for more details.
husky > pre-commit hook failed (add --no-verify to bypass)

But you installed Husky v4 instead of v5.
v4 is really working as expected. The issue is only with husky v5.

OK I will try the V5 😃

As for husky@5, it will ignore the .git/hooks/commit-msg so we need add .husky/commit-msg manually

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

Then commit-msg-linter will work.

@legend80s

I'm trying to use your last solution, 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

I'm trying to use your last solution, 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(-)

complete solution at issue #8

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"

As for husky@5, it will ignore the .git/hooks/commit-msg so we need add .husky/commit-msg manually

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

Then commit-msg-linter will work.

This worked for me!