Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(switch): handle fork branch conflicts on GitLab and Azure DevOps (#4542)

Worktrunk Bot0081536a2b0e
diff --git a/docs/src/content/docs/switch.md b/docs/src/content/docs/switch.md
index d9cc1858f..916a8509e 100644
--- a/docs/src/content/docs/switch.md
+++ b/docs/src/content/docs/switch.md
@@ -166,7 +166,7 @@ $ wt switch --prs # Browse open PRs/MRs in the
Both work anywhere a branch is accepted, including `--base`. The `--create` flag cannot be used with a PR/MR reference since the branch already exists.
-If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. A pre-existing local branch with that name tracking something else requires renaming first.
+If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. If a local branch with that name already exists for a different ref, Worktrunk uses a prefixed branch instead. The prefixed branch can fetch the PR or MR but cannot push to the fork.
The `--prs` flag adds the repository's open PRs (GitHub) or MRs (GitLab) that aren't already in the interactive picker. Selecting one switches to it as `pr:<number>` / `mr:<number>` would.
diff --git a/plugins/worktrunk/skills/worktrunk/reference/switch.md b/plugins/worktrunk/skills/worktrunk/reference/switch.md
index ad6cb6c26..a622cfb46 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/switch.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/switch.md
@@ -142,7 +142,7 @@ $ wt switch --prs # Browse open PRs/MRs in the
Both work anywhere a branch is accepted, including `--base`. The `--create` flag cannot be used with a PR/MR reference since the branch already exists.
-If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. A pre-existing local branch with that name tracking something else requires renaming first.
+If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. If a local branch with that name already exists for a different ref, Worktrunk uses a prefixed branch instead. The prefixed branch can fetch the PR or MR but cannot push to the fork.
The `--prs` flag adds the repository's open PRs (GitHub) or MRs (GitLab) that aren't already in the interactive picker. Selecting one switches to it as `pr:<number>` / `mr:<number>` would.
diff --git a/skills/worktrunk/reference/switch.md b/skills/worktrunk/reference/switch.md
index ad6cb6c26..a622cfb46 100644
--- a/skills/worktrunk/reference/switch.md
+++ b/skills/worktrunk/reference/switch.md
@@ -142,7 +142,7 @@ $ wt switch --prs # Browse open PRs/MRs in the
Both work anywhere a branch is accepted, including `--base`. The `--create` flag cannot be used with a PR/MR reference since the branch already exists.
-If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. A pre-existing local branch with that name tracking something else requires renaming first.
+If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. If a local branch with that name already exists for a different ref, Worktrunk uses a prefixed branch instead. The prefixed branch can fetch the PR or MR but cannot push to the fork.
The `--prs` flag adds the repository's open PRs (GitHub) or MRs (GitLab) that aren't already in the interactive picker. Selecting one switches to it as `pr:<number>` / `mr:<number>` would.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 7b3ae5045..f8bf71303 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -768,7 +768,7 @@ $ wt switch --prs # Browse open PRs/MRs in the
Both work anywhere a branch is accepted, including `--base`. The `--create` flag cannot be used with a PR/MR reference since the branch already exists.
-If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. A pre-existing local branch with that name tracking something else requires renaming first.
+If the PR or MR is on a fork, the local branch uses its branch name directly, so `git push` works normally. If a local branch with that name already exists for a different ref, Worktrunk uses a prefixed branch instead. The prefixed branch can fetch the PR or MR but cannot push to the fork.
The `--prs` flag adds the repository's open PRs (GitHub) or MRs (GitLab) that aren't already in the interactive picker. Selecting one switches to it as `pr:<number>` / `mr:<number>` would.
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rs
index 32f76a051..b6f103080 100644
--- a/src/commands/worktree/switch.rs
+++ b/src/commands/worktree/switch.rs
@@ -398,8 +398,16 @@ fn resolve_fork_ref(
));
}
- // Branch exists but doesn't track this ref - try prefixed name (GitHub/Gitea)
- if let Some(prefixed) = info.prefixed_local_branch_name() {
+ // GitLab defers project URL lookup until a new branch is needed.
+ let mut prefixed_info = info.clone();
+ if forge == ForgeKind::GitLab {
+ let urls =
+ worktrunk::git::remote_ref::gitlab::fetch_gitlab_project_urls(info, repo_root)?;
+ prefixed_info.fork_push_url = urls.fork_push_url;
+ }
+
+ // A conflicting branch uses a fetch-only prefixed name on every forge.
+ if let Some(prefixed) = prefixed_info.prefixed_local_branch_name() {
if let Some(prefixed_tracks) = branch_tracks_ref(
repo_root,
&prefixed,
@@ -432,8 +440,7 @@ fn resolve_fork_ref(
.into());
}
- // GitHub and Gitea support prefixed branch names. This path has no
- // fork push URL, so the branch remains fetch-only.
+ // This path has no fork push URL, so the branch remains fetch-only.
let remote = remote_ref::find_remote(repo, info)?;
return Ok((
Selector::rewritten_to(prefixed),
@@ -447,7 +454,7 @@ fn resolve_fork_ref(
));
}
- // GitLab and Azure DevOps don't support prefixed branch names.
+ // The fork URL was missing or did not identify a usable prefix.
return Err(GitError::BranchTracksDifferentRef {
branch: local_branch,
ref_type,
diff --git a/src/git/remote_ref/info.rs b/src/git/remote_ref/info.rs
index c4704ab07..6fd61f802 100644
--- a/src/git/remote_ref/info.rs
+++ b/src/git/remote_ref/info.rs
@@ -139,14 +139,23 @@ impl RemoteRefInfo {
/// Generate a prefixed local branch name for when the unprefixed name conflicts.
///
- /// Returns `<owner>/<branch>` (e.g., `contributor/main`).
- /// Used for GitHub/Gitea fork PRs; GitLab and Azure DevOps don't support this pattern.
+ /// Uses the fork owner, GitLab namespace, or Azure DevOps fork repository name.
+ /// GitLab needs its deferred fork URL populated before calling this method.
pub fn prefixed_local_branch_name(&self) -> Option<String> {
match &self.platform_data {
PlatformData::GitHub { head_owner, .. } | PlatformData::Gitea { head_owner, .. } => {
Some(format!("{}/{}", head_owner, self.source_branch))
}
- PlatformData::GitLab { .. } | PlatformData::AzureDevOps { .. } => None,
+ PlatformData::GitLab { .. } => self
+ .fork_push_url
+ .as_deref()
+ .and_then(crate::git::GitRemoteUrl::parse)
+ .map(|url| format!("{}/{}", url.owner(), self.source_branch)),
+ PlatformData::AzureDevOps { .. } => self
+ .fork_push_url
+ .as_deref()
+ .and_then(crate::git::GitRemoteUrl::parse)
+ .map(|url| format!("{}/{}", url.repo(), self.source_branch)),
}
}
}
@@ -339,7 +348,7 @@ mod tests {
#[test]
fn test_prefixed_local_branch_name_gitlab() {
- let info = RemoteRefInfo {
+ let mut info = RemoteRefInfo {
number: 101,
title: "Test".to_string(),
author: "contributor".to_string(),
@@ -357,8 +366,16 @@ mod tests {
target_project_id: 123,
},
};
- // GitLab doesn't support prefixed branch names
- assert_eq!(info.prefixed_local_branch_name(), None);
+ assert_eq!(
+ info.prefixed_local_branch_name(),
+ Some("contributor/main".to_string())
+ );
+ info.fork_push_url =
+ Some("ssh://[email protected]:2222/group/subgroup/repo.git".to_string());
+ assert_eq!(
+ info.prefixed_local_branch_name(),
+ Some("group/subgroup/main".to_string())
+ );
}
#[test]
@@ -436,7 +453,7 @@ mod tests {
source_branch: "main".to_string(),
is_cross_repo: true,
url: "https://dev.azure.com/myorg/myproject/_git/myrepo/pullrequest/550".to_string(),
- fork_push_url: None,
+ fork_push_url: Some("[email protected]:v3/myorg/myproject/myrepo-fork".to_string()),
platform_data: PlatformData::AzureDevOps {
host: "dev.azure.com".to_string(),
organization: "myorg".to_string(),
@@ -444,7 +461,10 @@ mod tests {
repo_name: "myrepo".to_string(),
},
};
- assert_eq!(info.prefixed_local_branch_name(), None);
+ assert_eq!(
+ info.prefixed_local_branch_name(),
+ Some("myrepo-fork/main".to_string())
+ );
}
#[test]
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index e4cc649ba..ce430a128 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -7253,8 +7253,10 @@ fn test_switch_pr_azure_visualstudio_host(#[from(repo_with_remote)] mut repo: Te
});
}
-#[rstest]
-fn test_switch_pr_azure_fork(#[from(repo_with_remote)] repo: TestRepo) {
+/// Pushes an Azure DevOps fork PR head to `refs/pull/42/head` and mocks `az`
+/// to describe it. `fork_urls` is the fork's `(remoteUrl, sshUrl)`; `None`
+/// leaves both `null`.
+fn setup_azure_fork_pr(repo: &TestRepo, fork_urls: Option<(&str, &str)>) -> std::path::PathBuf {
repo.run_git(&["checkout", "-b", "azure-pr-source"]);
fs::write(
repo.root_path().join("azure-pr-file.txt"),
@@ -7276,12 +7278,9 @@ fn test_switch_pr_azure_fork(#[from(repo_with_remote)] repo: TestRepo) {
repo.run_git(&["push", "origin", &format!("{}:refs/pull/42/head", sha)]);
repo.run_git(&["checkout", "main"]);
- set_azure_remote_url(
- &repo,
- "https://dev.azure.com/myorg/myproject/_git/test-repo",
- );
+ set_azure_remote_url(repo, "https://dev.azure.com/myorg/myproject/_git/test-repo");
- let az_response = r#"{
+ let az_response = serde_json::json!({
"title": "Add feature fix for edge case",
"createdBy": {"uniqueName": "[email protected]"},
"status": "active",
@@ -7294,13 +7293,23 @@ fn test_switch_pr_azure_fork(#[from(repo_with_remote)] repo: TestRepo) {
},
"forkSource": {
"repository": {
- "remoteUrl": "https://dev.azure.com/myorg/myproject/_git/test-repo-fork",
- "sshUrl": "[email protected]:v3/myorg/myproject/test-repo-fork"
+ "remoteUrl": fork_urls.map(|(remote_url, _)| remote_url),
+ "sshUrl": fork_urls.map(|(_, ssh_url)| ssh_url)
}
}
- }"#;
+ })
+ .to_string();
+ setup_mock_az(repo, &az_response)
+}
- let mock_bin = setup_mock_az(&repo, az_response);
+const AZURE_FORK_URLS: (&str, &str) = (
+ "https://dev.azure.com/myorg/myproject/_git/test-repo-fork",
+ "[email protected]:v3/myorg/myproject/test-repo-fork",
+);
+
+#[rstest]
+fn test_switch_pr_azure_fork(#[from(repo_with_remote)] repo: TestRepo) {
+ let mock_bin = setup_azure_fork_pr(&repo, Some(AZURE_FORK_URLS));
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -7310,6 +7319,41 @@ fn test_switch_pr_azure_fork(#[from(repo_with_remote)] repo: TestRepo) {
});
}
+/// A local `feature-fix` that doesn't track the PR makes the checkout use the
+/// fork repository name as a prefix.
+#[rstest]
+fn test_switch_pr_azure_fork_conflict(#[from(repo_with_remote)] repo: TestRepo) {
+ let mock_bin = setup_azure_fork_pr(&repo, Some(AZURE_FORK_URLS));
+ repo.run_git(&["branch", "feature-fix", "main"]);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_azure_fork_conflict", cmd);
+ });
+ assert_eq!(
+ repo.git_output(&["config", "branch.test-repo-fork/feature-fix.merge"])
+ .trim(),
+ "refs/pull/42/head"
+ );
+}
+
+/// Without a fork URL there is no repository name to prefix with, so a
+/// conflicting local branch still errors.
+#[rstest]
+fn test_switch_pr_azure_fork_missing_url(#[from(repo_with_remote)] repo: TestRepo) {
+ let mock_bin = setup_azure_fork_pr(&repo, None);
+ repo.run_git(&["branch", "feature-fix", "main"]);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_azure_fork_missing_url", cmd);
+ });
+}
+
/// With no `webUrl` in the response, the org and host come from the local
/// remote. An `ssh.dev.azure.com` remote must still suggest an HTTPS
/// `dev.azure.com` URL for the PR's repository, not one on the SSH host.
@@ -7642,12 +7686,29 @@ fn setup_mock_glab_for_mr(repo: &TestRepo, glab_response: &str) -> std::path::Pa
MockConfig::new("glab")
.version("glab version 1.40.0 (mock)")
.command("api", MockResponse::file("mr_response.json"))
+ .command(
+ "api projects/456",
+ MockResponse::output(r#"{"ssh_url_to_repo":"[email protected]:group/subgroup/test-repo.git","http_url_to_repo":"https://gitlab.com/group/subgroup/test-repo.git"}"#),
+ )
+ .command(
+ "api projects/123",
+ MockResponse::output(r#"{"ssh_url_to_repo":"[email protected]:owner/test-repo.git","http_url_to_repo":"https://gitlab.com/owner/test-repo.git"}"#),
+ )
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
mock_bin
}
+fn prepare_gitlab_conflicting_fork_ref(repo: &TestRepo) {
+ repo.run_git(&["push", "origin", "main:refs/merge-requests/42/head"]);
+ let bare_url = repo.git_output(&["config", "remote.origin.url"]);
+ let bare_url = bare_url.trim();
+ let gitlab_url = "https://gitlab.com/owner/test-repo.git";
+ repo.run_git(&["remote", "set-url", "origin", gitlab_url]);
+ repo.run_git(&["config", &format!("url.{bare_url}.insteadOf"), gitlab_url]);
+}
+
/// Test that --create flag conflicts with mr: syntax
#[rstest]
fn test_switch_mr_create_conflict(#[from(repo_with_remote)] repo: TestRepo) {
@@ -8402,7 +8463,7 @@ fn test_switch_mr_fork_existing_branch_tracks_mr(#[from(repo_with_remote)] repo:
"https://gitlab.com/owner/test-repo.git",
]);
- // Fork MR response (project URLs not needed since branch already exists)
+ // The branch already tracks this MR, so project URLs are not fetched.
let glab_response = r#"{
"title": "Add feature fix for edge case",
"author": {"username": "contributor"},
@@ -8444,15 +8505,9 @@ fn test_switch_mr_fork_existing_branch_tracks_different(#[from(repo_with_remote)
// Go back to main
repo.run_git(&["checkout", "main"]);
- // Set origin URL to GitLab-style
- repo.run_git(&[
- "remote",
- "set-url",
- "origin",
- "https://gitlab.com/owner/test-repo.git",
- ]);
+ prepare_gitlab_conflicting_fork_ref(&repo);
- // Fork MR response for MR 42, but branch tracks MR 99 (error case)
+ // Fork MR response for MR 42, but branch tracks MR 99.
let glab_response = r#"{
"title": "Add feature fix for edge case",
"author": {"username": "contributor"},
@@ -8472,6 +8527,11 @@ fn test_switch_mr_fork_existing_branch_tracks_different(#[from(repo_with_remote)
configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_mr_fork_existing_branch_tracks_different", cmd);
});
+ assert_eq!(
+ repo.git_output(&["config", "branch.group/subgroup/feature-fix.merge"])
+ .trim(),
+ "refs/merge-requests/42/head"
+ );
}
/// Test fork MR checkout when branch exists but has no tracking config
@@ -8481,15 +8541,9 @@ fn test_switch_mr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test
repo.run_git(&["branch", "feature-fix", "main"]);
// No config set - branch exists but doesn't track anything
- // Set origin URL to GitLab-style
- repo.run_git(&[
- "remote",
- "set-url",
- "origin",
- "https://gitlab.com/owner/test-repo.git",
- ]);
+ prepare_gitlab_conflicting_fork_ref(&repo);
- // Fork MR response (project URLs not needed since branch already exists)
+ // The conflicting branch requires source project URLs for its prefix.
let glab_response = r#"{
"title": "Add feature fix for edge case",
"author": {"username": "contributor"},
@@ -8509,6 +8563,11 @@ fn test_switch_mr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test
configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_mr_fork_existing_no_tracking", cmd);
});
+ assert_eq!(
+ repo.git_output(&["config", "branch.group/subgroup/feature-fix.merge"])
+ .trim(),
+ "refs/merge-requests/42/head"
+ );
}
/// Test mr: with unknown glab error (falls through to general error handler)
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
index 20c98d53d..f38d9eb59 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -273,7 +273,7 @@ The pr:<number> / mr:<number> shortcut and the PR/MR's web URL b
Both work anywhere a branch is accepted, including --base. The --create flag cannot be used with a PR/MR reference since the branch already exists.
-If the PR or MR is on a fork, the local branch uses its branch name directly, so git push works normally. A pre-existing local branch with that name tracking something else requires renaming first.
+If the PR or MR is on a fork, the local branch uses its branch name directly, so git push works normally. If a local branch with that name already exists for a different ref, Worktrunk uses a prefixed branch instead. The prefixed branch can fetch the PR or MR but cannot push to the fork.
The --prs flag adds the repository's open PRs (GitHub) or MRs (GitLab) that aren't already in the interactive picker. Selecting one switches to it as pr:<number> / mr:<number> would.
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_branch_tracks_different.snap b/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_branch_tracks_different.snap
index aca8edc5f..4999bed0d 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_branch_tracks_different.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_branch_tracks_different.snap
@@ -54,13 +54,16 @@ info:
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
-success: false
-exit_code: 1
+success: true
+exit_code: 0
----- stdout -----
----- stderr -----
◎ Fetching MR !42...
  Add feature fix for edge case (!42)
  by @contributor · opened · feature-fix · https://gitlab.com/owner/test-repo/-/merge_requests/42
