Skip to content

refactor(switch): consolidate handle_switch into worktree/switch - #2597

Merged
max-sixty merged 2 commits into
mainfrom
simplify/merge-handle-switch
May 4, 2026
Merged

max-sixty merged 2 commits into
mainfrom
simplify/merge-handle-switch

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • src/commands/handle_switch.rs was a thin coordinator over src/commands/worktree/switch.rs. The boundary forced cross-file imports of SwitchOptions, SwitchPlan, SwitchBranchInfo, SwitchResult, plan_switch, and execute_switch despite all the real work living in worktree/switch.rs.
  • Moved the body into worktree/switch.rs as run_switch (renamed from handle_switch) and deleted src/commands/handle_switch.rs.
  • Updated callers (main.rs, commands/picker/mod.rs), commands/mod.rs, the STDOUT_ALLOWED_PATHS allowlist in tests/integration_tests/output_system_guard.rs, and the handle_switch.rs reference in src/git/error.rs. Dropped the now-unused SwitchPlan re-export from commands/worktree/mod.rs.
  • No behavior change. cargo run -- hook pre-merge --yes passes (3490 tests + lints + doc + insta + lychee).

Test plan

  • cargo run -- hook pre-merge --yes (full pre-merge: tests, lints, doc, insta, lychee)
  • cargo check --bins --tests --features shell-integration-tests

🤖 Generated with Claude Code

worktrunk-bot
worktrunk-bot previously approved these changes May 4, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows build is broken: cargo build fails with three unused_imports errors in src/commands/worktree/mod.rs (test (windows) run).

The root cause is that commands::picker is #[cfg(unix)]-gated, and after this refactor picker is the only consumer of these re-exports. Before the move, handle_switch.rs (compiled on all platforms) also pulled them through worktree::*, which kept them live on Windows. Now that run_switch lives inside worktree/switch.rs and reaches its helpers via super::resolve::* and same-module paths, nothing on Windows references the worktree:: re-exports of offer_bare_repo_worktree_path_fix, execute_switch, plan_switch, approve_switch_hooks, run_pre_switch_hooks, or spawn_switch_background_hooks.

path_mismatch survives because repository_ext.rs (always compiled) still consumes it via super::worktree::path_mismatch.

Fix is to gate the picker-only re-exports on #[cfg(unix)]. Inline suggestion below. Happy to push the commit if you prefer.

The codecov/patch failure on the same run looks like a side-effect of the move — codecov treats lines 1045–1525 of the new switch.rs as added patch lines even though they're the same code as the old handle_switch.rs. Worth re-checking once Windows compiles.

Comment thread src/commands/worktree/mod.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review May 4, 2026 19:27

CI failed — Windows build breaks with unused_imports errors after the picker re-exports lost their non-picker consumer (handle_switch.rs).

`handle_switch.rs` was a thin coordinator over `worktree/switch.rs` —
loading config, planning, approving hooks, executing, and handling
output/shell-integration prompts. The split forced cross-file imports of
`SwitchOptions`, `SwitchPlan`, `SwitchBranchInfo`, `SwitchResult`,
`plan_switch`, and `execute_switch` despite all the real work living in
`worktree/switch.rs`.

Move the body into `worktree/switch.rs` as `run_switch` (renamed from
`handle_switch`) and delete `src/commands/handle_switch.rs`. Update the
two call sites (`main.rs`, `commands/picker/mod.rs`) and the
`STDOUT_ALLOWED_PATHS` allowlist. Drop the now-unused `SwitchPlan`
re-export from `commands/worktree/mod.rs`. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty force-pushed the simplify/merge-handle-switch branch from b5eeab3 to 5078f2d Compare May 4, 2026 20:10
After consolidating handle_switch into worktree/switch, several
worktree re-exports are consumed only by `commands::picker`, which
is `#[cfg(unix)]`-gated. On Windows they trigger `unused_imports`
and break the build. Gate them on `cfg(unix)` so they only exist
where their consumer does.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty force-pushed the simplify/merge-handle-switch branch from 5078f2d to 2ca655d Compare May 4, 2026 20:12
@max-sixty
max-sixty merged commit 3a01e67 into main May 4, 2026
26 of 27 checks passed
@max-sixty
max-sixty deleted the simplify/merge-handle-switch branch May 4, 2026 22:25
max-sixty added a commit that referenced this pull request May 4, 2026
Lost in the modify/delete merge with #2597 (which renamed handle_switch
to run_switch in worktree/switch.rs). Local pre-merge passed because the
working tree had the edit, but the merge commit didn't stage it.

Co-Authored-By: Claude <[email protected]>
max-sixty added a commit to mikeyroush/worktrunk that referenced this pull request May 11, 2026
Adds Azure DevOps as a third forge alongside GitHub and GitLab:

- `wt switch pr:N` dispatches to GitHub or Azure DevOps automatically based on
  the repo's configured remotes (GitHub still wins in mixed-remote setups).
- `wt list --full` surfaces Azure DevOps PR and pipeline status via the `az` CLI.
- `forge.platform` accepts `azure-devops` as an override.
- `wt config show --full` reports `az` install/auth state when the platform is
  detected as Azure DevOps.

Implementation notes:
- New `AzureDevOpsProvider` implements `RemoteRefProvider`; auto-detects the
  organisation from any Azure DevOps remote URL so contributors don't have to
  pass `--org`.
- `GitRemoteUrl` learns `is_azure_devops()`, `azure_organization()`, and
  `azure_project()` to parse `dev.azure.com`, `ssh.dev.azure.com`, and legacy
  `*.visualstudio.com` URLs (which don't fit the standard host/owner/repo shape).
- Pipeline URLs are constructed from org/project/build ID rather than the API's
  `url` field (which is a REST endpoint, not a browser URL).
- Requires the `azure-devops` extension (`az extension add --name azure-devops`).

Originally proposed by @mikeyroush in max-sixty#1256; reimplemented against current `main`
to pick up the `[forge]` config section (max-sixty#1826), `url.insteadOf` fallback (max-sixty#1771),
and `handle_switch` consolidation (max-sixty#2597) that landed after the original branch.

Co-Authored-By: mroush <[email protected]>
Co-Authored-By: Claude <[email protected]>
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.

2 participants