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.

files in .gitignore directories are being deleted

See original GitHub issue

Description

lint-staged is deleting all .js files in directories mentioned in my .gitignore file!

Steps to reproduce

  • Setup clean project and installed and configured eslint
  • Used npx mrm lint-staged to setup lint-staged, as per docs
  • Ran npm run lint-staged. Everything is ok
  • Added node_modules/ to my .gitignore
  • Ran npm run lint-staged. All .js files in node_modules/ have been deleted!

Video of the bug in action: https://www.youtube.com/watch?v=AQPmeRm6ozU Repo I used: https://github.com/tctimmeh/lint-staged-deleting-files

Debug Logs

expand to view
$ ll keepthis/
total 0
-rw-rw-r-- 1 timmeh timmeh 0 Feb 14 11:06 dontdeleteme.js
$ 
$ cat .gitignore 
keepthis/

$ 
$ ./node_modules/.bin/lint-staged --debug
  lint-staged:bin Running `lint-staged@10.0.7` +0ms
  lint-staged:bin Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: undefined,
  debug: true,
  maxArgLength: 65536,
  quiet: false,
  relative: false,
  shell: false
} +1ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/tmp/esl-test/package.json`:
  lint-staged { '*.js': 'eslint --cache --fix' } +7ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '*.js': 'eslint --cache --fix'
}
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/tmp/esl-test` +0ms
  lint-staged:resolveGitRepo Deleting GIT_DIR from env with value `undefined` +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/tmp/esl-test` +10ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/tmp/esl-test/.git` +0ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only' ] +9ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'foo.js' ] +13ms
  lint-staged:chunkFiles Resolved an argument string length of 20 characters from 1 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 65536 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: '*.js',
  lint-staged:gen-tasks   commands: 'eslint --cache --fix',
  lint-staged:gen-tasks   fileList: [ '/tmp/esl-test/foo.js' ]
  lint-staged:gen-tasks } +1ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands 'eslint --cache --fix' +0ms
  lint-staged:task cmd: eslint +0ms
  lint-staged:task args: [ '--cache', '--fix' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
Preparing... [started]
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Backing up merge state... +1ms
  lint-staged:file Reading file `/tmp/esl-test/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/tmp/esl-test/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/tmp/esl-test/.git/MERGE_MSG` +0ms
  lint-staged:file File `/tmp/esl-test/.git/MERGE_HEAD` doesn't exist, ignoring... +1ms
  lint-staged:file File `/tmp/esl-test/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/tmp/esl-test/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +1ms
  lint-staged:git Running git command [ 'ls-files', '--deleted' ] +10ms
  lint-staged:git Running git command [
  'stash',
  'save',
  '--include-untracked',
  '--keep-index',
  'lint-staged automatic backup'
] +3ms
  lint-staged:git Restoring merge state... +498ms
  lint-staged:git Done restoring merge state! +0ms
  lint-staged:git Running git command [ 'ls-files', '--others', '--exclude-standard' ] +495ms
  lint-staged:file Unlinking file `/tmp/esl-test/keepthis/dontdeleteme.js` +502ms
  lint-staged:git Running git command [ 'stash', 'list' ] +5ms
  lint-staged:git Running git command [
  'diff',
  '--binary',
  '--unified=0',
  '--no-color',
  '--no-ext-diff',
  '--patch',
  '--output=/tmp/esl-test/.git/lint-staged_unstaged.patch',
  'stash@{0}',
  '-R'
] +28ms
  lint-staged:git Done backing up original state! +41ms
Preparing... [completed]
Running tasks... [started]
Running tasks for *.js [started]
eslint --cache --fix [started]
eslint --cache --fix [failed]
→ 
Running tasks for *.js [failed]
→ 
Running tasks... [failed]
Applying modifications... [started]
Applying modifications... [skipped]
→ Skipped because of errors from tasks.
Reverting to original state... [started]
  lint-staged:git Restoring original state... +8ms
  lint-staged:git Running git command [ 'stash', 'list' ] +16ms
  lint-staged:git Running git command [ 'reset', '--hard', 'HEAD' ] +23ms
  lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ] +4ms
  lint-staged:git Done restoring original state! +560ms
  lint-staged:git Restoring merge state... +0ms
  lint-staged:git Done restoring merge state! +0ms
Reverting to original state... [completed]
Cleaning up... [started]
  lint-staged:git Dropping backup stash... +0ms
  lint-staged:file Unlinking file `/tmp/esl-test/.git/lint-staged_unstaged.patch` +606ms
  lint-staged:git Running git command [ 'stash', 'list' ] +534ms
  lint-staged:git Running git command [ 'stash', 'drop', '--quiet', 'stash@{0}' ] +29ms
  lint-staged:git Done dropping backup stash! +68ms
Cleaning up... [completed]



✖ eslint found some errors. Please fix them and try committing again.
$ 
$ 
$ ll keepthis/
total 0
$ 

Environment

  • OS: Xubuntu 19.04
  • Node.js: v12.16.0
  • lint-staged: v10.0.7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
okonetcommented, Mar 30, 2020

🎉 This issue has been resolved in version 10.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
iirojcommented, Mar 18, 2020

@kalbert312 the linked PR #801 above should help, although git-ignored files shouldn’t ever be affected (unless the change to .gitignore hasn’t been committed yet). I haven’t dared merge it yet due to the situation with COVID-19…

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - How to remove files that are listed in the .gitignore but still ...
Use git clean -xdn to perform a dry run and see what will be removed. Then use git clean -xdf to execute it....
Read more >
How To Remove Committed Files From Git Version Control
Create a .gitignore file, if you haven't already · Edit . · Execute the following command: git rm --cached path/to/file . · Verify...
Read more >
Why Does Git Locally Delete My Empty Directory? - Super User
It is full of tracked files. On computer A, my program deletes all of the files in dir_foo/ , but leaves the directory...
Read more >
Steps to removing untracked files from working tree - W3docs
To delete only the ignored files and directories use the -X option, instead. That deletes all files and directories listed in the .gitignore...
Read more >
.gitignore File – How to Ignore Files and Folders in Git
The git rm command, along with the --cached option, deletes the file from the repository but does not delete the actual file. This...
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