lint-staged: refs/stash@0 is not a valid reference
Description
$ npm exec lint-staged √ Preparing lint-staged… √ Running tasks for staged files… √ Applying modifications from tasks… × error: refs/stash@0 is not a valid reference
× lint-staged failed due to a git error. Any lost modifications can be restored from a git stash:
> git stash list stash@{0}: automatic lint-staged backup > git stash apply --index stash@{0}
Running lint-staged@123.7
under MSYS2 in Windows 10 but otherwise nothing fancy.
Debug Logs
expand to view
2022-03-18T17:05:51.935Z lint-staged:bin Running `lint-staged@12.3.7`
2022-03-18T17:05:51.935Z lint-staged:bin Options parsed from command-line: {
allowEmpty: false,
concurrent: true,
configPath: undefined,
cwd: undefined,
debug: true,
maxArgLength: 4095.5,
quiet: false,
relative: false,
shell: false,
stash: true,
verbose: false
}
2022-03-18T17:05:51.937Z lint-staged:validateOptions Validating options...
2022-03-18T17:05:51.937Z lint-staged:validateOptions Validated options!
2022-03-18T17:05:51.937Z lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`)
2022-03-18T17:05:51.937Z lint-staged:runAll Running all linter scripts...
2022-03-18T17:05:51.937Z lint-staged:runAll Using working directory `C:\path\to\repo`
2022-03-18T17:05:51.938Z lint-staged:resolveGitRepo Resolving git repo from `C:\path\to\repo`
2022-03-18T17:05:51.938Z lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`)
2022-03-18T17:05:51.938Z lint-staged:resolveGitRepo Unset GIT_WORK_TREE (was `undefined`)
2022-03-18T17:05:51.938Z lint-staged:execGit Running git command [ 'rev-parse', '--show-prefix' ]
2022-03-18T17:05:52.086Z lint-staged:resolveGitRepo Resolved git directory to be `C:/path/to/repo`
2022-03-18T17:05:52.086Z lint-staged:resolveGitRepo Resolved git config directory to be `C:/path/to/repo/.git`
2022-03-18T17:05:52.086Z lint-staged:execGit Running git command [ 'log', '-1' ]
2022-03-18T17:05:52.248Z lint-staged:execGit Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ]
2022-03-18T17:05:52.393Z lint-staged:runAll Loaded list of staged files in git:
[
'C:/path/to/repo/package-lock.json',
'C:/path/to/repo/package.json'
]
2022-03-18T17:05:52.393Z lint-staged:getConfigGroups Grouping configuration files...
2022-03-18T17:05:52.393Z lint-staged:getConfigGroups Grouping staged files by their directories...
2022-03-18T17:05:52.393Z lint-staged:getConfigGroups Grouped staged files into 1 directories:
2022-03-18T17:05:52.395Z lint-staged:getConfigGroups {
'C:\\path\\to\\repo': [ 'C:/path/to/repo/package-lock.json', 'C:/path/to/repo/package.json' ]
}
2022-03-18T17:05:52.395Z lint-staged:getConfigGroups Searching config files...
2022-03-18T17:05:52.395Z lint-staged:loadConfig Searching for configuration from `C:\path\to\repo`...
2022-03-18T17:05:52.396Z lint-staged:loadConfig Successfully loaded config from `C:\path\to\repo\package.json`:
{ '*.{js,json,md,ts}': 'prettier --write' }
2022-03-18T17:05:52.396Z lint-staged:getConfigGroups Found new config "C:\path\to\repo\package.json" from "C:\path\to\repo"!
2022-03-18T17:05:52.396Z lint-staged:validateConfig Validating config from `C:\path\to\repo\package.json`...
2022-03-18T17:05:52.397Z lint-staged:validateConfig Validated config from `C:\path\to\repo\package.json`:
2022-03-18T17:05:52.397Z lint-staged:validateConfig {
'*.{js,json,md,ts}': 'prettier --write'
}
2022-03-18T17:05:52.397Z lint-staged:loadConfig Searching for configuration from `C:\path\to\repo`...
2022-03-18T17:05:52.398Z lint-staged:loadConfig Successfully loaded config from `C:\path\to\repo\package.json`:
{ '*.{js,json,md,ts}': 'prettier --write' }
2022-03-18T17:05:52.398Z lint-staged:getConfigGroups Found existing config "C:\path\to\repo\package.json" from "C:\path\to\repo"!
2022-03-18T17:05:52.398Z lint-staged:getConfigGroups Grouped staged files into 1 groups!
2022-03-18T17:05:52.398Z lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name' ]
2022-03-18T17:05:52.535Z lint-staged:execGit Running git command [ 'ls-files', '-z', '--full-name', '--others', '--exclude-standard' ]
2022-03-18T17:05:52.680Z lint-staged:loadConfig Loading configuration from `C:/path/to/repo/package.json`...
2022-03-18T17:05:52.682Z lint-staged:loadConfig Successfully loaded config from `C:\path\to\repo\package.json`:
{ '*.{js,json,md,ts}': 'prettier --write' }
2022-03-18T17:05:52.682Z lint-staged:validateConfig Validating config from `C:\path\to\repo\package.json`...
2022-03-18T17:05:52.682Z lint-staged:validateConfig Validated config from `C:\path\to\repo\package.json`:
2022-03-18T17:05:52.682Z lint-staged:validateConfig {
'*.{js,json,md,ts}': 'prettier --write'
}
2022-03-18T17:05:52.682Z lint-staged:runAll Found 1 configs:
{
'C:\\path\\to\\repo\\package.json': { '*.{js,json,md,ts}': 'prettier --write' }
}
2022-03-18T17:05:52.683Z lint-staged:chunkFiles Resolved an argument string length of 90 characters from 2 files
2022-03-18T17:05:52.683Z lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 4095.5
2022-03-18T17:05:52.683Z lint-staged:generateTasks Generating linter tasks
2022-03-18T17:05:52.686Z lint-staged:generateTasks Generated task:
{
pattern: '*.{js,json,md,ts}',
commands: 'prettier --write',
fileList: [
'C:/path/to/repo/package-lock.json',
'C:/path/to/repo/package.json'
]
}
2022-03-18T17:05:52.686Z lint-staged:makeCmdTasks Creating listr tasks for commands 'prettier --write'
2022-03-18T17:05:52.688Z lint-staged:resolveTaskFn cmd: prettier
2022-03-18T17:05:52.688Z lint-staged:resolveTaskFn args: [ '--write' ]
2022-03-18T17:05:52.688Z lint-staged:resolveTaskFn execaOptions: {
cwd: 'C:\\path\\to\\repo',
preferLocal: true,
reject: false,
shell: false
}
2022-03-18T17:05:52.688Z lint-staged:chunkFiles Resolved an argument string length of 90 characters from 2 files
2022-03-18T17:05:52.689Z lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 4095.5
[STARTED] Preparing lint-staged...
2022-03-18T17:05:52.691Z lint-staged:GitWorkflow Backing up original state...
2022-03-18T17:05:52.692Z lint-staged:GitWorkflow Getting partially staged files...
2022-03-18T17:05:52.692Z lint-staged:execGit Running git command [ 'status', '-z' ]
2022-03-18T17:05:52.847Z lint-staged:GitWorkflow Found partially staged files: [ 'package.json' ]
2022-03-18T17:05:52.847Z lint-staged:execGit Running git command [
'diff',
'--binary',
'--unified=0',
'--no-color',
'--no-ext-diff',
'--src-prefix=a/',
'--dst-prefix=b/',
'--patch',
'--submodule=short',
'--output',
'C:\\path\\to\\repo\\.git\\lint-staged_unstaged.patch',
'--',
'package.json'
]
2022-03-18T17:05:52.993Z lint-staged:GitWorkflow Backing up merge state...
2022-03-18T17:05:52.993Z lint-staged:file Reading file `C:\path\to\repo\.git\MERGE_HEAD`
2022-03-18T17:05:52.993Z lint-staged:file Reading file `C:\path\to\repo\.git\MERGE_MODE`
2022-03-18T17:05:52.993Z lint-staged:file Reading file `C:\path\to\repo\.git\MERGE_MSG`
2022-03-18T17:05:52.993Z lint-staged:file File `C:\path\to\repo\.git\MERGE_HEAD` doesn't exist, ignoring...
2022-03-18T17:05:52.993Z lint-staged:file File `C:\path\to\repo\.git\MERGE_MODE` doesn't exist, ignoring...
2022-03-18T17:05:52.994Z lint-staged:file File `C:\path\to\repo\.git\MERGE_MSG` doesn't exist, ignoring...
2022-03-18T17:05:52.994Z lint-staged:GitWorkflow Done backing up merge state!
2022-03-18T17:05:52.994Z lint-staged:GitWorkflow Getting deleted files...
2022-03-18T17:05:52.994Z lint-staged:execGit Running git command [ 'ls-files', '--deleted' ]
2022-03-18T17:05:53.130Z lint-staged:GitWorkflow Found deleted files: []
2022-03-18T17:05:53.131Z lint-staged:execGit Running git command [ 'stash', 'create' ]
2022-03-18T17:05:53.410Z lint-staged:execGit Running git command [
'stash',
'store',
'--quiet',
'--message',
'lint-staged automatic backup',
'9203a6ce04636a2f320ae4c9529d69dd777632fc'
]
2022-03-18T17:05:53.553Z lint-staged:GitWorkflow Done backing up original state!
[SUCCESS] Preparing lint-staged...
[STARTED] Hiding unstaged changes to partially staged files...
2022-03-18T17:05:53.554Z lint-staged:execGit Running git command [ 'checkout', '--force', '--', 'package.json' ]
[SUCCESS] Hiding unstaged changes to partially staged files...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 2 files
[STARTED] *.{js,json,md,ts} — 2 files
[STARTED] prettier --write
[SUCCESS] prettier --write
[SUCCESS] *.{js,json,md,ts} — 2 files
[SUCCESS] package.json — 2 files
[SUCCESS] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
2022-03-18T17:05:54.131Z lint-staged:GitWorkflow Adding task modifications to index...
2022-03-18T17:05:54.131Z lint-staged:execGit Running git command [
'add',
'--',
'C:/path/to/repo/package-lock.json',
'C:/path/to/repo/package.json'
]
2022-03-18T17:05:54.288Z lint-staged:GitWorkflow Done adding task modifications to index!
2022-03-18T17:05:54.288Z lint-staged:execGit Running git command [ 'diff', '--name-only', '--cached' ]
[SUCCESS] Applying modifications from tasks...
[STARTED] Restoring unstaged changes to partially staged files...
2022-03-18T17:05:54.436Z lint-staged:GitWorkflow Restoring unstaged changes...
2022-03-18T17:05:54.436Z lint-staged:execGit Running git command [
'apply',
'-v',
'--whitespace=nowarn',
'--recount',
'--unidiff-zero',
'C:\\path\\to\\repo\\.git\\lint-staged_unstaged.patch'
]
[SUCCESS] Restoring unstaged changes to partially staged files...
[STARTED] Cleaning up temporary files...
2022-03-18T17:05:54.586Z lint-staged:GitWorkflow Dropping backup stash...
2022-03-18T17:05:54.586Z lint-staged:execGit Running git command [ 'stash', 'list' ]
2022-03-18T17:05:54.831Z lint-staged:execGit Running git command [ 'stash', 'drop', '--quiet', 'refs/stash@{0}' ]
[FAILED] error: refs/stash@0 is not a valid reference
× lint-staged failed due to a git error.
Any lost modifications can be restored from a git stash:
> git stash list
stash@{0}: automatic lint-staged backup
> git stash apply --index stash@{0}
Environment
- OS: Windows 10, MSYS2
- Node.js: 14.17.5
- Git: 2.35.1
lint-staged
: 12.3.7
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (5 by maintainers)
Commits related to this issue
- fix: escape curly braces fixes #1121 — committed to ext/lint-staged by ext 2 years ago
Took me a while to get some time to investigate further, still not sure what the issue is but it seems like
git
itself is at fault somehow.I use code similar to
execGit.js
and gradually removed/changed things until only the bare minimal was left. Running the above script produces the output:Running
git show refs/stash@{0}
on CLI works as expected.Similarly using
bash -c
works as expected.The issue doesn’t appear to be within
lint-staged
at all but I’m still at a loss for what to do. I’d gladly help any way I can, should I file this as a bug toexeca
instead?