Expand description
The shadow ref store: snapshot, private target, symbolic refs and HEAD.
What:
The shadow ref store: a snapshot of every real ref,
the private target ref,
symbolic refs,
and the private HEAD.
Why:
Hooks resolve tags, other branches and remote-tracking refs as they stood at invocation.
With the files backend the snapshot is one packed-refs file and the private target is a loose ref,
which takes precedence over a packed entry;
with reftable the snapshot is one update-ref --stdin transaction
(src/shadow-repository/shadow-refs.ts).
In TS you’d write (pseudocode):
await writeShadowRefs({ gitPath, cwd, shadowPath, capture });Structs§
- RefSnapshot
Entry - What: One real ref at invocation. Why: Symbolic refs and direct refs take different snapshot forms.
Constants§
- PACKED_
REFS_ HEADER - Header Git writes for a sorted
packed-refsfile without peeled lines. The trailing space matches Git’s own writer, which older readers require.
Functions§
- format_
packed_ refs - What: Formats the files-backend snapshot of every direct ref except the private target. Why: The target is written loose, so a packed copy would only be shadowed.
- list_
real_ refs - What:
Lists every real ref of the owning worktree in byte order.
Why:
Sorting by bytes matches the incumbent’s
Buffer.compareorder in the packed file. - write_
shadow_ refs - What:
Writes the shadow ref store:
the snapshot, the symbolic refs, the private target ref and
HEAD. Why: The order matches the incumbent’s: symbolic refs come after their targets exist, andHEADcomes last.