Skip to content

fix: tolerate transient git temp files during .git removal#267

Closed
test1-deepthought wants to merge 1 commit into
leanprover:mainfrom
test1-deepthought:fix/rmtree-ignore-errors
Closed

fix: tolerate transient git temp files during .git removal#267
test1-deepthought wants to merge 1 commit into
leanprover:mainfrom
test1-deepthought:fix/rmtree-ignore-errors

Conversation

@test1-deepthought

Copy link
Copy Markdown

Summary

shutil.rmtree on the cloned .git directory fails with FileNotFoundError when Git's pack-bitmap machinery leaves transient scratch files (e.g. bitmap-ref-tips_*) in .git/objects/pack/ that are deleted between os.scandir and os.unlink during traversal.

Root Cause

In clone_at_sha(), git fetch --depth=1 origin <sha> triggers Git's pack-bitmap machinery, which creates temporary files in .git/objects/pack/ with names like bitmap-ref-tips_TcnqzU. These are scratch files used by pack-bitmap-write.c to compute reachability bitmaps. Git typically cleans them up, but when a shallow fetch resolves to a commit not reachable from any ref tip, the temp files can be left behind and may be deleted between os.scandir and os.unlink.

Fix

Added ignore_errors=True to shutil.rmtree(). The .git directory is being deleted solely to scrub the auth token from origin remote URL in .git/config — any leftover temp files that can't be unlinked are harmless.

Fixes #266

Related Issue

#266

Git's pack-bitmap machinery creates transient scratch files (e.g.
`bitmap-ref-tips_*`) in `.git/objects/pack/` during shallow fetches.
These can be deleted between `os.scandir` and `os.unlink` during
`shutil.rmtree`, causing a FileNotFoundError crash.

Added `ignore_errors=True` to `shutil.rmtree()` so leftover temp files
that disappear mid-traversal are silently skipped. The `.git` directory
is being deleted solely to scrub the auth token; any surviving temp
files are harmless.

Fixes leanprover#266
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.

[submission] EVO (deepthought.com.au)

1 participant