Skip to content

feat(merge): remote-aware push with divergence reconciliation (BRW-IJBPWQ) - #2

Merged
JonathanWorks merged 1 commit into
mainfrom
feat/merge-remote-reconcile-v2
Apr 22, 2026
Merged

feat(merge): remote-aware push with divergence reconciliation (BRW-IJBPWQ)#2
JonathanWorks merged 1 commit into
mainfrom
feat/merge-remote-reconcile-v2

Conversation

@JonathanWorks

Copy link
Copy Markdown

Supersedes #1. Squashed to a single clean commit for clean main history after the local-squash vs remote-history collision that this PR fixes (the irony is intentional).

Lifts the manual wt-restack recovery flow into a built-in wt merge phase so agent-only workflows no longer spend ~15 min per merge recovering from the non-fast-forward collision when a feature branch has intermediate CI-visibility commits.

Why

In agent-only workflows (pwm-os, DIRTMAN, brainwrap itself), feature branches are pushed to origin while work is in progress because CI, PR review, and multi-session handoffs all need the commits resolvable on the remote. When wt merge later locally squashes the branch, a plain git push hits non-fast-forward. Force-push is hook-blocked in governed repos. The workaround was a manual wt-restack — create a -vN branch, close the old PR, open a new PR. Two such events in a single pwm-os session on 2026-04-22 (PRs 695→703 and 709→714) motivated this, plus THIS very PR's own supersession.

What

New module src/commands/worktree/remote_reconcile.rs classifies local-vs-remote state into four variants and dispatches to a configured reconciliation strategy: Absent (first push), InSync (no-op), Ahead (rebase), Diverges (apply [merge] on_diverged_remote: remote-squash / restack / abort).

Config

[merge]
push_to_origin = true
on_diverged_remote = "remote-squash"
auto_open_pr_if_missing = true

All three fields default off to preserve pre-0.38 behavior exactly.

Invariants preserved

  • Zero force-push in any path.
  • gh pr merge stays internal to wt (governance rule unchanged for developer CLI).
  • Default push_to_origin = false preserves pre-0.38 model.

Verification

  • 7 new unit tests pass.
  • cargo test --lib 1000/1001 (1 pre-existing mock_commands flake).
  • cargo test --bin wt 584/584.
  • cargo clippy --all-targets -- -D warnings clean.
  • cargo fmt applied.
  • pre-commit gates: no-direct-cmd-output now clean (refactored gh helper onto shell_exec::Cmd).

BRW-IJBPWQ. Ready for review + merge.

Remote-aware feature branch push to origin during `wt merge`, with three configurable strategies for handling divergence between the local squash and pre-existing remote commits. Integrates GitHub CLI for server-side squash-merge, branch restacking, or explicit abort. Routes `gh` invocations through `shell_exec::Cmd` to comply with pre-commit rules. Adds `[merge] push_to_origin`, `on_diverged_remote`, and `auto_open_pr_if_missing` config options. Resolves the collision between agent-only workflows (which push intermediate commits for CI/review) and local squashing by delegating merge-time push decisions to user-configurable policies instead of requiring force-push or project-level hooks.
@JonathanWorks
JonathanWorks merged commit 995c11a into main Apr 22, 2026
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