fix(git): regenerate missing packfile index to recover orphaned packs#38388
Draft
bircni wants to merge 1 commit into
Draft
fix(git): regenerate missing packfile index to recover orphaned packs#38388bircni wants to merge 1 commit into
bircni wants to merge 1 commit into
Conversation
lunny
reviewed
Jul 10, 2026
| // pack without its ".idx" makes the whole repository unreadable with "packfile not found". | ||
| // This happens on Windows (issue #38359): the gogit storage keeps ".pack" descriptors open, | ||
| // so git's repack cleanup can delete the ".idx" while failing to unlink the locked ".pack". | ||
| repairOrphanPackIndexes(ctx, gitDirPath) |
Member
There was a problem hiding this comment.
Does this mean it will be checked for every repository where it is used?
Contributor
|
I don't think it's right to keep adding more patches. There are far more "git repo maintenance" related problems. For example: stale ".lock" files. Ideally, we need a "maintenance" zone on the repo setting page, let repo owner "fix" the repo in wrong state. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #38359.
On Windows, the official Gitea binary is built with the
gogittag, so git objects are read through go-git instead of the git CLI. go-git opens repositories withKeepDescriptors: true(modules/git/repo_base_gogit.go), which keeps every.packfile descriptor open for the lifetime of the cached repository.When a subsequent
git pushtriggers auto-gc /repack -d, git consolidates packfiles and unlinks the redundant ones. On Windows an open handle blocks deletion — but go-git only holds the.packopen (it opens.idxfiles transiently and closes them). So git succeeds in deleting the.idxwhile failing to unlink the still-locked.pack, leaving an orphan packfile with no index.The next time a fresh go-git storage opens that repository,
ObjectStorage.requireIndex()scans for*.packfiles and tries to load each.idx. The orphan's missing index returnsErrPackfileNotFound("packfile not found"), and becauserequireIndexaborts on the first failure, every object read then fails with a500 Internal Server Error— on the web UI, the API, and actions (GetBranchCommit,ListBranches,CreateCommitStatusForRunJobs, etc.), exactly as seen in the reported logs.The reporter's manual workaround (regenerating the missing
.idx) isgit index-packunder the hood, so this is safe to automate — the packfile still contains all objects, only the index is gone.