Skip to content

Use common dir to locate packed-refs and reftable - #1657

Merged
tmat merged 1 commit into
dotnet:release/10.0.4xxfrom
tmat:FixWorktreeRefs
Apr 27, 2026
Merged

tmat merged 1 commit into
dotnet:release/10.0.4xxfrom
tmat:FixWorktreeRefs

Conversation

@tmat

@tmat tmat commented Apr 21, 2026 •

Copy link
Copy Markdown
Member

The docs https://git-scm.com/docs/git-pack-refs say the packed-refs file is in $GIT_DIR, but it's actually in $GIT_COMMON_DIR. This is mentioned in https://git-scm.com/docs/gitrepository-layout#Documentation/gitrepository-layout.txt-packed-refs.

Similarly, reftable is also located in $GIT_COMMON_DIR even though the doc says it's in $GIT_DIR.

Fixes #1290
Includes #1289 by @vikukush

@tmat
tmat requested a review from ViktorHofer as a code owner April 21, 2026 14:47
@tmat

tmat commented Apr 21, 2026

Copy link
Copy Markdown
Member Author

@jjonescz ptal

@tmat
tmat merged commit 317814b into dotnet:release/10.0.4xx Apr 27, 2026
9 checks passed
@tmat

tmat commented May 1, 2026

Copy link
Copy Markdown
Member Author

/backport to release/10.0.3xx

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.3xx (link to workflow run)

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 3, 2026
richlander added a commit to richlander/dotnet-inspect that referenced this pull request Aug 3, 2026
* Name the missing SourceLink when a source-backed section has no rows

A test that inspects the test assembly and asks for `Source Locations`
reported "produced no data after being listed by -D" when the build
emitted no SourceLink. That names the symptom, so the failure reads as a
product regression in whatever changed most recently — which is exactly
the misdiagnosis recorded in #3658.

The environment can silently withhold SourceLink. Under a .NET 11 SDK,
`Microsoft.Build.Tasks.Git` reads `packed-refs` from `$GIT_DIR` rather
than `$GIT_COMMON_DIR`; those coincide for a primary checkout and differ
for a linked worktree, so a worktree whose branch ref has been packed by
`git gc` resolves no revision and the build emits no SourceLink, with no
warning and a green build. Fixed upstream by dotnet/sourcelink#1657,
which the .NET 11 SDK has not ingested.

`TestAssemblySourceLink` probes the test assembly's own PDB and, when the
SourceLink blob is absent, supplies a hint naming the cause and the
repair. `CliDiscoverySections_AreSelectable` appends it only for
source-backed sections, so an unrelated failure is not misattributed to
the environment. The assertions still fail rather than skip: absent
SourceLink is a repairable broken environment, not an unavailable
optional tool, and skipping would drop real coverage.

Validated both directions on the full CLI suite (2843 tests, 0 failed,
14 platform skips). Rebuilding the test assembly with
`/p:EnableSourceLink=false` — verified to strip the blob from the PDB —
reproduces #3658's exact message and now appends the cause; the normal
build is green.

Refs #3658

Co-authored-by: Copilot <[email protected]>

* Validate PDB identity, hedge the cause, and narrow the hint

Addresses three findings from the GPT-5.6 review round on PR #3713, each
reproduced first on a clean review worktree at the reviewed head.

Probe through `PdbContext` instead of `SourceLinkReader`. Only
`PdbContext` validates that the adjacent PDB belongs to the assembly, so
a stale or foreign PDB carrying its own SourceLink map satisfied the old
probe while the product rejected it — suppressing the hint in exactly the
case that needed it. Reproduced by copying `dotnet-inspect.pdb` over the
test PDB: the test failed with the bare pre-PR message. It now names the
mismatch.

