mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
fix(git): never discard committed local work in rebase_onto_base (#683)
The shared rebase primitive (dev sync_branch verb, PM/CEO rebase path,
submit-freshen, merge-conflict resolver) opened with fetch -> checkout ->
unconditional reset --hard origin/<head_branch>. The dirty-tree gate
protects uncommitted edits only; the reset silently rewound past every
committed-but-unpushed commit — and the commit do-verb never pushes, so
mid-rework a dev routinely has exactly that. The force-with-lease push
then republished the truncated branch as authoritative (the lease
matched the freshly-fetched, never-moved origin ref).
rebase_onto_base now classifies local vs origin/<head> post-fetch:
- behind/equal: reset --hard origin as before (origin loses nothing)
- strictly ahead: reset skipped — the rebase runs from the local tip and
the lease'd push publishes the previously-doomed commits
- diverged: a patch-equivalence probe (rev-list --right-only
--cherry-pick) first rescues the self-inflicted residue of a prior
rebase whose force-push failed (treated as ahead, self-heals on
retry); only genuine two-sided divergence returns a new
{status: diverged, local_only, origin_only} — no reset, no rebase,
no push, neither side silently discarded
- an absent local ref is recovered from origin (branch + checkout,
never reset)
Callers: the sync_branch verb maps diverged to an actionable envelope
steering to i_am_blocked (stash-preserved note included); the
submit-freshen hard-rejects it like conflicts; the merge-conflict
resolver already escalates any non-rebased/superseded status to the
CEO and degrades gracefully (pinned by test, no code change).
New real-git suite (bare origin + clone, no subprocess mocking)
asserts origin-side outcomes: ahead-publishes, behind-adopts,
diverged-refuses-untouched, absent-ref recovery, superseded,
conflicts, and wedge self-heal on retry via a rejecting pre-receive
hook.
Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
@@ -1463,7 +1463,10 @@ async def test_rebase_onto_base_stash_true_auto_stashes_and_pops() -> None:
|
||||
if args[:2] == ["status", "--porcelain"]:
|
||||
res.stdout = " M dirty.py\n"
|
||||
elif args[:2] == ["rev-list", "--count"]:
|
||||
res.stdout = "1"
|
||||
# Only the post-rebase unique-vs-base count is non-zero; the
|
||||
# pre-rebase local-vs-origin(HEAD) classification reads as
|
||||
# "nothing unique on either side" (behind/equal, not diverged).
|
||||
res.stdout = "1" if args[2] == "origin/master..HEAD" else "0"
|
||||
else:
|
||||
res.stdout = ""
|
||||
return res
|
||||
@@ -1499,7 +1502,10 @@ async def test_rebase_onto_base_stash_pop_conflict_preserves_stash() -> None:
|
||||
if args[:2] == ["status", "--porcelain"]:
|
||||
res.stdout = " M dirty.py\n"
|
||||
elif args[:2] == ["rev-list", "--count"]:
|
||||
res.stdout = "1"
|
||||
# Only the post-rebase unique-vs-base count is non-zero; the
|
||||
# pre-rebase local-vs-origin(HEAD) classification reads as
|
||||
# "nothing unique on either side" (behind/equal, not diverged).
|
||||
res.stdout = "1" if args[2] == "origin/master..HEAD" else "0"
|
||||
elif args == ["stash", "pop"]:
|
||||
res.returncode = 1 # pop conflicted — stash is NOT dropped by git
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user