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.

check for git lock

See original GitHub issue

Description

I keep getting erros like this more and more often. Running the command again fixes. Screen Shot 2020-04-14 at 4 15 35 PM

Screen Shot 2020-04-15 at 5 40 43 PM

I have a feeling this is happening because git is busy when I commit, which could be due to vscode using git.

Steps to reproduce

Should happen if you can start a lint-staged process at the same time git is busy doing something else.

Debug Logs

expand to view
./node_modules/.bin/lint-staged --debug
  lint-staged:bin Running `lint-staged@10.1.3` +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
} +1ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Users/vamac/Desktop/app/package.json`:
  lint-staged {
  lint-staged   '*.{js,jsx,ts,tsx}': [ 'yarn prettier --write' ],
  lint-staged   'package.json': [ 'yarn sort-package-json', 'yarn prettier --write' ]
  lint-staged } +26ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '*.{js,jsx,ts,tsx}': [
    'yarn prettier --write'
  ],
  'package.json': [
    'yarn sort-package-json',
    'yarn prettier --write'
  ]
}
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +2ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/vamac/Desktop/app` +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/vamac/Desktop/app` +9ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/vamac/Desktop/app/.git` +0ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +9ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [] +16ms
ℹ No staged files found.
  lint-staged tasks were executed successfully! +17ms

Debug Logs of Problem

expand to view
$ /Users/vamac/Desktop/app/node_modules/.bin/lint-staged --debug
  lint-staged:bin Running `lint-staged@10.1.6` +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
} +1ms
  lint-staged Loading config using `cosmiconfig` +0ms
  lint-staged Successfully loaded config from `/Users/vamac/Desktop/app/package.json`:
  lint-staged {
  lint-staged   '*.{js,jsx,ts,tsx}': [ 'yarn prettier --write' ],
  lint-staged   'package.json': [ 'yarn sort-package-json', 'yarn prettier --write' ]
  lint-staged } +10ms
  lint-staged:cfg Validating config +0ms
Running lint-staged with the following config:
{
  '*.{js,jsx,ts,tsx}': [
    'yarn prettier --write'
  ],
  'package.json': [
    'yarn sort-package-json',
    'yarn prettier --write'
  ]
}
  lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`) +1ms
  lint-staged:run Running all linter scripts +0ms
  lint-staged:resolveGitRepo Resolving git repo from `/Users/vamac/Desktop/app` +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/vamac/Desktop/app` +13ms
  lint-staged:resolveGitRepo Resolved git config directory to be `/Users/vamac/Desktop/app/.git` +0ms
  lint-staged:git Running git command [ 'log', '-1' ] +13ms
  lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ] +9ms
  lint-staged:run Loaded list of staged files in git:
  lint-staged:run [ 'src/screens/EditProfileScreen/EditProfileScreen.tsx' ] +32ms
  lint-staged:chunkFiles Resolved an argument string length of 78 characters from 1 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 {
  lint-staged:gen-tasks   pattern: '*.{js,jsx,ts,tsx}',
  lint-staged:gen-tasks   commands: [ 'yarn prettier --write' ],
  lint-staged:gen-tasks   fileList: [
  lint-staged:gen-tasks     '/Users/vamac/Desktop/app/src/screens/EditProfileScreen/EditProfileScreen.tsx'
  lint-staged:gen-tasks   ]
  lint-staged:gen-tasks } +2ms
  lint-staged:gen-tasks Generated task:
  lint-staged:gen-tasks {
  lint-staged:gen-tasks   pattern: 'package.json',
  lint-staged:gen-tasks   commands: [ 'yarn sort-package-json', 'yarn prettier --write' ],
  lint-staged:gen-tasks   fileList: []
  lint-staged:gen-tasks } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'yarn prettier --write' ] +0ms
  lint-staged:task cmd: yarn +0ms
  lint-staged:task args: [ 'prettier', '--write' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'yarn sort-package-json', 'yarn prettier --write' ] +1ms
  lint-staged:task cmd: yarn +0ms
  lint-staged:task args: [ 'sort-package-json' ] +0ms
  lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false } +0ms
  lint-staged:task cmd: yarn +0ms
  lint-staged:task args: [ 'prettier', '--write' ] +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 Getting partially staged files... +0ms
  lint-staged:git Running git command [ 'status', '--porcelain' ] +15ms
  lint-staged:git Found partially staged files: [] +17ms
  lint-staged:git Getting deleted files... +0ms
  lint-staged:git Running git command [ 'ls-files', '--deleted' ] +17ms
  lint-staged:git Found deleted files: [] +9ms
  lint-staged:git Backing up merge state... +0ms
  lint-staged:file Reading file `/Users/vamac/Desktop/app/.git/MERGE_HEAD` +0ms
  lint-staged:file Reading file `/Users/vamac/Desktop/app/.git/MERGE_MODE` +0ms
  lint-staged:file Reading file `/Users/vamac/Desktop/app/.git/MERGE_MSG` +0ms
  lint-staged:file File `/Users/vamac/Desktop/app/.git/MERGE_HEAD` doesn't exist, ignoring... +1ms
  lint-staged:file File `/Users/vamac/Desktop/app/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
  lint-staged:file File `/Users/vamac/Desktop/app/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
  lint-staged:git Done backing up merge state! +1ms
  lint-staged:git Running git command [ 'stash', 'save', 'lint-staged automatic backup' ] +10ms
  lint-staged:git Running git command [ 'stash', 'list' ] +44ms
  lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ] +16ms
