Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(switch): accept pr:N/mr:N in --base (#2263)
Worktrunk Bot1d01a25e9043
diff --git a/docs/content/switch.md b/docs/content/switch.mdindex 7445b8a3c..583166fb8 100644--- a/docs/content/switch.md+++ b/docs/content/switch.md@@ -50,7 +50,9 @@ If the branch already has a worktree, `wt switch` changes directories to it. Oth| `pr:{N}` | GitHub PR #N's branch || `mr:{N}` | GitLab MR !N's branch |-{{ terminal(cmd="wt switch - # Back to previous|||wt switch ^ # Default branch worktree|||wt switch --create fix --base=@ # Branch from current HEAD|||wt switch pr:123 # PR #123's branch|||wt switch mr:101 # MR !101's branch") }}+{{ terminal(cmd="wt switch - # Back to previous|||wt switch ^ # Default branch worktree|||wt switch --create fix --base=@ # Branch from current HEAD|||wt switch --create fix --base=pr:123 # Branch from PR #123's head|||wt switch pr:123 # PR #123's branch|||wt switch mr:101 # MR !101's branch") }}++Shortcuts also apply to `--base`. For a fork PR/MR, the head commit is fetched and used as the base SHA without creating a tracking branch.## Interactive picker@@ -145,7 +147,8 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spa<b><span class=c>-b</span></b>, <b><span class=c>--base</span></b><span class=c> <BASE></span>Base branch- Defaults to default branch.+ Defaults to default branch. Supports the same shortcuts as the branch argument: <b>^</b>, <b>@</b>, <b>-</b>,+<b> pr:{N}</b>, <b>mr:{N}</b>.<b><span class=c>-x</span></b>, <b><span class=c>--execute</span></b><span class=c> <EXECUTE></span>Command to run after switchdiff --git a/skills/worktrunk/reference/switch.md b/skills/worktrunk/reference/switch.mdindex a1203fab0..2bd05f90e 100644--- a/skills/worktrunk/reference/switch.md+++ b/skills/worktrunk/reference/switch.md@@ -46,13 +46,16 @@ $ wt switch --create temp --no-hooks # Skip hooks| `mr:{N}` | GitLab MR !N's branch |```bash-$ wt switch - # Back to previous-$ wt switch ^ # Default branch worktree-$ wt switch --create fix --base=@ # Branch from current HEAD-$ wt switch pr:123 # PR #123's branch-$ wt switch mr:101 # MR !101's branch+$ wt switch - # Back to previous+$ wt switch ^ # Default branch worktree+$ wt switch --create fix --base=@ # Branch from current HEAD+$ wt switch --create fix --base=pr:123 # Branch from PR #123's head+$ wt switch pr:123 # PR #123's branch+$ wt switch mr:101 # MR !101's branch```+Shortcuts also apply to `--base`. For a fork PR/MR, the head commit is fetched and used as the base SHA without creating a tracking branch.+## Interactive pickerWhen called without arguments, `wt switch` opens an interactive picker to browse and select worktrees with live preview.@@ -136,7 +139,8 @@ Options:-b, --base <BASE>Base branch- Defaults to default branch.+ Defaults to default branch. Supports the same shortcuts as the branch argument: ^, @, -,+ pr:{N}, mr:{N}.-x, --execute <EXECUTE>Command to run after switchdiff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 07994305e..d770354a3 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -284,7 +284,8 @@ pub(crate) struct SwitchArgs {/// Base branch///- /// Defaults to default branch.+ /// Defaults to default branch. Supports the same shortcuts as the branch+ /// argument: `^`, `@`, `-`, `pr:{N}`, `mr:{N}`.#[arg(short = 'b', long, requires = "branch", add = crate::completion::branch_value_completer())]pub(crate) base: Option<String>,@@ -571,13 +572,16 @@ $ wt switch --create temp --no-hooks # Skip hooks| `mr:{N}` | GitLab MR !N's branch |```console-$ wt switch - # Back to previous-$ wt switch ^ # Default branch worktree-$ wt switch --create fix --base=@ # Branch from current HEAD-$ wt switch pr:123 # PR #123's branch-$ wt switch mr:101 # MR !101's branch+$ wt switch - # Back to previous+$ wt switch ^ # Default branch worktree+$ wt switch --create fix --base=@ # Branch from current HEAD+$ wt switch --create fix --base=pr:123 # Branch from PR #123's head+$ wt switch pr:123 # PR #123's branch+$ wt switch mr:101 # MR !101's branch```+Shortcuts also apply to `--base`. For a fork PR/MR, the head commit is fetched and used as the base SHA without creating a tracking branch.+## Interactive pickerWhen called without arguments, `wt switch` opens an interactive picker to browse and select worktrees with live preview.diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rsindex c3427ab65..8f3cef168 100644--- a/src/commands/worktree/switch.rs+++ b/src/commands/worktree/switch.rs@@ -260,30 +260,88 @@ fn resolve_same_repo_ref(repo: &Repository,info: &RemoteRefInfo,) -> anyhow::Result<ResolvedTarget> {- // Find the remote for the same-repo PR/MR and fetch the branch with an- // explicit refspec. This ensures the remote tracking branch is created even- // in repos with limited fetch refspecs (single-branch clones, bare repos).- let remote = remote_ref::find_remote(repo, info)?;+ fetch_same_repo_branch(repo, info)?;++ Ok(ResolvedTarget {+ branch: info.source_branch.clone(),+ method: CreationMethod::Regular {+ create_branch: false,+ base_branch: None,+ },+ })+}+/// Fetch a same-repo PR/MR's source branch with an explicit refspec so the+/// remote-tracking ref exists locally even in repos with limited fetch+/// refspecs (single-branch clones, bare repos).+fn fetch_same_repo_branch(repo: &Repository, info: &RemoteRefInfo) -> anyhow::Result<()> {+ let remote = remote_ref::find_remote(repo, info)?;let branch = &info.source_branch;eprintln!("{}",progress_message(cformat!("Fetching <bold>{branch}</> from {remote}...")));- // Explicit refspec creates/updates the remote-tracking ref even when it's outside- // the configured fetch refspec (e.g., single-branch clones, bare repos).let refspec = format!("+refs/heads/{branch}:refs/remotes/{remote}/{branch}");// Use -- to prevent branch names starting with - from being interpreted as flagsrepo.run_command(&["fetch", "--", &remote, &refspec]).with_context(|| cformat!("Failed to fetch branch <bold>{}</> from {}", branch, remote))?;+ Ok(())+}- Ok(ResolvedTarget {- branch: info.source_branch.clone(),- method: CreationMethod::Regular {- create_branch: false,- base_branch: None,- },- })+/// Resolve a `--base` value, expanding `pr:`/`mr:` shortcuts. Non-shortcut+/// inputs go through [`Repository::resolve_worktree_name`] (handles `@`/`-`/`^`).+fn resolve_base_ref(repo: &Repository, base: &str) -> anyhow::Result<String> {+ if let Some(suffix) = base.strip_prefix("pr:")+ && let Ok(number) = suffix.parse::<u32>()+ {+ return resolve_remote_ref_as_base(repo, &GitHubProvider, number);+ }++ if let Some(suffix) = base.strip_prefix("mr:")+ && let Ok(number) = suffix.parse::<u32>()+ {+ return resolve_remote_ref_as_base(repo, &GitLabProvider, number);+ }++ repo.resolve_worktree_name(base)+}++/// Resolve `pr:{N}` / `mr:{N}` for `--base`. Same-repo returns the source+/// branch name; fork returns the PR head SHA so we don't create a tracking+/// branch for a ref the user hasn't asked to check out.+fn resolve_remote_ref_as_base(+ repo: &Repository,+ provider: &dyn RemoteRefProvider,+ number: u32,+) -> anyhow::Result<String> {+ let ref_type = provider.ref_type();+ let symbol = ref_type.symbol();++ eprintln!(+ "{}",+ progress_message(cformat!(+ "Fetching base {} {symbol}{number}...",+ ref_type.name()+ ))+ );++ let info = provider.fetch_info(number, repo)?;+ eprintln!("{}", format_with_gutter(&format_ref_context(&info), None));++ if !info.is_cross_repo {+ fetch_same_repo_branch(repo, &info)?;+ return Ok(info.source_branch.clone());+ }++ let remote = remote_ref::find_remote(repo, &info)?;+ let display = ref_type.display(number);+ repo.run_command(&["fetch", "--", &remote, &provider.tracking_ref(number)])+ .with_context(|| cformat!("Failed to fetch <bold>{display}</> from {remote}"))?;+ Ok(repo+ .run_command(&["rev-parse", "FETCH_HEAD"])+ .context("Failed to resolve FETCH_HEAD to a commit SHA")?+ .trim()+ .to_string())}/// Resolve the switch target, handling pr:/mr: syntax and --create/--base flags.@@ -330,7 +388,7 @@ fn resolve_switch_target();None} else {- let resolved = repo.resolve_worktree_name(base_str)?;+ let resolved = resolve_base_ref(repo, base_str)?;if !repo.ref_exists(&resolved)? {return Err(GitError::ReferenceNotFound {reference: resolved,diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex 8bd4dce7b..365c97c62 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -2238,6 +2238,248 @@ fn test_switch_pr_base_conflict(repo: TestRepo) {});}+/// `wt switch --create X --base pr:N` resolves the PR to its head branch for+/// a same-repo PR, fetching the branch so it's usable as the base.+#[rstest]+fn test_switch_base_pr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {+ // Create the PR source branch on the remote so we have something to fetch+ repo.add_worktree("feature-auth");+ repo.run_git(&["push", "origin", "feature-auth"]);++ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .run()+ .unwrap()+ .stdout,+ )+ .trim()+ .to_string();++ // Rewrite origin so find_remote_for_repo matches owner/test-repo+ repo.run_git(&[+ "remote",+ "set-url",+ "origin",+ "https://github.com/owner/test-repo.git",+ ]);+ repo.run_git(&[+ "config",+ &format!("url.{}.insteadOf", bare_url),+ "https://github.com/owner/test-repo.git",+ ]);++ let gh_response = r#"{+ "title": "Fix authentication bug in login flow",+ "user": {"login": "alice"},+ "state": "open",+ "draft": false,+ "head": {+ "ref": "feature-auth",+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}+ },+ "base": {+ "ref": "main",+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}+ },+ "html_url": "https://github.com/owner/test-repo/pull/101"+ }"#;++ let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));++ let settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(+ &repo,+ "switch",+ &[+ "--create",+ "feat/visual-tweaks",+ "--base",+ "pr:101",+ "--no-cd",+ ],+ None,+ );+ configure_mock_gh_env(&mut cmd, &mock_bin);+ assert_cmd_snapshot!("switch_base_pr_same_repo", cmd);+ });+}++/// `wt switch --create X --base pr:N` resolves a fork PR to its head commit+/// SHA via refs/pull/N/head without creating a tracking branch.+#[rstest]+fn test_switch_base_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {+ // Create a PR head commit and push it as refs/pull/42/head on the remote+ repo.run_git(&["checkout", "-b", "pr-source"]);+ fs::write(repo.root_path().join("pr-file.txt"), "PR content").unwrap();+ repo.run_git(&["add", "pr-file.txt"]);+ repo.run_git(&["commit", "-m", "PR commit"]);+ let commit_sha = repo+ .git_command()+ .args(["rev-parse", "HEAD"])+ .run()+ .unwrap();+ let sha = String::from_utf8_lossy(&commit_sha.stdout)+ .trim()+ .to_string();+ repo.run_git(&["push", "origin", &format!("{}:refs/pull/42/head", sha)]);+ repo.run_git(&["checkout", "main"]);++ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .run()+ .unwrap()+ .stdout,+ )+ .trim()+ .to_string();+ repo.run_git(&[+ "remote",+ "set-url",+ "origin",+ "https://github.com/owner/test-repo.git",+ ]);+ repo.run_git(&[+ "config",+ &format!("url.{}.insteadOf", bare_url),+ "https://github.com/owner/test-repo.git",+ ]);++ // head.repo differs from base.repo → fork PR+ let gh_response = r#"{+ "title": "Add feature fix for edge case",+ "user": {"login": "contributor"},+ "state": "open",+ "draft": false,+ "head": {+ "ref": "feature-fix",+ "repo": {"name": "test-repo", "owner": {"login": "contributor"}}+ },+ "base": {+ "ref": "main",+ "repo": {"name": "test-repo", "owner": {"login": "owner"}}+ },+ "html_url": "https://github.com/owner/test-repo/pull/42"+ }"#;++ let mock_bin = setup_mock_gh_for_pr(&repo, Some(gh_response));++ let mut settings = setup_snapshot_settings(&repo);+ // Fork base resolves to a commit SHA (no tracking branch created). Mask it+ // so the snapshot is stable across the test repo's non-deterministic SHAs.+ // Can't use \b because ANSI escape characters aren't word boundaries.+ settings.add_filter(r"[0-9a-f]{40}", "[SHA]");+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(+ &repo,+ "switch",+ &["--create", "my-work", "--base", "pr:42", "--no-cd"],+ None,+ );+ configure_mock_gh_env(&mut cmd, &mock_bin);+ assert_cmd_snapshot!("switch_base_pr_fork", cmd);+ });++ // The PR branch name must NOT have been created as a local branch — we+ // just based `my-work` on the PR's head commit.+ let branches = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["branch", "--list"])+ .run()+ .unwrap()+ .stdout,+ )+ .into_owned();+ assert!(+ !branches.contains("feature-fix"),+ "fork PR head should not produce a local tracking branch: {branches}"+ );+ assert!(+ !branches.contains("contributor/feature-fix"),+ "prefixed fork PR branch should not be created: {branches}"+ );+}++/// `wt switch --create X --base mr:N` resolves a same-repo MR to its source+/// branch, fetching it so the base is usable.+#[rstest]+fn test_switch_base_mr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {+ repo.add_worktree("feature-auth");+ repo.run_git(&["push", "origin", "feature-auth"]);++ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .run()+ .unwrap()+ .stdout,+ )+ .trim()+ .to_string();+ repo.run_git(&[+ "remote",+ "set-url",+ "origin",+ "https://gitlab.com/owner/test-repo.git",+ ]);+ repo.run_git(&[+ "config",+ &format!("url.{}.insteadOf", bare_url),+ "https://gitlab.com/owner/test-repo.git",+ ]);++ let glab_response = r#"{+ "title": "Fix authentication bug in login flow",+ "author": {"username": "alice"},+ "state": "opened",+ "draft": false,+ "source_branch": "feature-auth",+ "source_project_id": 123,+ "target_project_id": 123,+ "web_url": "https://gitlab.com/owner/test-repo/-/merge_requests/101"+ }"#;++ let mock_bin = setup_mock_glab_for_mr(&repo, Some(glab_response));++ let settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(+ &repo,+ "switch",+ &["--create", "feat/follow-up", "--base", "mr:101", "--no-cd"],+ None,+ );+ configure_mock_glab_env(&mut cmd, &mock_bin);+ assert_cmd_snapshot!("switch_base_mr_same_repo", cmd);+ });+}++/// `--base pr:N` is ignored when `--create` is absent: we warn and do NOT+/// hit the network. `gh` is intentionally not mocked — if the resolver ran,+/// the command would fail with "gh: command not found".+#[rstest]+fn test_switch_base_pr_without_create(#[from(repo_with_remote)] mut repo: TestRepo) {+ // A branch that already exists so `wt switch` can succeed without --create+ repo.add_worktree("existing");++ let settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(+ &repo,+ "switch",+ &["existing", "--base", "pr:101", "--no-cd"],+ None,+ );+ assert_cmd_snapshot!("switch_base_pr_without_create", cmd);+ });+}+/// Test fork PR where branch already exists and tracks same PR (should reuse)#[rstest]fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo) {diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snapindex a9f1319b4..d3bc71c6c 100644--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap@@ -52,7 +52,7 @@ Usage: [1m[36mwt switch[0m [36m[OPTIONS][0m [36m[BRANCH][0m [1m[36m[--[1m[36m-b[0m, [1m[36m--base[0m[36m [0m[36m<BASE>[0mBase branch[0m- Defaults to default branch.[0m+ Defaults to default branch. Supports the same shortcuts as the branch argument: [1m^[0m, [1m@[0m, [1m-[0m, [1mpr:{N}[0m, [1mmr:{N}[0m.[0m[1m[36m-x[0m, [1m[36m--execute[0m[36m [0m[36m<EXECUTE>[0mCommand to run after switch[0m@@ -157,11 +157,14 @@ If the branch already has a worktree, [2mwt switch[0m changes directories to i[2mpr:{N}[0m GitHub PR #N's branch[2mmr:{N}[0m GitLab MR !N's branch-[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m-[0m[2m # Back to previous[0m[2m[0m-[107m [0m [2m[0m[2m[34mwt[0m[2m switch ^ # Default branch worktree[0m[2m[0m-[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m fix [0m[2m[36m--base=@[0m[2m # Branch from current HEAD[0m[2m[0m-[107m [0m [2m[0m[2m[34mwt[0m[2m switch pr:123 # PR #123's branch[0m[2m[0m-[107m [0m [2m[0m[2m[34mwt[0m[2m switch mr:101 # MR !101's branch[0m[2m[0m+[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m-[0m[2m # Back to previous[0m[2m[0m+[107m [0m [2m[0m[2m[34mwt[0m[2m switch ^ # Default branch worktree[0m[2m[0m+[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m fix [0m[2m[36m--base=@[0m[2m # Branch from current HEAD[0m[2m[0m+[107m [0m [2m[0m[2m[34mwt[0m[2m switch [0m[2m[36m--create[0m[2m fix [0m[2m[36m--base=pr:123[0m[2m # Branch from PR #123's head[0m[2m[0m+[107m [0m [2m[0m[2m[34mwt[0m[2m switch pr:123 # PR #123's branch[0m[2m[0m+[107m [0m [2m[0m[2m[34mwt[0m[2m switch mr:101 # MR !101's branch[0m[2m[0m++Shortcuts also apply to [2m--base[0m. For a fork PR/MR, the head commit is fetched and used as the base SHA without creating a tracking branch.[1m[32mInteractive picker[0mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_base_mr_same_repo.snap b/tests/snapshots/integration__integration_tests__switch__switch_base_mr_same_repo.snapnew file mode 100644index 000000000..b9b71f0ff--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_base_mr_same_repo.snap@@ -0,0 +1,56 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - feat/follow-up+ - "--base"+ - "mr:101"+ - "--no-cd"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching base MR !101...[39m+[107m [0m [1mFix authentication bug in login flow[22m (!101)+[107m [0m by @alice · opened · feature-auth · [90mhttps://gitlab.com/owner/test-repo/-/merge_requests/101[39m+[36m◎[39m [36mFetching [1mfeature-auth[22m from origin...[39m+[32m✓[39m [32mCreated branch [1mfeat/follow-up[22m from [1mfeature-auth[22m and worktree @ [1m_REPO_.feat-follow-up[22m[39m+[2m↳[22m [2mTo customize worktree locations, run [4mwt config create[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_base_pr_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_base_pr_fork.snapnew file mode 100644index 000000000..4203c783e--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_base_pr_fork.snap@@ -0,0 +1,55 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - my-work+ - "--base"+ - "pr:42"+ - "--no-cd"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching base PR #42...[39m+[107m [0m [1mAdd feature fix for edge case[22m (#42)+[107m [0m by @contributor · open · contributor:feature-fix · [90mhttps://github.com/owner/test-repo/pull/42[39m+[32m✓[39m [32mCreated branch [1mmy-work[22m from [1m[SHA][22m and worktree @ [1m_REPO_.my-work[22m[39m+[2m↳[22m [2mTo customize worktree locations, run [4mwt config create[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_base_pr_same_repo.snap b/tests/snapshots/integration__integration_tests__switch__switch_base_pr_same_repo.snapnew file mode 100644index 000000000..935c719d2--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_base_pr_same_repo.snap@@ -0,0 +1,56 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - feat/visual-tweaks+ - "--base"+ - "pr:101"+ - "--no-cd"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching base PR #101...[39m+[107m [0m [1mFix authentication bug in login flow[22m (#101)+[107m [0m by @alice · open · feature-auth · [90mhttps://github.com/owner/test-repo/pull/101[39m+[36m◎[39m [36mFetching [1mfeature-auth[22m from origin...[39m+[32m✓[39m [32mCreated branch [1mfeat/visual-tweaks[22m from [1mfeature-auth[22m and worktree @ [1m_REPO_.feat-visual-tweaks[22m[39m+[2m↳[22m [2mTo customize worktree locations, run [4mwt config create[24m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_base_pr_without_create.snap b/tests/snapshots/integration__integration_tests__switch__switch_base_pr_without_create.snapnew file mode 100644index 000000000..1f6fe42c5--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_base_pr_without_create.snap@@ -0,0 +1,51 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - existing+ - "--base"+ - "pr:101"+ - "--no-cd"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[33m▲[39m [33m--base flag is only used with --create, ignoring[39m+[2m○[22m Switched to worktree for [1mexisting[22m @ [1m_REPO_.existing[22m