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

[Bug] Husky hook erroring out #100

Closed
jklmli opened this issue Jul 5, 2017 · 7 comments
Closed

[Bug] Husky hook erroring out #100

jklmli opened this issue Jul 5, 2017 · 7 comments

Comments

@jklmli
Copy link

jklmli commented Jul 5, 2017

My package.json configuration looks like this:

{
  "scripts": {
    "commitmsg": "commitplease",
  },
  "commitplease": {
    "nohook": true,
    "style": "angular",
    "types": ["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
  },
}

When I commit something with this setup, I get this error:

$ git commit --amend
husky > npm run -s commitmsg (node v6.10.2)

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.normalize (path.js:1177:5)
    at module.exports (/Users/kevin/Code/monapt/node_modules/commitplease/index.js:98:12)
    at Object.<anonymous> (/Users/kevin/Code/monapt/node_modules/commitplease/commitplease.js:3:24)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)

husky > commit-msg hook failed (add --no-verify to bypass)

Is this an issue with the documentation or a bug in the code?
My current workaround is to set:

  "scripts": {
    "commitmsg": "commitplease .git/COMMIT_EDITMSG",
  }

which is working fine.

@alisianoi
Copy link
Collaborator

alisianoi commented Jul 5, 2017

As you probably already know, commitplease uses argv[0] to decide if it is going to fetch .git/COMMIT_EDITMSG and check it (working as a hook) or if it is going to use a git manipulation library to fetch the whole .git and check (possibly all of the) commits (working as a script).

Recently (see jquery/jquery#3708) it looks like either node or git have stopped supplying .git/COMMIT_EDITMSG as argv[0] to commitplease, hence the undefined for path. What you are doing in your workaround is this:

  1. You say you use husky, so it will trigger the commitmsg section of package.json
  2. That section used to run commitplease in the "working as a script" mode, which broke
  3. By supplying argv[0] you are now tricking it to run in the "hook mode", which works.

Sorry, I have not yet found the time to figure this one out, if you could that would be great!

@jklmli
Copy link
Author

jklmli commented Jul 6, 2017

Thanks for the detailed explanation, that makes sense.

What do you think about updating the documentation in the meantime to include .git/COMMIT_EDITMSG in the commitmsg hook?

@jzaefferer
Copy link
Owner

@all3fox I guess #98 will fix this?

@alisianoi
Copy link
Collaborator

No, I doubt it, that issue is for the jQuery install problem: jquery/jquery#3708

@Aqours
Copy link

Aqours commented Oct 27, 2017

I found .git/COMMIT_EDITMSG always show old message which I used, but not the new message I input when using git commit.

Is there a (temp) solution to resolve this issue?

I reinstall husky and commitplease packages, and it works fine.

@alisianoi
Copy link
Collaborator

alisianoi commented Oct 27, 2017

@jzaefferer I traced this problem back to husky, take a look at this line. Husky uses this script to "build" all of their hooks on the fly at install time. The line I am linking to is used in the following fashion: scan package.json for predefined entries into scripts and run that entry when the hook is triggered.

There are no arguments passed anywhere, just the scripts entry is run. So, what @jiaweihli is doing (explicitly supplying .git/COMMIT_EDITMSG) is indeed the only way to work with husky.

I have dug out my issue to husky where I am complaining that I cannot pass --silent as parameter to npm. The crux of the matter is the same though: husky runs exactly the line from scripts, all the parameters go to the script and cannot be propagated up to npm (in that case).

So, imo we do need to explicitly document this case better, I'll take a look at our README now. Once I document it, I will close this issue.

@alisianoi
Copy link
Collaborator

Ok, since it was a one-sentence change, I took the liberty of pushing everything to master. Once again, thanks to @jiaweihli and sorry for not getting to this sooner. Feel free to reopen if needed.

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