Hedge the diagnosis. The probe establishes that SourceLink is absent, not
why, yet the hint asserted packed refs and prescribed a git repair for
every cause, including an explicitly disabled build that no ref surgery
can fix. It now reports the observation as fact, offers #3658 as the
known candidate with a `git rev-parse --git-common-dir` check to confirm
it, and names the causes needing no repair. That also corrects the path:
a linked worktree's `packed-refs` lives in the common dir, not in its own
`.git`.

Narrow the predicate. `Context: Source Location` resolves from
portable-PDB sequence points and still renders method, token, file, and
line without SourceLink, dropping only the URL — verified by A/B against
token `0x060007A2`. Hinting there would misattribute an unrelated token
or PDB failure to the environment, the very mistake this exists to
prevent, so it is removed. The predicate now also requires the command to
inspect the test assembly, since `package` and `diff` reach artifacts
whose SourceLink is independent of this build.

Add `TestAssemblySourceLinkTests` as the non-vacuity gate. A probe stuck
at "available" would never fire and a probe stuck at "unavailable" would
smear an irrelevant note across unrelated failures; nothing else in the
suite would notice either way.

Validated on all three states: normal build green; foreign PDB and
`/p:EnableSourceLink=false` each fail with the correct distinct reason.
Full CLI suite 2844 tests, 0 failed, 14 platform skips.

Refs #3658

Co-authored-by: Copilot <[email protected]>

* Make the confirmation check sound and the gate kill both mutations

Addresses the two Medium findings from review round 2 on PR #3713.

The suggested confirmation was defective. `test -f` on
`refs/heads/$(git rev-parse --abbrev-ref HEAD)` succeeds in the healthy
loose-ref state and fails in states unrelated to #3658, so its polarity
was ambiguous; in a detached worktree it tested `refs/heads/HEAD`, and
the prescribed repair would then have created a branch literally named
`HEAD`. The check now requires all three conditions that define the
defect — HEAD on a branch, a linked worktree, and no loose ref under the
common dir — and states that exit 0 means the cause applies. Verified
across four checkout shapes: primary on a branch, linked worktree with a
loose ref, detached linked worktree, and linked worktree with a packed
ref. Only the last reports a match.

