Lint-staged: Bug when run with husky from atom git gui

Created on 8 Feb 2019  路  9Comments  路  Source: okonet/lint-staged

Description

When I commit from the cli everything works fine, but when I commit from atom i get this error:

Steps to reproduce

  1. use atom
  2. setup to use lint-staged with husky
  3. try to commit from Atom git gui

Debug Logs

STDERR: 17:22:04.472031 git.c:418
trace: built-in: git rev-parse --verify HEAD
husky > pre-commit hook failed (add --no-verify to bypass)
Command failed: /bin/sh -c lint-staged

after digging around and adding logs I ended up in the staged-git-files code and I found that when it's calling node's child_process.spawn the PATH is not correctly set.

    var cmd = spawn(bits[0], args, {
        cwd: module.exports.cwd
    });

if I add:

    var cmd = spawn(bits[0], args, {
        cwd: module.exports.cwd,
        env: {
          PATH: process.env.PATH
        }
    });

everything start working again

Environment

  • OS: Ubuntu 18.0.4
  • Node.js: 10.15.1
  • lint-staged: 8.1.3

Most helpful comment

I solved my problem by using npx lint-staged instead of int-staged proposed by @zorzysty in https://github.com/okonet/lint-staged/issues/420#issuecomment-558121775 :

    "hooks": {
-     "pre-commit": "lint-staged"
+     "pre-commit": "npx lint-staged"
    }

All 9 comments

I鈥檓 not sure where the issue is exactly but it doesn鈥檛 look like it鈥檚 in this package. Could you investigate and submit a PR to the appropriate package please?

I know the issue might not be directly with lint-staged but since its a complex bug that relates to the context of invocation as well as the a package it depends on I figured it would be good to notify of the issue before doing more investigation.

Feel free to close if you want.

I think it鈥檚 good you reported it here. Just wanted to make sure we are on the same page.

I have the same bug.

If I remove the following pre-commit hook, Atom succeeds to commit:

"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
    }
}

Otherwise, I get this error:

16:00:38.977583 git.c:418               trace: built-in: git commit --cleanup=verbatim -m sdf
16:00:39.004382 run-command.c:643       trace: run_command: GIT_EDITOR=: GIT_INDEX_FILE=.git/index .git/hooks/pre-commit
husky > pre-commit (node v9.11.2)
STDERR: 16:00:39.904813 git.c:418               trace: built-in: git rev-parse --verify HEAD
husky > pre-commit hook failed (add --no-verify to bypass)

I narrowed down the problem as you can see in this issue I created: https://github.com/mcwhittemore/staged-git-files/issues/18

@xuopled I fixed my problem for now:

  1. go to your packages in atom
  2. search for the github core package
  3. click on settings
  4. uncheck the Git Diagnostics checkbox

I'm unable to commit from Atom editor (Windows):

husky > pre-commit (node v10.16.0)
/c/Users/Nelson Martell/Documents/GitHub/xxxxx/node_modules/.bin/lint-staged: line 5: cygpath: command not found
internal/modules/cjs/loader.js:638
    throw err;
    ^
Error: Cannot find module 'C:\lint-staged\bin\lint-staged.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
husky > pre-commit hook failed (add --no-verify to bypass)

But in console it works fine.

I solved my problem by using npx lint-staged instead of int-staged proposed by @zorzysty in https://github.com/okonet/lint-staged/issues/420#issuecomment-558121775 :

    "hooks": {
-     "pre-commit": "lint-staged"
+     "pre-commit": "npx lint-staged"
    }

Glad you got it solved. I don't this is directly an issue with lint-staged, so I'll close the issue.

Was this page helpful?
0 / 5 - 0 ratings