Preparing... [failed]
→ fatal: Unable to create '/Users/vamac/Desktop/app/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: conflicts in index.Try without --index.
Running tasks... [started]
Running tasks... [skipped]
→ Skipped because of previous git error.
Applying modifications... [started]
Applying modifications... [skipped]
→ Skipped because of previous git error.
Cleaning up... [started]
Cleaning up... [skipped]
→ Skipped because of previous git error.

  ✖ lint-staged failed due to a git error.
  Any lost modifications can be restored from a git stash:

    > git stash list
    stash@{0}: On master: automatic lint-staged backup
    > git stash apply --index stash@{0}

fatal: Unable to create '/Users/vamac/Desktop/app/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
error: conflicts in index.Try without --index.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky > pre-commit hook failed (add --no-verify to bypass)

Environment

  • OS: mac os mojave
  • Node.js: 13.12.0
  • lint-staged: 10.1.3

this could be addressed by checking if $PWD/.git/index.lock exists and sleeping a bit to see if git finishes being used. I could be wrong tho so leaving issue issue to get some ideas/feedback

EDIT: added debug logs (sorry 🙏 ) and a new print-screen EDIT2: added debug logs of actual bug happening, been using the lib on debug mode for this

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
iirojcommented, Apr 21, 2020

@Thomazella it was just released, actually, in v10.1.7.

1reaction
iirojcommented, Apr 21, 2020

https://github.com/okonet/lint-staged/pull/850 could help here, since files no longer disappear from the disk and file watchers etc shouldn’t trigger.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding and Using Git's index.lock File | Pluralsight
The index.lock file prevents changes to your local repository from happening from outside of the currently running git process so as to ensure ......
Read more >
File Locking - GitLab Docs
On the top bar, select Main menu > Projects and find your project. On the left sidebar, select Repository > Locked Files. This...
Read more >
Git index.lock file - Azure Repos - Microsoft Learn
To check for long running Git operations, open Task Manager (CTRL+ALT+DELETE), sort by name, and look for git.exe or other Git related processes ......
Read more >
git index.lock File exists when I try to commit, but cannot delete ...
lock file, first verify that you don't have any Git processes running. To check for long-running Git operations, open Task Manager, sort by...
Read more >
Git - How to Solve `'git/index.lock': File exists` Error in ...
1)-Open terminal . 2)-Open project file location. 3)-Rum command - defaults write com.apple.finder AppleShowAllFiles YES. Now u can see hidden ...
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