Skip to content

refactor: derive undo's checkout target from state, not the command label#80

Merged
andyrewlee merged 1 commit into
mainfrom
audit/33-undo-drop-rename-label
Jun 15, 2026
Merged

refactor: derive undo's checkout target from state, not the command label#80
andyrewlee merged 1 commit into
mainfrom
audit/33-undo-drop-rename-label

Conversation

@andyrewlee

Copy link
Copy Markdown
Owner

undo_op.go was the one place the otherwise command-agnostic undo engine branched
on a literal command label (if entry.Label == "rename"), flagged as debt in its
own comment. Derive the post-undo checkout purely from the snapshot diff:
restoredRenameTarget (state diff) else missingRestoredRef (the lone recorded ref
the rebuild brought back) -- unconditionally, since restoredRenameTarget
short-circuits to "" when state is unavailable (the naive 'gate behind it' form
regresses the s==nil path). For a create-on-undo both yield "", so the generic
restore still runs. Adds an s==nil rename-recovery test for the previously
unguarded path.


Part of a 38-PR stacked diff (audit/01audit/38), reviewed and merged bottom-up. This PR is based on audit/32-document-flagsets-recipe.

@andyrewlee andyrewlee force-pushed the audit/32-document-flagsets-recipe branch from 3445c78 to bb0df97 Compare June 15, 2026 06:40
@andyrewlee andyrewlee changed the base branch from audit/32-document-flagsets-recipe to main June 15, 2026 06:41
@andyrewlee andyrewlee force-pushed the audit/33-undo-drop-rename-label branch from ebb7f32 to b8a7eda Compare June 15, 2026 06:41
undo_op.go was the one place the otherwise command-agnostic undo engine branched on a literal command label (if entry.Label == "rename"), flagged as debt in its own comment. That branch only recomputed the post-undo checkout for a renamed current branch — but the generic restore already lands HEAD on entry.CurrentBranch (the branch checked out when the command ran), which for a current-branch rename is the restored old name and for a create undo is the parent. The undo oracle in the model test even defines correct post-undo HEAD as entry.CurrentBranch, so a label-specific derivation could only ever agree with it.

So drop the label branch and the two helpers it used (restoredRenameTarget, missingRestoredRef), now dead, and rely on the generic restore. Add an s==nil rename-recovery test for the cmd loadErr path (Undo called with a nil state), where the generic entry.CurrentBranch restore still lands on the old name. The full engine suite — including the random invariant model that fuzzes rename+undo and asserts HEAD == entry.CurrentBranch — stays green.
@andyrewlee andyrewlee force-pushed the audit/33-undo-drop-rename-label branch from b8a7eda to d0777ab Compare June 15, 2026 06:47
@andyrewlee andyrewlee merged commit 4d71edc into main Jun 15, 2026
4 checks passed
@andyrewlee andyrewlee deleted the audit/33-undo-drop-rename-label branch June 15, 2026 06:48
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.

1 participant