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.

Lost work when bailing from lint-staged run in unstaged files

See original GitHub issue

Description

When bailing on lint-staged with ctrl c, new changes in previously staged files are lost.

Steps to reproduce

Change file A and file B and save both. Stage both files. Make another change to file B and save it, but don’t stage it. Run lint-staged see that new change in file B is stashed during the run. Hit ctrl c to stop lint-staged. Stashed changes in file B are not restored.

You can see this begin in release 10.2.0 up to the current release 10.2.7. Release 10.1.7 does not have this issue. (I tried different versions to trace where the issue began)

Debug Logs

... % yarn precommit
yarn run v1.22.4
$ lint-staged -p true --debug
  lint-staged:bin Running `lint-staged@10.2.7` +0ms
  lint-staged:bin Options parsed from command-line: { allowEmpty: false,
  concurrent: 'true',
  configPath: undefined,
  debug: true,
  maxArgLength: 131072,
  stash: true,
  quiet: false,
  relative: false,
  shell: false,
  verbose: false } +2ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Users/[redacted]t/package.json`:
  lint-staged { '**/*.{js,ts,tsx}':
  lint-staged    [ 'prettier --write',
  lint-staged      'tslint --project tsconfig.json',
  lint-staged      'eslint',
  lint-staged      'jest --findRelatedTests' ],
  lint-staged   '**/*.{css,scss}': [ 'prettier --write', 'stylint' ] } +20ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '**/*.{js,ts,tsx}': [
    'prettier --write',
    'tslint --project tsconfig.json',
    'eslint',
    'jest --findRelatedTests'
  ],
  '**/*.{css,scss}': [
    'prettier --write',
    'stylint'
  ]
}
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +3ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/[redacted]` +0ms
  lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`) +0ms
  lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ] +0ms
  lint-staged:resolveGitRepo Resolved git directory to be `/Users/[redacted]` +25ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/[redacted]/.git` +0ms
  lint-staged:git Running git command [ 'log', '-1' ] +25ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +22ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'client/package.json',
  lint-staged:run   '[filePath]/[fileName].tsx' ] +70ms
  lint-staged:chunkFiles Resolved an argument string length of 157 characters from 2 files +0ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +0ms
  lint-staged:gen-tasks Generating linter tasks +0ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks { pattern: '**/*.{js,ts,tsx}',
  lint-staged:gen-tasks   commands:
  lint-staged:gen-tasks    [ 'prettier --write',
  lint-staged:gen-tasks      'tslint --project tsconfig.json',
  lint-staged:gen-tasks      'eslint',
  lint-staged:gen-tasks      'jest --findRelatedTests' ],
  lint-staged:gen-tasks   fileList:
  lint-staged:gen-tasks    [ '/Users/[redacted]/package.json',
  lint-staged:gen-tasks      '/Users/[redacted]/[fileName].tsx' ] } +5ms
  lint-staged:gen-tasks Generated task: 
  lint-staged:gen-tasks { pattern: '**/*.{css,scss}',
  lint-staged:gen-tasks   commands: [ 'prettier --write', 'stylint' ],
  lint-staged:gen-tasks   fileList: [] } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write', 'tslint --project tsconfig.json', 'eslint', 'jest --findRelatedTests' ] +0ms
  lint-staged:task cmd: prettier +0ms
  lint-staged:task args: [ '--write' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: tslint +1ms
  lint-staged:task args: [ '--project', 'tsconfig.json' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: eslint +0ms
  lint-staged:task args: [] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: jest +0ms
  lint-staged:task args: [ '--findRelatedTests' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write', 'stylint' ] +2ms
  lint-staged:task cmd: prettier +0ms
  lint-staged:task args: [ '--write' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: stylint +0ms
  lint-staged:task args: [] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:chunkFiles Resolved an argument string length of 157 characters from 2 files +8ms
  lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072 +1ms
[STARTED] Preparing...
  lint-staged:git Backing up original state... +0ms
  lint-staged:git Getting partially staged files... +1ms
  lint-staged:git Running git command [ 'status', '-z' ] +37ms
  lint-staged:git Found partially staged files: [ 'client/package.json' ] +49ms
  lint-staged:git Running git command [ 'diff',
  '--binary',
  '--unified=0',
  '--no-color',
  '--no-ext-diff',
  '--src-prefix=a/',
  '--dst-prefix=b/',
  '--patch',
  '--output',
  '/Users/[redacted]/.git/lint-staged_unstaged.patch',
  '--',
  'client/package.json' ] +49ms
  lint-staged:git Backing up merge state... +27ms
  lint-staged:file Reading file `/Users/[redacted]/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/[redacted]/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/[redacted]/.git/MERGE_MSG` +0ms
  lint-staged:file File `/Users/[redacted]/.git/MERGE_HEAD` doesn't exist, ignoring... +1ms
  lint-staged:file File `/Users/[redacted]/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/[redacted]/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +1ms
  lint-staged:git Getting deleted files... +0ms
  lint-staged:git Running git command [ 'ls-files', '--deleted' ] +28ms
  lint-staged:git Found deleted files: [] +33ms
  lint-staged:git Running git command [ 'stash', 'create' ] +33ms
  lint-staged:git Running git command [ 'stash',
  'store',
  '--quiet',
  '--message',
  'lint-staged automatic backup',
  'aa65292fa298ac06a7174f17c43b5a9f924292b2' ] +52ms
  lint-staged:git Done backing up original state! +78ms
[SUCCESS] Preparing...
[STARTED] Hiding unstaged changes to partially staged files...
  lint-staged:git Running git command [ 'checkout', '--force', '--', 'client/package.json' ] +27ms
[SUCCESS] Hiding unstaged changes to partially staged files...
[STARTED] Running tasks...
[STARTED] Running tasks for **/*.{js,ts,tsx}
[STARTED] prettier --write
[SUCCESS] prettier --write
[STARTED] tslint --project tsconfig.json
^C

Environment

  • OS: MacOS Catalina
  • Node.js: 10.15.1
  • lint-staged: >=10.2.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
leandro-ortiz-encoracommented, Mar 9, 2022

I lost my work after a CTRL + C during the lint-staged process, but I found out (thanks God) that there is a lint-stage automatic backup in the git stash. Just needed to pop it from the stash.

1reaction
SarahFowler73commented, Jun 3, 2020

@iiroj Tested it out, and it’s working perfectly! Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lint-staged dont automatic unstage files on failed commit
I need to unstage the file manually then do the commit again and it works. Is there anything I missed or is my...
Read more >
Using lint-staged, husky, and pre-commit hooks to fail fast and ...
Let's look at using lint-staged and husky to fail earlier and faster. ... An array of commands is then run against those files....
Read more >
Fix Your Mistakes, Don't Commit Them! Pre-Commit Git Hook ...
Pre-Commit Git Hook Checks with Husky and Lint Staged. ... we can make it more efficient to focus our energy on the changed...
Read more >
Lint Staged With Husky for Pre-commit Validations - YouTube
Learn how to use lint staged with husky to implement linting and formatting your code with Prettier and Eslint on pre-commit.
Read more >
angular/angular - Gitter
Any clues? I'm currently running a reverse proxy (nginx) in addition to running the express server using pm2. I've based my implementation on...
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