Clearer force params#53
Merged
Merged
Conversation
The previous --force was always lease-protected: PlansToPushCommands sent the captured session-start target hash as the push command's expected-old, and receive-pack rejected updates where the target had moved during the run. The name oversold the danger — it never matched git push --force's raw clobber semantics. Replace with two explicit flags matching git push's surface: - --force-with-lease — previous behavior (allow non-FF, send captured target tip as expected-old; server rejects on lease miss). - --force-blind — new path; zero the expected-old for non-delete commands so receive-pack overwrites regardless of current target value. Matches git push --force. The two are mutually exclusive. Legacy --force errors out with a migration hint pointing at both replacements (pre-0.5, no installed script base to preserve). bootstrap and replicate continue to reject force flags entirely. SyncPolicy.Force splits into ForceWithLease + ForceBlind on the public API; syncer.Config grows a ForceAny() helper for the internal "allow non-FF" sense (planner permissiveness). convert.PlansToPushCommands takes a forceBlind bool; incremental/materialized strategies plumb it from cfg, others pass false since bootstrap/replicate reject force. Closes the rename portion of #47. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: a733497c4d7f
When a non-BestEffort push gets a CommandStatusErr whose status looks like a lease miss (stale info / fetch first / non-fast-forward / does not match expected old value), wrap it with "target ref X moved or differs from session start; rerun, or use --force-blind to overwrite." The wrapper preserves the underlying CommandStatusErr via fmt.Errorf %w, so callers and tests that inspect the typed error keep working; the hint is purely additive on the error message. Closes the reason-text portion of #47. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 6432aa0b89a7
- Use cobra's MarkFlagsMutuallyExclusive for the lease/blind pair instead of a hand-rolled RunE check. - Pull lease-failure markers to a package-level var; loop the contains-checks for symmetry and to keep the list in one place. - Trim PlansToPushCommands doc; lease semantics already live on SyncPolicy. - Shorten the legacy --force migration message. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 604f682ccdc6
nodo
previously approved these changes
May 13, 2026
Three issues from review on top of the force-clarification branch: 1. BestEffort silently defeated --force-with-lease. The OnRejection callback installed under BestEffort stored every per-ref ng status for downgrade to a warning, including lease-mismatch statuses. `sync --all-refs --force-with-lease` could then exit successfully after a concurrent target update, contradicting the lease. Export gitproto.IsLeaseFailure and add a syncer.leaseFailureError pass after finalizeCounts. Lease-class rejections (stale info / fetch first / non-fast-forward / does not match) now escalate to a fatal error even with BestEffort on; non-lease rejections continue to downgrade to warnings. 2. Public and unstable APIs accepted invalid force combinations and only rejected them deep in newSession (after auth resolution). Add SyncPolicy.Validate, invoke it from gitsync.SyncRequest.Validate and gitsync.PlanRequest.Validate, and from unstable.Client.Sync, .Plan, .Replicate. The syncer.go check stays as defense-in-depth for callers reaching syncer.Config directly (tests). 3. docs/usage.md described replicate as "fast-forward-only by design"; in fact replicate's contract is source-authoritative overwrite — divergent branches and tags are retargeted unconditionally, which is why force flags are unnecessary rather than disallowed by a gate. Rewrite the sentence. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: eaa899c96ddf
The lease-failure marker set in gitproto is intentionally broad to catch phrasing across servers (stale info / fetch first / non-fast-forward / does not match). That's right under --force-with-lease, where the user has explicitly promised "rerun if target moved." But the same server messages can mean ordinary policy rejection on a --force-blind or non-force best-effort run, which BestEffort is allowed to downgrade to warnings. Gate leaseFailureError on cfg.ForceWithLease so the escalation only fires when the lease contract is actually in effect. Other rejection paths follow the BestEffort warn-and-continue contract as documented. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 153a4deb52ba
errorlint flagged the `!= err` comparison on a wrapped error. The helper currently returns the input untouched on the non-lease branch (so `==` works), but the contract is "pass through unchanged" — switch to errors.Is so the test still passes if the helper ever wraps with a non-lease annotation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: b1e36ac6c6d5
The parser already rejects --force with a migration hint, but the usageError() string still listed it as a valid flag. Replace with --force-with-lease and --force-blind so the help text matches what the parser accepts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 98799f8a9225
nodo
approved these changes
May 14, 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.
Clarify force semantics:
--force-with-leaseand--force-blindCloses #47.
The old
--forcewas always lease-protected — it sent the captured session-start target tip as the push command's expected-old, so receive-pack rejected updates where the target had moved during the run. The name oversold the danger: it never matchedgit push --force's raw clobber.Replace it with two explicit flags that mirror git's surface:
--force-with-lease— previous behavior (allow non-FF, captured tip as expected-old; server rejects on lease miss).--force-blind— new path (zero expected-old, overwrite regardless of current target value; matchesgit push --force).The two flags are mutually exclusive. Legacy
--forceerrors out with a migration hint.bootstrapandreplicatecontinue to reject force flags entirely. Pre-0.5, so hard switch — no silent semantics flip.On the API side,
SyncPolicy.Forcesplits intoForceWithLease+ForceBlind.convert.PlansToPushCommandstakes aforceBlindbool; sync's incremental and materialized strategies plumb it through.Also: when receive-pack returns a lease-failure
ng(stale info / fetch first / non-fast-forward / does not match), the error is wrapped with a "target ref X moved or differs from session start; rerun, or use --force-blind to overwrite" hint.Notes
docs/usage.md.--forcerejection, mutual exclusion, replicate-with-force rejection, and the lease-failure annotation.Note
Medium Risk
Changes force-push behavior and CLI/API semantics, including a new blind overwrite path that can clobber target refs if misused. Touches core sync planning/push code paths, though guarded by mutual-exclusion checks and expanded tests.
Overview
Replaces the single
--forceknob with two explicit options:--force-with-lease(previous behavior) and--force-blind(true overwrite by sending a zero expected-old), enforcing mutual exclusivity and rejecting the legacy--forceflag with migration guidance.Plumbs the new policy fields through public/unstable API types and internal
syncerconfig (ForceAny()for callers that only need “force enabled”), and updates strategies to generate push commands accordingly (blind mode zeroesOldon non-delete updates).Improves user feedback: planner/block messages now reference
--force-with-lease, blocked-sync guidance mentions both flags, and receive-pack lease-relatedngerrors are annotated with a rerun/--force-blindhint. Docs and tests are updated to cover the new flags and rejection cases (replicate/bootstrap force rejection, legacy flag rejection, and mutual exclusion).Reviewed by Cursor Bugbot for commit 1ce7b69. Configure here.