Testing that also showed the repair itself was wrong, and that the
workaround recorded in issue #3658 does not work: `git update-ref
<branch> HEAD` is a no-op when the value is unchanged, so the ref stays
packed. `git branch -f` refuses outright for a branch checked out in a
worktree. Deleting and recreating the ref does work, leaves HEAD
attached, and does not touch the working tree — confirmed with an
uncommitted file present. That is what the hint now prescribes, with the
no-op called out so the obvious command is not retried.

The gate asserted only the available branch, so a probe hard-wired to
"available" would have passed it and the full suite while silently
retiring the diagnostic — the mutation that costs an investigation.
`DescribeUnavailability` now takes a path, and the gate drives it over a
copy with no adjacent PDB and a copy carrying another assembly's
SourceLink-bearing PDB. Both mutations were injected and confirmed
killed: always-available fails 2 tests, always-unavailable fails 1.

Full CLI suite 2846 tests, 0 failed, 14 platform skips. The
`/p:EnableSourceLink=false` end-to-end path still reports the missing
blob and now carries the corrected check and repair.

Refs #3658

Co-authored-by: Copilot <[email protected]>

* Make the check path-safe and the repair reflog-safe

Addresses the two Medium findings from review round 3 on PR #3713, both
reproduced first.

The confirmation check false-positived in a primary checkout. Git answers
`--git-common-dir` relatively when invoked below the repository root
while `--git-dir` stays absolute, so the string comparison read
`/home/rich/git/dotnet-inspect/.git` against `../.git` and concluded
"linked worktree" — sending a developer into ref surgery on a checkout
that emits SourceLink correctly. `--path-format=absolute` on both sides
fixes it. A `show-ref --verify` clause was added alongside, so a branch
whose ref is simply gone is no longer reported as merely packed.

The repair discarded the branch reflog and left a window in which
symbolic HEAD pointed at a missing ref: interrupt it between the delete
and the recreate and `git rev-parse HEAD` fails outright. Renaming the
branch away and back rewrites the ref loosely without either cost — HEAD
follows each rename and stays resolvable throughout, so an interruption
leaves the branch under its temporary name rather than gone, and the
reflog carries across.

Both shipped strings were extracted from the emitted failure message and
run verbatim. The check reports a match in exactly one of eight checkout
shapes — primary and linked, root and subdirectory, loose and packed,
detached, and ref-deleted — and that one is the defect. The repair clears
it while preserving HEAD attachment, the reflog, upstream tracking, and
an uncommitted file.

Closing the loop end to end on a scratch repository: a linked worktree
with a packed ref builds "Source Link is empty"; after the shipped
repair the same build reports "Updating Source Link file"; and
`gc.packRefs false` keeps the ref loose across `git gc --prune=now`.
Every claim the hint makes is now measured.

Full CLI suite 2846 tests, 0 failed, 14 platform skips.

Refs #3658

Co-authored-by: Copilot <[email protected]>

* Split the repair by ref format and mark unverified claims

A reftable repository keeps a per-worktree ref stack, so a linked worktree
loses SourceLink whether or not anything was ever packed. Measured: a linked
worktree of a reftable repo builds "Source Link is empty" while its primary
checkout builds "Updating Source Link file".

The shipped check already reports those cases correctly, but the repair did
not apply to them: renaming a branch produces no loose ref under reftable,
gc.packRefs is meaningless, and `git refs migrate` refuses while worktrees
exist. A developer following the hint would loop forever. Split the repair on
`git rev-parse --show-ref-format` and, for reftable, direct them to the
primary checkout or a fixed SDK.

Also mark the command strings and the section predicate as enforced by no
gate, per the AGENTS.md rule that an asserted property names its gate or says
it has none.

Co-authored-by: Copilot <[email protected]>

* Disable the maintenance pack-refs task alongside gc.packRefs

gc.packRefs governs git gc only. The pack-refs maintenance task runs
pack-refs --all --prune regardless, so a repository with background
maintenance enabled repacks the repaired ref and silently re-breaks
SourceLink. Measured: with gc.packRefs=false, git gc leaves the loose ref
alone but git maintenance run --task=pack-refs removes it.

Prescribe maintenance.pack-refs.enabled=false as well, and say the settings
stop automatic repacking rather than all recurrence, since neither
constrains an explicit git pack-refs.

Co-authored-by: Copilot <[email protected]>

* Point the hint at the issue and drop an unreachable predicate clause

Six review rounds found six defects in the hint's embedded shell advice and
none in the surrounding code. That text is an unbounded surface — correct
advice varies by ref-storage backend, by whether git is invoked at the
repository root, and by which repacking setting applies — and no test can
execute it, so drift is silent. Keep the diagnosis, which is what a failing
assertion needs, and let issue #3658 carry the recipes and stay current.

The predicate's SourceLink: clause was unreachable. Those sections sit behind
the @SourceLink category door, which -D reports as a category rather than
expanding, so the discovery loop never selects one: measured 11 section rows
for library and 17 for type against the test assembly, none of them prefixed
SourceLink:. Source Locations, on member commands, is the sole live path,
confirmed by an EnableSourceLink=false build emitting the hint there and
nowhere else.

Co-authored-by: Copilot <[email protected]>

* Honor unprobed sections in discovery selection tests

-D lists sections with ProbeEffectiveness=false structurally, and the section
contract explicitly permits their -S result to be empty. Derive the discovery
test's non-empty exemptions from the type-detail and member-overload pipelines
instead of treating unavailable SourceLink as a broken test environment.

Keep asserting that every discovered section is selectable. Delete the
SourceLink-specific probe, diagnostics, and tests: packed refs, reftable, an
archive without .git, and EnableSourceLink=false are all valid ways for
SourceLink data to be unavailable, and the product already reports that state
correctly.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
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.

2 participants