feat(merge): remote-aware push with divergence reconciliation (BRW-IJBPWQ) - #2
Merged
Merged
Conversation
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.
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.
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
All three fields default off to preserve pre-0.38 behavior exactly.
Invariants preserved
Verification
BRW-IJBPWQ. Ready for review + merge.