Skip to content

Auto-push, sync messaging, and stale-ref sync fixes#43

Merged
brdv merged 5 commits intomainfrom
improve-push-behavior
Mar 12, 2026
Merged

Auto-push, sync messaging, and stale-ref sync fixes#43
brdv merged 5 commits intomainfrom
improve-push-behavior

Conversation

@brdv
Copy link
Owner

@brdv brdv commented Mar 12, 2026

Summary

Dogfooding friction fixes and two sync correctness bugs.

Auto-push unpushed commits in new/submit, clarify sync step messaging, fix stale local main ref in sync, and fix chained sync regression for multi-branch stacks.

Auto-push: When a branch already has an upstream but has unpushed local commits, new and submit now auto-push before creating the PR. This removes the manual git push step that was required between stacked branch operations — without it, GitHub would reject PR creation with "No commits between base and head."

Sync messaging: When old and new base are the same branch name (after a parent PR merge), the message now reads "dropping already-upstream commits" instead of the confusing "onto main (from main)."

Stale local main (Fix 3): stck sync fetches from origin but resolve_base_ref() preferred local refs over remote refs. After a PR merges on GitHub, local main is stale, so the rebase --onto target and merge-base resolved to stale values — making sync a no-op. Fixed by flipping resolve_base_ref() to prefer refs/remotes/origin/<branch>.

Chained sync (Fix 4): The stale-main fix overcorrects for chained syncs. When syncing a 3+ branch stack, step N rebases a branch locally but the remote ref is stale (not yet pushed). Step N+1's --onto target resolves to that stale remote ref — a no-op that leaves the descendant diverged. Fixed by tracking rebased branches in a HashSet during the sync loop and using local refs for subsequent steps.

Changelist

  • src/gitops.rs — Add push_branch() for safe fast-forward pushes; add resolve_onto_ref() wrapper; flip resolve_base_ref() to prefer remote refs
  • src/commands.rsrun_new() and run_submit() auto-push when upstream exists but branch needs push
  • src/commands.rs — Sync step message branches on old_base_ref == new_base_ref to show "dropping already-upstream commits"
  • src/commands.rs — Sync loop uses resolve_onto_ref() for --onto target; tracks rebased_in_this_sync to use local ref for chained steps
  • tests/harness/mod.rs — Add stub handlers for plain git push origin <branch>, STCK_TEST_LOCAL_MAIN_SHA/STCK_TEST_REMOTE_MAIN_SHA env vars, split merge-base handling for local vs remote main
  • tests/new.rs — Add tests for auto-push and skip-push-when-up-to-date
  • tests/submit.rs — Add test for auto-push
  • tests/sync.rs — Add sync_uses_remote_main_when_local_main_is_stale and sync_chained_rebase_uses_local_ref_for_previously_rebased_branch; update existing chained sync assertions

Checklist

  • Changes are minimal and focused for this milestone
  • No breaking CLI changes unless explicitly intended
  • Errors are user-facing, actionable, and prefixed with error:
  • Added/updated tests for behavior changes
  • Updated docs/plan if behavior or scope changed

QA

  • stck new a → commit → stck new b → should auto-push a and create PR without error
  • stck submit on a branch with unpushed commits → should auto-push then create PR
  • Merge bottom PR in a stack → stck sync → step message says "dropping already-upstream commits"
  • Merge bottom PR in a 2-branch stack → stck sync → child rebases onto updated main (not a no-op)
  • Merge bottom PR in a 3-branch stack → stck sync → both descendants rebase correctly; no conflicts on GitHub

brdv and others added 5 commits March 12, 2026 20:04
When a branch already has an upstream but has unpushed local commits,
`new` and `submit` now auto-push before creating the PR. This prevents
the "No commits between base and head" GitHub error that forced a
manual `git push` between stacked branch operations.

Uses a regular push (not --force-with-lease) so non-fast-forward
pushes fail safely.

Also improves sync step messaging: when the old and new base are the
same branch (after a parent PR merge), the message now reads "dropping
already-upstream commits" instead of the confusing "from main" phrasing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@brdv brdv changed the title Auto-push unpushed commits and clarify sync messaging Auto-push, sync messaging, and stale-ref sync fixes Mar 12, 2026
@brdv brdv merged commit 84bf644 into main Mar 12, 2026
1 check passed
@brdv brdv deleted the improve-push-behavior branch March 12, 2026 21:37
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