fix: derive needs_restack from git, not stale parent_head - #141
Merged
Conversation
`ez status` answered "does this branch need a restack?" by comparing the parent tip against the recorded `parent_head`. That SHA is only a cache of where the branch forked from its parent, and it goes stale whenever history moves outside ez — a hand-rolled `git rebase`, an amend in another worktree, a force-pushed parent. A branch sitting cleanly on top of its parent was therefore reported as needing a restack, in both `--json` and the human warning. `ez checkout` already asked git the right question, so the two commands disagreed about the same branch. Add a shared `restack::branch_needs_restack` that tests whether the parent tip is in the branch's history, and route both commands through it. The restack engine is unchanged: with a stale `parent_head` it already falls back to git's merge base, and the resulting no-op rebase is what refreshes the cache.
This was referenced Aug 11, 2026
Merged
rohoswagger
added a commit
that referenced
this pull request
Aug 11, 2026
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.
ez statusanswered "does this branch need a restack?" by comparing the parent tip against the recordedparent_head:That SHA is only a cache of where the branch forked from its parent. It goes stale whenever history moves outside ez — a hand-rolled
git rebase, an amend in another worktree, a force-pushed parent — so a branch sitting cleanly on top of its parent was reported as needing a restack, in both--jsonand the human warning.ez checkoutalready asked git the right question (git::is_ancestor), so the two commands disagreed about the same branch.Fix
Shared helper in
cmd/restack.rsthat asks git instead of the cache:cmd/status.rs— both the--jsonand human paths use it. The human path also no longer?-fails when the parent ref is gone.cmd/checkout.rs— routed through the same helper so the two can't drift apart again.The restack engine is unchanged. It keys off
parent_headtoo, but with a stale SHAeffective_old_basealready falls back to git's merge base and the resultinggit rebase --onto X X branchis a no-op that just refreshes the metadata — that's the healing path, working as intended.Tests
restack.rs: one rebases outside ez and asserts the stale cache produces no false positive (and that a genuinely moved parent still returns true); one covers the missing-parent guard.tests/navigation_status_cli.rsthat were asserting the buggy behaviour — they only corruptedparent_headand expected a warning. They now advance trunk for the positive case, plus new inverse tests: stale cache alone meansneeds_restack: falseand no warning printed.