Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't lock git repo when checking status #2648

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

idbrii
Copy link
Contributor

@idbrii idbrii commented Jul 19, 2023

Fix "fatal: Unable to create '.git/index.lock': File exists." when doing fugitive commands.

Since upgrading fugitive from tpope/vim-fugitive@7c1f2ed to 5f0d280, I occasionally hit this lock error when using ZZ to save and close the fugitive rebase window.

I have no other windows or tabs open (nothing that might be invoking git). I get the error around 1 in 5 attempts on a larger git repo and less often on small repos (like vim-fugitive's repo).

However, I have airline and have the git branch name and dirty status in my statusline. A minimal repro of just sensible, fugitive, and vim-airline with no custom airline configuration produces the issue. If I use :AirlineToggle to turn off the statusline, it seems to go away.

Airline uses fugitive to get the branch name (with FugitiveHead()) and strip the fugitive:// name from buffers (with FugitiveReal()).

I tried removing ShellCmdPost fugitiveline.vim and that seems to fix it, but I don't understand why.

What makes more sense is that the dirty check is asynchronous and is trying to check status when fugitive is trying to rebase. Because the repo is large, it takes longer to get status (true for just running git status too).

I have async enabled:
:echo g:airline#init#vim_async
1

tpope suggests using --no-optional-locks to solve: tpope/vim-fugitive#1624

That also appears to fix the issue.

This flag was introduced to git in 2017 which would make airline fail on older gits:
git/git@27344d6 There's also GIT_OPTIONAL_LOCKS=0 environment variable, but that requires more infra work. Not sure if airline already supports 6 year old git?

Fix "fatal: Unable to create '.git/index.lock': File exists." when doing
fugitive commands.

Since upgrading fugitive from fugitive@7c1f2ed to 5f0d280, I
occasionally hit this lock error when using `ZZ` to save and close the
fugitive rebase window.

I have no other windows or tabs open (nothing that might be invoking
git). I get the error around 1 in 5 attempts on a larger git repo and
less often on small repos (like vim-fugitive's repo).

However, I have airline and have the git branch name and dirty status in
my **statusline**. A minimal repro of just sensible, fugitive, and
vim-airline with no custom airline configuration produces the issue. If
I use `:AirlineToggle` to turn off the statusline, it seems to go away.

Airline uses fugitive to get the branch name (with `FugitiveHead()`) and
strip the `fugitive://` name from buffers (with `FugitiveReal()`).

I tried removing ShellCmdPost fugitiveline.vim and that *seems* to fix
it, but I don't understand why.

What makes more sense is that the dirty check is asynchronous and is
trying to check status when fugitive is trying to rebase. Because the
repo is large, it takes longer to get status (true for just running `git
status` too).

I have async enabled:
    :echo g:airline#init#vim_async
    1

tpope suggests using --no-optional-locks to solve:
tpope/vim-fugitive#1624

That also appears to fix the issue.

This flag was introduced to git in 2017 which would make airline fail on
older gits:
git/git@27344d6
There's also GIT_OPTIONAL_LOCKS=0 environment variable, but that
requires more infra work.
@chrisbra
Copy link
Member

Makes sense. I would think a 6 year old git requirement should be okay. But who knows what ancient versions are people use. After all I sometimes still have to use an ancient vim 7.4 on some CentOS boxes..

So thanks, looks good to me!

@chrisbra chrisbra merged commit e6bb842 into vim-airline:master Jul 19, 2023
@idbrii idbrii deleted the git-nolock branch July 19, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants