Skip to content

submit: Refuse to overwrite commits pushed to a branch by someone else#1308

Open
ed-irl wants to merge 1 commit into
ed-irl/branch-syncfrom
ed-irl/submit-lease-protect
Open

submit: Refuse to overwrite commits pushed to a branch by someone else#1308
ed-irl wants to merge 1 commit into
ed-irl/branch-syncfrom
ed-irl/submit-lease-protect

Conversation

@ed-irl

@ed-irl ed-irl commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

gs branch submit previously force-pushed with a lease against the remote-tracking ref, which advances on every fetch and so could silently overwrite commits a maintainer (or anyone else) added to a branch after git-spice last pushed it.

Submit now leases against the commit git-spice itself last recorded pushing. Because that baseline only changes when git-spice pushes, it survives local restacks while still catching foreign commits. Before pushing, submit classifies the remote:

  • Advanced — the remote gained commits on top of our last push. Submit refuses, lists the offending commits (now including author email), and points to gs branch sync.
  • Diverged — the remote was rewritten away from our last push. Submit refuses since it can't tell what a force-push would discard.
  • No baseline — no record of the last push and the remote differs. Submit refuses rather than guess.
  • Safe / fast-forward / up-to-date — push proceeds, leasing against the recorded baseline.

--force overrides all of these.

Supporting changes:

  • git.ListCommitsDetails now also reports each commit's author email (%ae), used when listing foreign commits.
  • gs branch sync --rebase records the integrated remote head as the new baseline. A conflict-interrupted sync resumes via a hidden --record-pushed continuation that records the baseline without re-running the rebase.
  • branch split carries the last-pushed baseline onto the new branch so a later submit still has a baseline to check against.

Documented in the CR guide; added test scripts covering the advanced, diverged, and force-push cases.

@ed-irl

ed-irl commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Lease against the commit git-spice last pushed (UpstreamLastPushedHash)
instead of the local remote-tracking ref. The tracking ref advances on
every fetch, silently defeating --force-with-lease and letting submit
overwrite commits pushed by someone else.

Submit now classifies the remote against our last-pushed baseline and
refuses to overwrite when the remote has advanced (listing the foreign
commits and pointing to 'gs branch sync') or diverged. Because the
baseline is the remote-side last-pushed hash, this survives restacks,
which only rewrite local hashes.

Also carry the baseline when 'branch split' reassigns a CR to a new
branch, and record it after a conflicted 'branch sync --rebase' is
resumed, so a clean (non-force) submit works in both cases.
@abhinav abhinav force-pushed the ed-irl/branch-sync branch from 1725dbc to 7363b3a Compare June 28, 2026 14:04
@abhinav abhinav force-pushed the ed-irl/submit-lease-protect branch from 5c06b5d to b715e02 Compare June 28, 2026 14:04
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