jesseduffield / jesseduffield/lazygit

Repeatedly hitting index.lock failures

Open
#5,906 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
82.4k
Forks
3k
Avg merge
2d 18h
Merged PRs (30d)
19

Description

### Describe the bug
I am operating in a very large repo, and frequently hit problems where I can't check out a branch without getting the below error:

Image

> fatal: Unable to create '/.git/index.lock': File exists.
> Another git process seems to be running in this repository, or the lock file may be stale.

### To Reproduce
I'm not sure how to reproduce directly, but for me it's as simple as switching branches will trigger it most of the time.

### Expected behavior
I'd expect to rarely/never hit this index.lock problem.

### Version info:

> commit=, build date=, build source=Homebrew, version=0.64.0, os=darwin, arch=arm64, git version=2.55.0

Was also occurring on last two releases as well. I wonder if this is related: https://github.com/jesseduffield/lazygit/pull/5788?

### Terminal info:
iTerm 2: version 3.6.11

### Additional context
I'm running Goland at the same time, but I'm not using their Git features explicitly. I don't see anything that suggests it's Goland trying to read the git index.

I've tried to check what commands are holding the lock. I see `git status --untracked-files=all --porcelain -z --find-renames=50%` comes up a bit, and the parent is lazygit.

I tried running this manually to see how long it takes and got:

> 0.35s user 2.37s system 79% cpu 3.441 total

On avg it was somewhere between 2-4 seconds for this repo.

I see the following logs:

Logs

Aug 7 18:50:47 |DEBU| RunCommand command="git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium refs/heads/master --"
Aug 7 18:50:47 |INFO| postRefreshUpdate for localBranches took 253.042µs
Aug 7 18:50:47 |ERRO| read |0: file already closed
Aug 7 18:50:48 |DEBU| RunCommand command="git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium refs/heads/my-new-branch --"
Aug 7 18:50:48 |ERRO| read |0: file already closed
Aug 7 18:50:48 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:48 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:48 |INFO| git checkout my-new-branch (wall 101.912041ms, cpu 35.673ms)
Aug 7 18:50:48 |WARN| lock error prevented command from running; retrying in 20ms
Aug 7 18:50:48 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:48 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:48 |INFO| git checkout my-new-branch (wall 108.728791ms, cpu 30.895ms)
Aug 7 18:50:48 |WARN| lock error prevented command from running; retrying in 40ms
Aug 7 18:50:48 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:48 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:48 |INFO| git checkout my-new-branch (wall 111.455459ms, cpu 33.685ms)
Aug 7 18:50:48 |WARN| lock error prevented command from running; retrying in 80ms
Aug 7 18:50:48 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:49 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:49 |INFO| git checkout my-new-branch (wall 102.784125ms, cpu 34.459ms)
Aug 7 18:50:49 |WARN| lock error prevented command from running; retrying in 160ms
Aug 7 18:50:49 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:49 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:49 |INFO| git checkout my-new-branch (wall 109.252791ms, cpu 32.028ms)
Aug 7 18:50:49 |WARN| lock error prevented command from running; retrying in 320ms
Aug 7 18:50:49 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:49 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:49 |INFO| git checkout my-new-branch (wall 106.687583ms, cpu 34.246ms)
Aug 7 18:50:49 |WARN| lock error prevented command from running; retrying in 640ms
Aug 7 18:50:50 |DEBU| RunCommand command="git checkout my-new-branch"
Aug 7 18:50:50 |ERRO| fatal: Unable to create '/MyDirectory/.git/index.lock': File exists.

Another git process seems to be running in this repository, or the lock file may be stale

Aug 7 18:50:50 |INFO| git checkout my-new-branch (wall 107.590709ms, cpu 35.349ms)
Aug 7 18:50:50 |INFO| refreshing all scopes (async)
Aug 7 18:50:50 |DEBU| RunCommand command="git for-each-ref \"--format=%(objectname) %(refname)\" refs/heads"
Aug 7 18:50:50 |INFO| git for-each-ref "--format=%(objectname) %(refname)" refs/heads (wall 33.102333ms, cpu 5.835ms)
Aug 7 18:50:50 |INFO| RefsSnapshot took 33.274375ms
Aug 7 18:50:50 |INFO| refreshed merge conflicts in 40.125µs


Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by tracing the command handling around the logged git status and git checkout operations, then reproduce branch switching in a large repository while observing index.lock contention. Done means the repeated checkout failures are explained and branch switching handles this situation reliably.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.