改进孤立剥离线的处理
作者: rngassa-stack创建于 2026年9月25日更新于 2026年9月25日
标签bug
Bug Description
When dotgit.DotGit.RemoveReference (via rewritePackedRefsWithoutRef) deletes a reference from packed-refs that has a corresponding peeled line (^<sha>, such as an annotated tag in a # pack-refs with: peeled fully-peeled sorted file), it skips writing the reference line <tag-sha> refs/tags/<name>, but does not skip the immediately following ^<peeled-sha> line.
In storage/filesystem/dotgit/dotgit.go:
rewritePackedRefsWithoutRefscanspacked-refsline by line and callsd.processLine(line).- When
ref != nil && ref.Name() == name, it setsfound = trueand executescontinue, omitting the ref line from the rewrittenpacked-refsfile. - On the very next line (
^<target-sha>),d.processLine(line)hitscase '^': return nil, nil. - Because
ref == nil,rewritePackedRefsWithoutRefwrites the^<target-sha>line into the temporarypacked-refsfile. This causes two severe forms of corruption inpacked-refs: - Total repository corruption when the deleted tag is the first entry in
packed-refs: The^<target-sha>line appears immediately after the# pack-refs with: peeled fully-peeled sortedheader with no preceding reference record. Nativegitimmediately aborts on all commands (git status,git fetch,git rev-list, etc.) with:fatal: unexpected line in .git/packed-refs: ^<sha> - Silent metadata corruption when the deleted tag is NOT the first entry: The
^<target-sha>line becomes attached as the peeled value of whatever reference happened to precede the deleted tag inpacked-refs.
go-git Version
v5.19.2
内容来源: go-git/go-git