Skip to content

fix(ci): a sync clears git lock files left by an interrupted git - #82

Merged
Benbentwo merged 1 commit into
mainfrom
fix/stale-git-locks
Nov 17, 2026
Merged

Benbentwo merged 1 commit into
mainfrom
fix/stale-git-locks

Conversation

@Benbentwo

Copy link
Copy Markdown
Owner

Requested by Ben · project thread

Problem

A build that is cancelled, or a daemon that stops, while git is checking out leaves .git/index.lock in the work-root checkout. Every later sync of that repo then fails within seconds:

fatal: Unable to create '<checkout>/.git/index.lock': File exists.
ERROR: sync <repo>: git checkout: exit status 128

It stayed that way until someone removed the file by hand.

Change

syncRepo now removes any git lock file it finds in an existing checkout before it runs git: *.lock in the repo's git dir, under its refs, and the same in each submodule's git dir under .git/modules. Each removal is named in the build log.

This is safe because a sync runs under the workspace lock, so a git lock still on disk has no live owner among cooperating writers. docs/ci.md says so, and says not to run git by hand in a work-root checkout without taking that lock.

Tests

TestWorkspaceSyncClearsLocksLeftByAnInterruptedGit: plants four locks (index, HEAD, a ref, a submodule index), checks as a control that plain git refuses to check out over them, then checks the sync succeeds, lands on the pinned commit, removes all four and logs each.

go test ./... passes.

A build cancelled or a daemon stopped mid-checkout leaves .git/index.lock in
the checkout, and every later sync of that repo failed with 'Unable to create
index.lock: File exists' until someone removed the file by hand.

Each sync now removes any git lock it finds in the checkout before it starts
(the repo's git dir, its refs, and each submodule's git dir) and names each one
in the build log. The sync holds the workspace lock, so a lock still on disk has
no owner.
@Benbentwo Benbentwo self-assigned this Nov 17, 2026
@Benbentwo
Benbentwo marked this pull request as ready for review November 17, 2026 11:02
@Benbentwo
Benbentwo merged commit 94200b9 into main Nov 17, 2026
6 checks passed
@Benbentwo
Benbentwo deleted the fix/stale-git-locks branch November 17, 2026 11:04
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.

1 participant