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

Error running check-clang-format precommit ENOENT (Windows) #59

Open
alanwright opened this issue Dec 12, 2018 · 1 comment
Open

Error running check-clang-format precommit ENOENT (Windows) #59

alanwright opened this issue Dec 12, 2018 · 1 comment

Comments

@alanwright
Copy link

alanwright commented Dec 12, 2018

I'm setting up clang-format with precommit hook in a repository on a windows machine and getting the below error emitted from the check-clang-format script. The file it's complaining about does exist (I see it's written in python), but windows complains with ENOENT error. Am I missing anything in my setup or is there a bug?

package.json:

"scripts": {
    "precommit": "check-clang-format \"npm format\"",
    "format": "git-clang-format"
  },

cmd output (ran as admin):

> git commit -m "test"

Warning: Setting pre-commit script in package.json > scripts will be deprecated
Please move it to husky.hooks in package.json, a .huskyrc file, or a husky.config.js file
Or run ./node_modules/.bin/husky-upgrade for automatic update

See https://github.com/typicode/husky for usage

husky > pre-commit (node v8.11.1)
Error running git-clang-format: { Error: spawnSync node_modules\clang-format\bin\git-clang-format ENOENT
    at _errnoException (util.js:1022:11)
    at spawnSync (child_process.js:579:20)
    at main (node_modules\clang-format\bin\check-clang-format.js:63:18)
    at Object.<anonymous> (node_modules\clang-format\bin\check-clang-format.js:82:22)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawnSync node_modules\\clang-format\\bin\\git-clang-format',
  path: 'node_modules\\clang-format\\bin\\git-clang-format',
  spawnargs: [ '--diff' ] }
husky > pre-commit hook failed (add --no-verify to bypass

image

@alanwright alanwright changed the title Error running git-clang-format ENOENT (Windows) Error running check-clang-format precommit ENOENT (Windows) Dec 12, 2018
@shaka-b
Copy link

shaka-b commented Jan 11, 2019

I ran into the same issue on my windows machine.
The only workaround I found is to replace the spawn module (used in path-to-your-project/node_modules/clang-format/bin/check-clang-format.js) with cross-spawn:

#!/usr/bin/env node
/**
 * @fileoverview This script provides the glue to run git-clang-format as a pre-
 * commit hook.
 *
 * It checks that your git configuration is correct, and wraps the
 * git-clang-format program by simply exiting with non-zero exit code if any
 * changes are not already formatted correctly.
 *
 * To install it, see the instructions in the README.md.
 */

const spawn = require('cross-spawn').spawn.sync;`

See also #nodejs/node-v0.x-archive#2318

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

2 participants