Skip to content

feat(staged): show "Force push" on PR button when branch has diverged#752

Merged
matt2e merged 2 commits into
mainfrom
pr-button-to-show-force-push
May 27, 2026
Merged

feat(staged): show "Force push" on PR button when branch has diverged#752
matt2e merged 2 commits into
mainfrom
pr-button-to-show-force-push

Conversation

@matt2e
Copy link
Copy Markdown
Contributor

@matt2e matt2e commented May 27, 2026

Summary

When a branch has diverged from its upstream (e.g. after a rebase or amend), the PR button now shows "Force push" instead of "Push changes" without needing to hold the option key. Holding option still forces a force push when the local state alone wouldn't have triggered it.

Changes

  • Introduce derivePrPushAction returning 'none' | 'push' | 'forcePush', classifying diverged as forcePush and localAhead as push.
  • shouldShowPushChanges is preserved as a thin wrapper for callers that only need the boolean.
  • BranchCardPrButton derives pushAction and uses it for the label, tooltip, and click handler — option-held still forces force push.
  • Fork PRs (no origin/<branch>) keep the existing fallback: classified as push, with the backend's non-FF rejection driving the force-push dialog.
  • Adds unit tests covering each upstream relation, fork PR fallback, merged/no-PR/null gitState, and the wrong-branch guard.

Test plan

  • Branch with local commits ahead of upstream → button reads "Push changes"
  • Branch that has been rebased/amended (diverged) → button reads "Force push" without holding option
  • In-sync branch → no push action shown
  • Holding option on a localAhead branch still triggers force push

Replaces the boolean `shouldShowPushChanges` predicate with a richer
`derivePrPushAction` that mirrors the timeline's logic: `localAhead`
becomes `'push'`, `diverged` becomes `'forcePush'`, and the PR button's
label, click handler, and tooltip all read from it. Alt remains a
manual override so users can still force-push a fast-forward branch,
and fork PRs (missing upstream) keep the existing `'push'` + backend
non-FF rejection fallback.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
@matt2e matt2e requested review from baxen and wesbillman as code owners May 27, 2026 04:46
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4f21c9e80

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/staged/src/lib/features/branches/BranchCardPrButton.svelte Outdated
When the PR button is in "Force push" mode (branch diverged from
origin) clicking it now opens the existing force-push confirmation
dialog instead of force-pushing immediately. Holding alt at click
time skips the confirmation, matching the alt-override semantics used
elsewhere for power users who know they want to clobber the remote.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
@matt2e matt2e merged commit eb9dbf6 into main May 27, 2026
5 checks passed
@matt2e matt2e deleted the pr-button-to-show-force-push branch May 27, 2026 05:21
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