-✗ Branch feature-fix exists but doesn't track MR !42
-↳ To free the name, run git branch -m -- feature-fix feature-fix-old
+▲ Using prefixed branch name group/subgroup/feature-fix due to name conflict
+↳ Push to fork is not supported with prefixed branches; feedback welcome at https://github.com/max-sixty/worktrunk/issues/714
+✓ Created branch group/subgroup/feature-fix (tracking MR !42) and worktree @ _REPO_.group-subgroup-feature-fix
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_no_tracking.snap b/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_no_tracking.snap
index aca8edc5f..4999bed0d 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_no_tracking.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_mr_fork_existing_no_tracking.snap
@@ -54,13 +54,16 @@ info:
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
-success: false
-exit_code: 1
+success: true
+exit_code: 0
----- stdout -----
----- stderr -----
◎ Fetching MR !42...
  Add feature fix for edge case (!42)
  by @contributor · opened · feature-fix · https://gitlab.com/owner/test-repo/-/merge_requests/42
-✗ Branch feature-fix exists but doesn't track MR !42
-↳ To free the name, run git branch -m -- feature-fix feature-fix-old
+▲ Using prefixed branch name group/subgroup/feature-fix due to name conflict
+↳ Push to fork is not supported with prefixed branches; feedback welcome at https://github.com/max-sixty/worktrunk/issues/714
+✓ Created branch group/subgroup/feature-fix (tracking MR !42) and worktree @ _REPO_.group-subgroup-feature-fix
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_fork_conflict.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_fork_conflict.snap
new file mode 100644
index 000000000..e4d873437
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_fork_conflict.snap
@@ -0,0 +1,69 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:42"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_ALLOW_PROTOCOL: file
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_AUTHOR_EMAIL: [email protected]
+ GIT_AUTHOR_NAME: Test User
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_EMAIL: [email protected]
+ GIT_COMMITTER_NAME: Test User
+ GIT_CONFIG_COUNT: "2"
+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
+ GIT_CONFIG_KEY_0: user.useConfigOnly
+ GIT_CONFIG_KEY_1: rerere.enabled
+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
+ GIT_CONFIG_VALUE_0: "true"
+ GIT_CONFIG_VALUE_1: "false"
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #42...
+  Add feature fix for edge case (#42)
+  by @[email protected] · active · feature-fix · https://dev.azure.com/myorg/myproject/_git/test-repo/pullrequest/42
+▲ Using prefixed branch name test-repo-fork/feature-fix due to name conflict
+↳ Push to fork is not supported with prefixed branches; feedback welcome at https://github.com/max-sixty/worktrunk/issues/714
+✓ Created branch test-repo-fork/feature-fix (tracking PR #42) and worktree @ _REPO_.test-repo-fork-feature-fix
+▲ Cannot change directory — shell integration not installed
+↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_fork_missing_url.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_fork_missing_url.snap
new file mode 100644
index 000000000..950c56d5c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_azure_fork_missing_url.snap
@@ -0,0 +1,66 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:42"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_ALLOW_PROTOCOL: file
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_AUTHOR_EMAIL: [email protected]
+ GIT_AUTHOR_NAME: Test User
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_EMAIL: [email protected]
+ GIT_COMMITTER_NAME: Test User
+ GIT_CONFIG_COUNT: "2"
+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
+ GIT_CONFIG_KEY_0: user.useConfigOnly
+ GIT_CONFIG_KEY_1: rerere.enabled
+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
+ GIT_CONFIG_VALUE_0: "true"
+ GIT_CONFIG_VALUE_1: "false"
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #42...
+  Add feature fix for edge case (#42)
+  by @[email protected] · active · feature-fix · https://dev.azure.com/myorg/myproject/_git/test-repo/pullrequest/42
+✗ Branch feature-fix exists but doesn't track PR #42
+↳ To free the name, run git branch -m -- feature-fix feature-fix-old