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

"error: could not delete references" due to non-existent lock file #5378

Open
roelandschoukens opened this issue Jan 22, 2025 · 3 comments
Open

Comments

@roelandschoukens
Copy link

roelandschoukens commented Jan 22, 2025

Git is unable to remove a stale remote reference. (this is a branch that was deleted on the remote GIT repository).

$ git fetch
error: could not delete references: cannot lock ref 'refs/remotes/origin/wip/some/branch': Unable to create 'C:/path/to/clone/.git/refs/remotes/origin/wip/some/branch.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.

(branch name and paths shortened, but the paths involved are well within normal path length limits on Windows)

However this lock file does not exist.

Tracing git.exe in procmon shows that the process is creating the file, then noticing its existence, and then removing the file.

time               | name    | PID   | Operation             | Path                                                           | Result         | Detail
-------------------|---------|-------|-----------------------|----------------------------------------------------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9:43:01.4249506 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Created
9:43:01.4250374 am | git.exe | 23220 | QuerySecurityFile     | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        | Information: 0x20
9:43:01.4251863 am | git.exe | 23220 | CloseFile             | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        |
9:43:01.4256310 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.4676144 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.4832797 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.4983944 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.5296357 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.5601606 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.6066284 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | NAME COLLISION | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0
9:43:01.6067965 am | git.exe | 23220 | CreateFile            | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        | Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
9:43:01.6068177 am | git.exe | 23220 | QuerySecurityFile     | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        | Information: 0x20
9:43:01.6068228 am | git.exe | 23220 | QueryAttributeTagFile | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        | Attributes: A, ReparseTag: 0x0
9:43:01.6068296 am | git.exe | 23220 | <Unknown>             | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        |
9:43:01.6068387 am | git.exe | 23220 | CloseFile             | C:\path\to\clone\.git\refs\remotes\origin\wip\some\branch.lock | SUCCESS        |
9:43:01.8263445 am | git.exe | 44796 | CreateFile            | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        | Desired Access: Generic Read/Write, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: 0, OpenResult: Created
9:43:01.8264466 am | git.exe | 44796 | QuerySecurityFile     | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        | Information: 0x20
9:43:01.8331550 am | git.exe | 44796 | CloseFile             | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        |
9:43:01.8332106 am | git.exe | 44796 | CreateFile            | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        | Desired Access: Read Attributes, Delete, Disposition: Open, Options: Non-Directory File, Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
9:43:01.8332251 am | git.exe | 44796 | QuerySecurityFile     | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        | Information: 0x20
9:43:01.8332297 am | git.exe | 44796 | QueryAttributeTagFile | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        | Attributes: A, ReparseTag: 0x0
9:43:01.8332356 am | git.exe | 44796 | <Unknown>             | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        |
9:43:01.8332430 am | git.exe | 44796 | CloseFile             | C:\path\to\clone\.git\objects\maintenance.lock                 | SUCCESS        |

Installation info:

$ cat /etc/install-options.txt
Editor Option: Notepad++
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: WinSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Rebase
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable FSMonitor: Disabled
$ cat /etc/install-options.txt
Editor Option: Notepad++
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: WinSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Rebase
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable FSMonitor: Disable
>ver

Microsoft Windows [Version 10.0.22631.4037]```
@roelandschoukens
Copy link
Author

nb. I've since solved this issue by removing the offending branch from .git/packed-refs. Someone apparently pushed branches with the same name with different case to our server, eg. mybranch and MyBranch. Maybe it is creating two lock files for those names. That doesn't work on Windows.

@dscho
Copy link
Member

dscho commented Jan 24, 2025

This should be relatively easy to turn into an actual reproducer, i.e. a script that sets up a local repository, clones it, then makes some changes in the first one, then fetches into the cloned repository.

@roelandschoukens
Copy link
Author

roelandschoukens commented Jan 28, 2025

I unfortunately don't have the exact sequence of events that got me into this situation.

I tried to reproduce it, but didn't get this exact error. I got a different error though which is presumably related to this one:

On Windows, you can create the “upstream” test repository in WSL2 so you have a case-sensitive file system.

Create the "upstream repository" and two branches:

mkdir testrepo-upstream
cd testrepo-upstream
git init .

git commit --allow-empty -m "test 1"
git branch test-branch
git commit --allow-empty -m "test 2"
git branch Test-Branch

Create the victim repository on an NTFS volume, and fetch:

mkdir testrepo-victim
pushd testrepo-victim
git init .
git remote add r1 //wsl.localhost/path-to/testrepo-upstream
git fetch r1

Now update the branches:

# On testrepo-upstream:
git commit --allow-empty -m "test 3"
git branch -f test-branch
git commit --allow-empty -m "test 4"
git branch -f Test-Branch

And fetch on the victim:

# On testrepo-victim:
git fetch r1

This prints an error:

error: cannot lock ref 'refs/remotes/r1/test-branch': is at 56ea4621fd63826818892512a84c9894b2f2809c but expected 452ac1aeb83b035cac9ec74fa3336dc3488f5de6
 ! 452ac1a..1bab116  test-branch -> r1/test-branch  (unable to update local ref)

This error was however recoverable by fetching again after the upstream branches were removed.

This repo also does not have a .git/packed-refs file.

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

No branches or pull requests

2 participants