#2427·go-git

改进孤立剥离线的处理

作者: 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:

  1. rewritePackedRefsWithoutRef scans packed-refs line by line and calls d.processLine(line).
  2. When ref != nil && ref.Name() == name, it sets found = true and executes continue, omitting the ref line from the rewritten packed-refs file.
  3. On the very next line (^<target-sha>), d.processLine(line) hits case '^': return nil, nil.
  4. Because ref == nil, rewritePackedRefsWithoutRef writes the ^<target-sha> line into the temporary packed-refs file. This causes two severe forms of corruption in packed-refs:
  5. 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 sorted header with no preceding reference record. Native git immediately aborts on all commands (git status, git fetch, git rev-list, etc.) with: fatal: unexpected line in .git/packed-refs: ^<sha>
  6. 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 in packed-refs.

go-git Version

v5.19.2