refactor: derive undo's checkout target from state, not the command label#80
Merged
Merged
Conversation
3445c78 to
bb0df97
Compare
ebb7f32 to
b8a7eda
Compare
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.
b8a7eda to
d0777ab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/01…audit/38), reviewed and merged bottom-up. This PR is based onaudit/32-document-flagsets-recipe.