Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: use prefixed branch name for conflicting fork PR branches (#779)
Maximilian Roosbd4fa4b4a683
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rsindex 506686025..9792950e7 100644--- a/src/commands/worktree/switch.rs+++ b/src/commands/worktree/switch.rs@@ -9,7 +9,7 @@ use color_print::cformat;use dunce::canonicalize;use worktrunk::config::UserConfig;use worktrunk::git::mr_ref;-use worktrunk::git::pr_ref::{self, fork_remote_url};+use worktrunk::git::pr_ref::{self, fork_remote_url, prefixed_local_branch_name};use worktrunk::git::{GitError, RefType, Repository};use worktrunk::styling::{hint_message, info_message, progress_message, suggest_command, warning_message,@@ -60,7 +60,10 @@ fn resolve_pr_ref(// Fork PR: check if branch already exists and is tracking this PRlet local_branch = pr_ref::local_branch_name(&pr_info);- if let Some(tracks_this) = pr_ref::branch_tracks_pr(repo_root, &local_branch, pr_number) {+ // Determine if we need to use a prefixed branch name due to conflicts+ let (final_branch, fork_push_url) = if let Some(tracks_this) =+ pr_ref::branch_tracks_pr(repo_root, &local_branch, pr_number)+ {if tracks_this {crate::output::print(info_message(cformat!("Branch <bold>{local_branch}</> already configured for PR #{pr_number}"@@ -73,16 +76,44 @@ fn resolve_pr_ref(},});} else {- return Err(GitError::BranchTracksDifferentRef {- branch: local_branch,- ref_type: RefType::Pr,- number: pr_number,+ // Branch exists but doesn't track this PR - use prefixed name+ let prefixed = prefixed_local_branch_name(&pr_info);++ // Check if the prefixed branch also exists and tracks this PR+ if let Some(prefixed_tracks) =+ pr_ref::branch_tracks_pr(repo_root, &prefixed, pr_number)+ {+ if prefixed_tracks {+ crate::output::print(info_message(cformat!(+ "Branch <bold>{prefixed}</> already configured for PR #{pr_number}"+ )))?;+ return Ok(ResolvedTarget {+ branch: prefixed,+ method: CreationMethod::Regular {+ create_branch: false,+ base_branch: None,+ },+ });+ }+ // Prefixed branch exists but tracks something else - error+ return Err(GitError::BranchTracksDifferentRef {+ branch: prefixed,+ ref_type: RefType::Pr,+ number: pr_number,+ }+ .into());}- .into());++ // Use prefixed branch name; push won't work (None for fork_push_url)+ (prefixed, None)}- }+ } else {+ // Branch doesn't exist - use unprefixed name with push support+ let fork_push_url =+ fork_remote_url(&pr_info.host, &pr_info.head_owner, &pr_info.head_repo);+ (local_branch, Some(fork_push_url))+ };- // Branch doesn't exist - need fork setup// Resolve the remote now (during planning) to fail early if no matching remote existslet remote = repo.find_remote_for_repo(Some(&pr_info.host), &pr_info.base_owner, &pr_info.base_repo)@@ -96,10 +127,8 @@ fn resolve_pr_ref(}})?;- let fork_push_url = fork_remote_url(&pr_info.host, &pr_info.head_owner, &pr_info.head_repo);-return Ok(ResolvedTarget {- branch: local_branch,+ branch: final_branch,method: CreationMethod::ForkRef {ref_type: RefType::Pr,number: pr_number,@@ -186,6 +215,9 @@ fn resolve_mr_ref(},});} else {+ // TODO: Consider adding prefixed branch support for MRs like we do for PRs.+ // For now, MRs with conflicting branch names return an error.+ // See https://github.com/max-sixty/worktrunk/issues/714 for PR support.return Err(GitError::BranchTracksDifferentRef {branch: local_branch,ref_type: RefType::Mr,@@ -226,7 +258,7 @@ fn resolve_mr_ref(method: CreationMethod::ForkRef {ref_type: RefType::Mr,number: mr_number,- fork_push_url,+ fork_push_url: Some(fork_push_url),ref_url: mr_info.url,remote,},@@ -435,13 +467,14 @@ fn validate_worktree_creation(/// # Arguments////// * `remote_ref` - The ref to track (e.g., "pull/123/head" or "merge-requests/101/head")+/// * `fork_push_url` - URL to push to, or `None` if push isn't supported (prefixed branch)/// * `label` - Human-readable label for error messages (e.g., "PR #123" or "MR !101")fn setup_fork_branch(repo: &Repository,branch: &str,remote: &str,remote_ref: &str,- fork_push_url: &str,+ fork_push_url: Option<&str>,worktree_path: &Path,label: &str,) -> anyhow::Result<()> {@@ -453,15 +486,19 @@ fn setup_fork_branch(// Configure branch tracking for pull and pushlet branch_remote_key = format!("branch.{}.remote", branch);let branch_merge_key = format!("branch.{}.merge", branch);- let branch_push_remote_key = format!("branch.{}.pushRemote", branch);let merge_ref = format!("refs/{}", remote_ref);repo.run_command(&["config", &branch_remote_key, remote]).with_context(|| format!("Failed to configure branch.{}.remote", branch))?;repo.run_command(&["config", &branch_merge_key, &merge_ref]).with_context(|| format!("Failed to configure branch.{}.merge", branch))?;- repo.run_command(&["config", &branch_push_remote_key, fork_push_url])- .with_context(|| format!("Failed to configure branch.{}.pushRemote", branch))?;++ // Only configure pushRemote if we have a fork URL (not using prefixed branch)+ if let Some(url) = fork_push_url {+ let branch_push_remote_key = format!("branch.{}.pushRemote", branch);+ repo.run_command(&["config", &branch_push_remote_key, url])+ .with_context(|| format!("Failed to configure branch.{}.pushRemote", branch))?;+ }// Create worktree (delayed streaming: silent if fast, shows progress if slow)let worktree_path_str = worktree_path.to_string_lossy();@@ -692,7 +729,7 @@ pub fn execute_switch(&branch,remote,&remote_ref,- fork_push_url,+ fork_push_url.as_deref(),&worktree_path,&label,);@@ -703,9 +740,20 @@ pub fn execute_switch(return Err(e);}- crate::output::print(info_message(cformat!(- "Push configured to fork: <bright-black>{fork_push_url}</>"- )))?;+ // Show push configuration or warning about prefixed branch+ if let Some(url) = fork_push_url {+ crate::output::print(info_message(cformat!(+ "Push configured to fork: <bright-black>{url}</>"+ )))?;+ } else {+ // Prefixed branch name due to conflict - push won't work+ crate::output::print(warning_message(cformat!(+ "Using prefixed branch name <bold>{branch}</> due to name conflict"+ )))?;+ crate::output::print(hint_message(+ "Push to fork is not supported with prefixed branches; feedback welcome at https://github.com/max-sixty/worktrunk/issues/714",+ ))?;+ }(false, None, Some(label))}diff --git a/src/commands/worktree/types.rs b/src/commands/worktree/types.rsindex 07448abd2..1653b707c 100644--- a/src/commands/worktree/types.rs+++ b/src/commands/worktree/types.rs@@ -75,8 +75,9 @@ pub enum CreationMethod {ref_type: RefType,/// The PR/MR number.number: u32,- /// URL to push to (the fork's URL).- fork_push_url: String,+ /// URL to push to (the fork's URL). `None` when using a prefixed branch+ /// name (e.g., `contributor/main`) because push won't work.+ fork_push_url: Option<String>,/// Web URL for the PR/MR.ref_url: String,/// Resolved remote name where PR/MR refs live (e.g., "origin", "upstream").diff --git a/src/git/pr_ref.rs b/src/git/pr_ref.rsindex de3141b6e..60684fbee 100644--- a/src/git/pr_ref.rs+++ b/src/git/pr_ref.rs@@ -27,6 +27,7 @@//! - `base.repo.owner.login`, `base.repo.name` — target repo (where PR refs live)//! - `html_url` — PR web URL+use std::io::ErrorKind;use std::path::Path;use anyhow::{Context, bail};@@ -117,11 +118,7 @@ pub fn fetch_pr_info(pr_number: u32, repo_root: &std::path::Path) -> anyhow::ResOk(output) => output,Err(e) => {// Check if gh is not installed (OS error for command not found)- let error_str = e.to_string();- if error_str.contains("No such file")- || error_str.contains("not found")- || error_str.contains("cannot find")- {+ if e.kind() == ErrorKind::NotFound {bail!("GitHub CLI (gh) not installed; install from https://cli.github.com/");}return Err(anyhow::Error::from(e).context("Failed to run gh api"));@@ -244,6 +241,17 @@ pub fn local_branch_name(pr: &PrInfo) -> String {pr.head_ref_name.clone()}+/// Generate a prefixed local branch name for a fork PR when the unprefixed name conflicts.+///+/// Returns `<head_owner>/<head_ref_name>` (e.g., `contributor/main`).+///+/// This is used when the PR's branch name conflicts with an existing local branch.+/// Note: `git push` won't work with this naming because the local and remote+/// branch names don't match. Users must push manually with explicit refspecs.+pub fn prefixed_local_branch_name(pr: &PrInfo) -> String {+ format!("{}/{}", pr.head_owner, pr.head_ref_name)+}+/// Get the git protocol preference from `gh` (GitHub CLI).////// Returns `true` for SSH if `gh config get git_protocol` returns "ssh".@@ -341,6 +349,24 @@ mod tests {assert_eq!(local_branch_name(&pr), "feature-auth");}+ #[test]+ fn test_prefixed_local_branch_name() {+ // When the fork's branch name conflicts with a local branch,+ // we use owner/branch format as a fallback (push won't work)+ let pr = PrInfo {+ number: 101,+ head_ref_name: "main".to_string(),+ head_owner: "contributor".to_string(),+ head_repo: "repo".to_string(),+ base_owner: "owner".to_string(),+ base_repo: "repo".to_string(),+ is_cross_repository: true,+ host: "github.com".to_string(),+ url: "https://github.com/owner/repo/pull/101".to_string(),+ };+ assert_eq!(prefixed_local_branch_name(&pr), "contributor/main");+ }+#[test]fn test_fork_remote_url() {// Protocol depends on `gh config get git_protocol`diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex 17ac67604..940cf935a 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -1753,11 +1753,27 @@ fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo});}-/// Test fork PR where branch already exists but tracks different PR (should error)+/// Test fork PR where branch already exists but tracks different PR+/// Uses prefixed branch name `contributor/feature-fix` to avoid conflict#[rstest]fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: TestRepo) {+ // Create a PR ref 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"])+ .output()+ .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"]);+// Create the branch with tracking config for a DIFFERENT PR- // Branch name matches headRefName (no owner prefix) so git push workslet branch_name = "feature-fix";repo.run_git(&["branch", branch_name, "main"]);repo.run_git(&[@@ -1771,6 +1787,29 @@ fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: Tes"refs/pull/99/head", // Different PR!]);+ // Set up GitHub URL and redirect (like test_switch_pr_fork)+ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .output()+ .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",+ ]);+// gh api repos/{owner}/{repo}/pulls/{number} formatlet gh_response = r#"{"head": {@@ -1795,14 +1834,53 @@ fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: Tes}/// Test fork PR where branch exists but has no tracking config+/// Uses prefixed branch name `contributor/feature-fix` to avoid conflict#[rstest]fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: TestRepo) {+ // Create a PR ref 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"])+ .output()+ .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"]);+// Create the branch without any tracking config- // Branch name matches headRefName (no owner prefix) so git push workslet branch_name = "feature-fix";repo.run_git(&["branch", branch_name, "main"]);// No config set - branch exists but doesn't track anything+ // Set up GitHub URL and redirect (like test_switch_pr_fork)+ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .output()+ .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",+ ]);+// gh api repos/{owner}/{repo}/pulls/{number} formatlet gh_response = r#"{"head": {@@ -1826,6 +1904,151 @@ fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test});}+/// Test fork PR where prefixed branch already exists and tracks the same PR+/// Should reuse the existing prefixed branch+#[rstest]+fn test_switch_pr_fork_prefixed_exists_same_pr(#[from(repo_with_remote)] repo: TestRepo) {+ // Create the unprefixed branch (simulating existing local branch)+ repo.run_git(&["branch", "feature-fix", "main"]);++ // Create the prefixed branch with tracking config for THIS PR+ let prefixed_branch = "contributor/feature-fix";+ repo.run_git(&["branch", prefixed_branch, "main"]);+ repo.run_git(&[+ "config",+ &format!("branch.{}.remote", prefixed_branch),+ "origin",+ ]);+ repo.run_git(&[+ "config",+ &format!("branch.{}.merge", prefixed_branch),+ "refs/pull/42/head", // Same PR+ ]);++ // Create the worktree for the prefixed branch+ // Use "repo." prefix to match the test repo's directory naming convention+ let worktree_path = repo+ .root_path()+ .parent()+ .unwrap()+ .join("repo.contributor-feature-fix");+ repo.run_git(&[+ "worktree",+ "add",+ worktree_path.to_str().unwrap(),+ prefixed_branch,+ ]);++ // Set up GitHub URL+ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .output()+ .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",+ ]);++ let gh_response = r#"{+ "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 settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);+ configure_mock_gh_env(&mut cmd, &mock_bin);+ assert_cmd_snapshot!("switch_pr_fork_prefixed_exists_same_pr", cmd);+ });+}++/// Test fork PR where prefixed branch exists but tracks different PR (should error)+#[rstest]+fn test_switch_pr_fork_prefixed_exists_different_pr(#[from(repo_with_remote)] repo: TestRepo) {+ // Create the unprefixed branch (simulating existing local branch)+ repo.run_git(&["branch", "feature-fix", "main"]);++ // Create the prefixed branch with tracking config for a DIFFERENT PR+ let prefixed_branch = "contributor/feature-fix";+ repo.run_git(&["branch", prefixed_branch, "main"]);+ repo.run_git(&[+ "config",+ &format!("branch.{}.remote", prefixed_branch),+ "origin",+ ]);+ repo.run_git(&[+ "config",+ &format!("branch.{}.merge", prefixed_branch),+ "refs/pull/99/head", // Different PR!+ ]);++ // Set up GitHub URL+ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .output()+ .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",+ ]);++ let gh_response = r#"{+ "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 settings = setup_snapshot_settings(&repo);+ settings.bind(|| {+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);+ configure_mock_gh_env(&mut cmd, &mock_bin);+ assert_cmd_snapshot!("switch_pr_fork_prefixed_exists_different_pr", cmd);+ });+}+/// Test pr: when gh is not authenticated#[rstest]fn test_switch_pr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {@@ -2503,7 +2726,10 @@ fn test_switch_mr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {////// Creates a temporary directory with a symlink to git, excluding gh/glab./// Returns the path to use as PATH.-fn setup_minimal_bin_without_cli(repo: &TestRepo) -> std::path::PathBuf {+/// Create a minimal bin directory with only git, excluding gh/glab.+/// Returns None on Windows where this approach doesn't work reliably.+#[cfg(unix)]+fn setup_minimal_bin_without_cli(repo: &TestRepo) -> Option<std::path::PathBuf> {let minimal_bin = repo.root_path().join("minimal-bin");fs::create_dir_all(&minimal_bin).unwrap();@@ -2511,12 +2737,15 @@ fn setup_minimal_bin_without_cli(repo: &TestRepo) -> std::path::PathBuf {let git_path = which::which("git").expect("git must be installed to run tests");// Symlink git into our minimal bin directory- #[cfg(unix)]std::os::unix::fs::symlink(&git_path, minimal_bin.join("git")).unwrap();- #[cfg(windows)]- std::os::windows::fs::symlink_file(&git_path, minimal_bin.join("git.exe")).unwrap();+ Some(minimal_bin)+}- minimal_bin+/// On Windows, git requires its entire installation directory to function,+/// so we can't easily create a minimal PATH with just git. Skip these tests.+#[cfg(windows)]+fn setup_minimal_bin_without_cli(_repo: &TestRepo) -> Option<std::path::PathBuf> {+ None}/// Configure PATH to exclude gh/glab, keeping only git.@@ -2529,7 +2758,11 @@ fn configure_cli_not_installed_env(cmd: &mut std::process::Command, minimal_bin:/// Test pr: when gh CLI is not installed#[rstest]fn test_switch_pr_gh_not_installed(#[from(repo_with_remote)] repo: TestRepo) {- let minimal_bin = setup_minimal_bin_without_cli(&repo);+ let Some(minimal_bin) = setup_minimal_bin_without_cli(&repo) else {+ // Symlinks not available (Windows without Developer Mode)+ eprintln!("Skipping test: symlinks not available on this system");+ return;+ };let settings = setup_snapshot_settings(&repo);settings.bind(|| {@@ -2542,7 +2775,11 @@ fn test_switch_pr_gh_not_installed(#[from(repo_with_remote)] repo: TestRepo) {/// Test mr: when glab CLI is not installed#[rstest]fn test_switch_mr_glab_not_installed(#[from(repo_with_remote)] repo: TestRepo) {- let minimal_bin = setup_minimal_bin_without_cli(&repo);+ let Some(minimal_bin) = setup_minimal_bin_without_cli(&repo) else {+ // Symlinks not available (Windows without Developer Mode)+ eprintln!("Skipping test: symlinks not available on this system");+ return;+ };let settings = setup_snapshot_settings(&repo);settings.bind(|| {diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_different_pr.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_different_pr.snapindex 296cb1052..55d435831 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_different_pr.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_different_pr.snap@@ -30,11 +30,14 @@ info:WT_TEST_EPOCH: "1735776000"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"----success: false-exit_code: 1+success: true+exit_code: 0----- stdout ---------- stderr -----[36m◎[39m [36mFetching PR #42...[39m-[31m✗[39m [31mBranch [1mfeature-fix[22m exists but doesn't track PR #42[39m-[2m↳[22m [2mTo free the name, run [90mgit branch -m -- feature-fix feature-fix-old[39m[22m+[33m▲[39m [33mUsing prefixed branch name [1mcontributor/feature-fix[22m due to name conflict[39m+[2m↳[22m [2mPush to fork is not supported with prefixed branches; feedback welcome at https://github.com/max-sixty/worktrunk/issues/714[22m+[32m✓[39m [32mCreated branch [1mcontributor/feature-fix[22m (tracking [1mPR #42[22m) and worktree @ [1m_REPO_.contributor-feature-fix[22m[39m+[33m▲[39m [33mCannot change directory — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_no_tracking.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_no_tracking.snapindex 296cb1052..55d435831 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_no_tracking.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_no_tracking.snap@@ -30,11 +30,14 @@ info:WT_TEST_EPOCH: "1735776000"XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"----success: false-exit_code: 1+success: true+exit_code: 0----- stdout ---------- stderr -----[36m◎[39m [36mFetching PR #42...[39m-[31m✗[39m [31mBranch [1mfeature-fix[22m exists but doesn't track PR #42[39m-[2m↳[22m [2mTo free the name, run [90mgit branch -m -- feature-fix feature-fix-old[39m[22m+[33m▲[39m [33mUsing prefixed branch name [1mcontributor/feature-fix[22m due to name conflict[39m+[2m↳[22m [2mPush to fork is not supported with prefixed branches; feedback welcome at https://github.com/max-sixty/worktrunk/issues/714[22m+[32m✓[39m [32mCreated branch [1mcontributor/feature-fix[22m (tracking [1mPR #42[22m) and worktree @ [1m_REPO_.contributor-feature-fix[22m[39m+[33m▲[39m [33mCannot change directory — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_prefixed_exists_different_pr.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_prefixed_exists_different_pr.snapnew file mode 100644index 000000000..e7f47701b--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_prefixed_exists_different_pr.snap@@ -0,0 +1,40 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "pr:42"+ 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]"+ PATH: "[PATH]"+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching PR #42...[39m+[31m✗[39m [31mBranch [1mcontributor/feature-fix[22m exists but doesn't track PR #42[39m+[2m↳[22m [2mTo free the name, run [90mgit branch -m -- contributor/feature-fix contributor/feature-fix-old[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_prefixed_exists_same_pr.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_prefixed_exists_same_pr.snapnew file mode 100644index 000000000..18236f548--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_prefixed_exists_same_pr.snap@@ -0,0 +1,41 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "pr:42"+ 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]"+ PATH: "[PATH]"+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching PR #42...[39m+[2m○[22m Branch [1mcontributor/feature-fix[22m already configured for PR #42+[33m▲[39m [33mWorktree for [1mcontributor/feature-fix[22m @ [1m_REPO_.contributor-feature-fix[22m, but cannot change directory — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m