observing / pre-commit

Automatically installs a git pre-commit script in your git repository which runs your `npm test` on pre-commit
MIT License
1.88k stars 150 forks source link

pre-commit doesn't work when the current path contains a space #45

Closed fhemberger closed 9 years ago

fhemberger commented 9 years ago

I just installed pre-commit for a project which contains a space in the path name (e.g. /projects/example path). npm test itself runs fine, but when I try to commit, I get the following error:

$ git commit -m "package.json: add pre-commit"
module.js:338
    throw err;
          ^
Error: Cannot find module '/projects/example'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Function.Module.runMain (module.js:471:10)
    at startup (node.js:117:18)
    at node.js:948:3
3rd-Eden commented 9 years ago

Which version of pre-commit are you using?

fhemberger commented 9 years ago

Did a fresh npm install: v1.1.1

3rd-Eden commented 9 years ago

And what platform is this?

fhemberger commented 9 years ago

OS X v10.9.5 zsh v5.0.8 iojs v2.5.0

LaurenJanicki commented 9 years ago

I also had this issue.

pre-commit v1.1.1 OS X v10.10.3 OS X bash v3.2.57 node v0.12.7

$ git commit
module.js:338
    throw err;
          ^
Error: Cannot find module '/Users/lauren/code/my'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Where the full file path would be something like:

'/Users/lauren/code/my projects/folder/current-repo'

Changing "my projects" to "my-projects" made it possible to commit to the repo as expected again.

jltalens commented 9 years ago

@fhemberger @LaurenJanicki we had the same problem here, just some missing quotes. You can fix it quickly by going to your hooks directory (.git/hooks) and changing the line 49 in the pre-commit file from:

"$BINARY" $("$BINARY" -e "console.log(require.resolve('pre-commit'))")

to

"$BINARY" "$("$BINARY" -e "console.log(require.resolve('pre-commit'))")"

@3rd-Eden I can create a pull request if you want, I'll write some tests to cover that case.

fhemberger commented 9 years ago

Thanks. Would be great if this patch could land in the next release.

3rd-Eden commented 9 years ago

I thought it was already fixed.

fhemberger commented 9 years ago

@3rd-Eden Nope, both reports were for v1.1.1.

fhemberger commented 9 years ago

Closed through #52.

3rd-Eden commented 9 years ago

Released as 1.1.2

aloisdg commented 8 years ago

Same error here on Windows 10 with node v5.6.0 and zsh v5.0.6:

{ base16-builder } master » git commit -m "docs(contributing): Add missing links"
module.js:341
    throw err;
    ^

Error: Cannot find module 'C:\home\alois\source\base16-builder\.git\hooks\pre-commit'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:140:18)
    at node.js:1001:3
rofrol commented 6 years ago

Solution https://github.com/observing/pre-commit/issues/102#issuecomment-418514346

tmoodley commented 3 years ago

I added --no-verify to the end of the commit and it forced it to run. Not sure why that worked but it did.