Skip to content

Fix force-with-lease safety bypass caused by pre-push fetch#42

Merged
brdv merged 3 commits intomainfrom
fix/push-ancestor-check-before-force-push
Mar 12, 2026
Merged

Fix force-with-lease safety bypass caused by pre-push fetch#42
brdv merged 3 commits intomainfrom
fix/push-ancestor-check-before-force-push

Conversation

@brdv
Copy link
Owner

@brdv brdv commented Mar 12, 2026

Summary

Prevent stck push from silently overwriting remote commits when --force-with-lease is neutralized by a prior git fetch origin.

run_push calls gitops::fetch_origin() before gitops::push_force_with_lease(), which updates remote tracking refs to match the actual remote. Since --force-with-lease (without an explicit expected SHA) checks against those tracking refs, the safety check always passes after a fresh fetch — even when the remote has commits the local branch doesn't contain. This adds a pre-push ancestor check using the existing gitops::is_ancestor() helper: before each force push, verify that origin/<branch> is an ancestor of the local <branch>. If not, abort with a clear error telling the user to integrate remote changes first.

Changelist

  • src/commands.rs — Add ancestry guard in the run_push loop before each push_force_with_lease call
  • tests/push.rs — Add push_aborts_when_remote_has_commits_not_in_local_branch integration test
  • tests/harness/mod.rs — Add STCK_TEST_NOT_ANCESTOR_PAIRS env var support and self-identity ancestor rule to git stub

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

@brdv brdv merged commit 7e89898 into main Mar 12, 2026
1 check passed
@brdv brdv deleted the fix/push-ancestor-check-before-force-push branch March 12, 2026 18:31
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