question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Unable to get staged files" on Windows

See original GitHub issue

A team member on Windows is having trouble using lint-staged set up on project

On our project we have both eslint and prettier using lint-staged with a husky precommit hook, here is the configuration in our package.json:

  "lint-staged": {
    "**/*.{js,json}": [
      "eslint --fix",
      "prettier-eslint --write",
      "git add"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  }

We are using version 9.2.0 of lint-staged and 1.1.3 of husky.

Here are the outputs of multiple git commands for his project:

$ git status
On branch cleaner_test_fixes
Your branch is up to date with 'origin/cleaner_test_fixes'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
        modified:   readme.md
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   package.json
$ git diff --staged
diff --git a/readme.md b/readme.md
index 3443791..fd686f3 100755
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,4 @@
-# Spec Service
+# Spec Service blah
 ## Introduction
@@ -50,4 +50,4 @@ need bearer token
 * http://<url-removed>/repos/specservice/browse
 ## CI
-* http://<url-removed>/browse/CDKEX-SPEC
\ No newline at end of file
+* http://<url-removed>/browse/CDKEX-SPEC
$ git diff --staged --diff-filter=ACM --name-only
readme.md

The configuration works for the team members using MacOS as expected

Debug Logs

expand to view
$ git commit
husky > pre-commit (node v8.12.0)
2019-07-26T13:50:31.861Z lint-staged:bin Running `lint-staged@9.2.1`
2019-07-26T13:50:31.862Z lint-staged Loading config using `cosmiconfig`
2019-07-26T13:50:31.872Z lint-staged Successfully loaded config from `C:\src\fortellis\clean2\specservice\package.json`:
{ '**/*.{js,json}': [ 'eslint --fix', 'prettier-eslint --write', 'git add' ] }
2019-07-26T13:50:31.872Z lint-staged:cfg Validating config
Running lint-staged with the following config:
{
  '**/*.{js,json}': [
    'eslint --fix',
    'prettier-eslint --write',
    'git add'
  ]
}
2019-07-26T13:50:31.873Z lint-staged:run Running all linter scripts
2019-07-26T13:50:31.873Z lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ]
2019-07-26T13:50:31.973Z lint-staged:run Resolved git directory to be `\cygdrive\c\src\fortellis\clean2\specservice`
2019-07-26T13:50:31.973Z lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACM', '--name-only' ]
Unable to get staged files!
husky > pre-commit hook failed (add --no-verify to bypass)

Environment

  • OS: Windows 10 Enterprise w/ Cygwin
  • Node.js: 8.12.0
  • lint-staged: 9.2.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
iirojcommented, Aug 5, 2019

Here’s a new PR https://github.com/okonet/lint-staged/pull/678 that always converts paths to forward-slashes. Maybe it helps here.

1reaction
emily-currycommented, Jul 26, 2019

Having a similar issue. Debug output:

2019-07-26T16:46:27.898Z lint-staged:bin Running `lint-staged@9.2.1`
2019-07-26T16:46:27.906Z lint-staged:cfg Validating config
2019-07-26T16:46:27.908Z lint-staged:run Running all linter scripts
2019-07-26T16:46:27.908Z lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ]
2019-07-26T16:46:28.109Z lint-staged:run Resolved git directory to be `\c\Users\emily.curry\Code\use`
2019-07-26T16:46:28.109Z lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACM', '--name-only' ]
Unable to get staged files!

I’m in a msys2 environment, similar to cygwin (which @Jaredk3nt ) is using. It’s not the diff that’s failing really, it’s what resolveGitDir is returning as the git directory, which has incorrect path separators (they should be unix-style), which I’m guessing is caused by path.normalize. I see that it was included to fix tests here, but is it really necessary? Windows can handle using forward slashes as a path separator.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'lint-staged' is not recognized as an internal or external ...
When using cmd.exe or Visual Studio Code in Windows I get the error "'lint-staged' is not recognized as an internal or external command, ......
Read more >
Git Changes - unable stage additional files
When staging files for commit via the new Git Changes experience, I am unable to stage additional files after the first set. For...
Read more >
Adding file to git's stage does nothing and cannot be committed
I have run into this same situation where I add or modify few files and they start showing as both staged and unstaged....
Read more >
Unable to deselect files | Sourcetree for Windows
In the "Staged files" and "Unstaged files" lists you cannot deselect a file without selecting a different file. So if you have all...
Read more >
pre-commit
Before you can run hooks, you need to have the pre-commit package manager ... pre-commit run flake8 : run the flake8 hook against...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found