Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: fetch fork PRs from correct remote (#704)
Maximilian Roos7b84dc0aae80
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rsindex aa661e151..508155edb 100644--- a/src/commands/worktree/switch.rs+++ b/src/commands/worktree/switch.rs@@ -8,6 +8,7 @@ use anyhow::Context;use color_print::cformat;use dunce::canonicalize;use worktrunk::config::WorktrunkConfig;+use worktrunk::git::pr_ref::fork_remote_url;use worktrunk::git::{GitError, Repository};use worktrunk::styling::{hint_message, info_message, progress_message, suggest_command, warning_message,@@ -47,11 +48,8 @@ fn resolve_switch_target(return Err(GitError::PrBaseConflict { pr_number }.into());}- // Fetch PR info (network call)- let remote = repo.primary_remote()?;- crate::output::print(progress_message(cformat!(- "Fetching PR #{pr_number} from <bold>{remote}</>..."- )))?;+ // Fetch PR info (network call via gh CLI)+ crate::output::print(progress_message(cformat!("Fetching PR #{pr_number}...")))?;let repo_root = repo.repo_path()?;let pr_info = fetch_pr_info(pr_number, &repo_root)?;@@ -98,6 +96,8 @@ fn resolve_switch_target(pr_number,fork_push_url,pr_url: pr_info.url,+ base_owner: pr_info.base_owner,+ base_repo: pr_info.base_repo,},});} else {@@ -488,9 +488,25 @@ pub fn execute_switch(pr_number,fork_push_url,pr_url: _,+ base_owner,+ base_repo,} => {let pr_ref = format!("pull/{}/head", pr_number);- let remote = repo.primary_remote()?;++ // Find the remote that points to the base repo (where PR refs live)+ let remote = repo+ .find_remote_for_repo(base_owner, base_repo)+ .ok_or_else(|| {+ // Construct suggested URL using primary remote's protocol/host+ let reference_url = repo.primary_remote_url().unwrap_or_default();+ let suggested_url =+ fork_remote_url(base_owner, base_repo, &reference_url);+ GitError::NoRemoteForRepo {+ owner: base_owner.clone(),+ repo: base_repo.clone(),+ suggested_url,+ }+ })?;// Fetch the PR head (progress already shown during planning)repo.run_command(&["fetch", &remote, &pr_ref])diff --git a/src/commands/worktree/types.rs b/src/commands/worktree/types.rsindex f5485e405..9b16b1d08 100644--- a/src/commands/worktree/types.rs+++ b/src/commands/worktree/types.rs@@ -68,6 +68,10 @@ pub enum CreationMethod {pr_number: u32,fork_push_url: String,pr_url: String,+ /// Owner of the base repository (where the PR was opened)+ base_owner: String,+ /// Name of the base repository+ base_repo: String,},}diff --git a/src/git/error.rs b/src/git/error.rsindex 9fd778e58..3a6ab2b71 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -161,6 +161,20 @@ pub enum GitError {branch: String,pr_number: u32,},+ /// No remote found for the repository where the PR lives+ NoRemoteForRepo {+ owner: String,+ repo: String,+ /// Suggested URL to add as a remote (derived from primary remote's protocol/host)+ suggested_url: String,+ },+ /// GitHub CLI API command failed with unrecognized error+ GhApiError {+ /// Short description of what failed+ message: String,+ /// Full stderr output for debugging+ stderr: String,+ },Other {message: String,},@@ -626,6 +640,25 @@ impl std::fmt::Display for GitError {)}+ GitError::NoRemoteForRepo {+ owner,+ repo,+ suggested_url,+ } => {+ write!(+ f,+ "{}\n{}",+ error_message(cformat!("No remote found for <bold>{owner}/{repo}</>")),+ hint_message(cformat!(+ "Add the remote: <bright-black>git remote add upstream {suggested_url}</>"+ ))+ )+ }++ GitError::GhApiError { message, stderr } => {+ write!(f, "{}", format_error_block(error_message(message), stderr))+ }+GitError::Other { message } => {write!(f, "{}", error_message(message))}@@ -1196,6 +1229,34 @@ mod tests {assert!(display.contains("Commit or stash"));}+ #[test]+ fn test_git_error_gh_api_error() {+ let err = GitError::GhApiError {+ message: "gh api failed for PR #42".into(),+ stderr: "error: unexpected response\ncode: 500".into(),+ };+ let display = err.to_string();+ // Verify header and gutter content are present+ assert!(display.contains("gh api failed"));+ assert!(display.contains("unexpected response"));+ assert!(display.contains("500"));+ }++ #[test]+ fn test_git_error_no_remote_for_repo() {+ let err = GitError::NoRemoteForRepo {+ owner: "upstream-owner".into(),+ repo: "upstream-repo".into(),+ suggested_url: "https://github.com/upstream-owner/upstream-repo.git".into(),+ };+ let display = err.to_string();+ // Verify error message and hint+ assert!(display.contains("No remote found"));+ assert!(display.contains("upstream-owner/upstream-repo"));+ assert!(display.contains("git remote add upstream"));+ assert!(display.contains("https://github.com/upstream-owner/upstream-repo.git"));+ }+#[test]fn test_hook_error_with_hint_source() {use crate::HookType;diff --git a/src/git/pr_ref.rs b/src/git/pr_ref.rsindex 33342317e..984556705 100644--- a/src/git/pr_ref.rs+++ b/src/git/pr_ref.rs@@ -29,16 +29,17 @@//! │//! ▼//! ┌─────────────────────────────────────────────────────────┐-//! │ gh pr view 101 --json headRefName,headRepository, │-//! │ headRepositoryOwner,isCrossRepository,url │+//! │ gh api repos/{owner}/{repo}/pulls/101 │+//! │ → head.ref, head.repo, base.repo, html_url │//! └─────────────────────────────────────────────────────────┘//! │-//! ├─── isCrossRepository == false ───▶ Same-repo PR+//! ├─── base.repo == head.repo ───▶ Same-repo PR//! │ │-//! │ └─▶ Branch exists in origin, use directly+//! │ └─▶ Branch exists in primary remote, use directly//! │-//! └─── isCrossRepository == true ───▶ Fork PR+//! └─── base.repo != head.repo ───▶ Fork PR//! │+//! ├─▶ Find remote for base.repo (where PR refs live)//! └─▶ Set up push to fork URL//! ```//!@@ -48,19 +49,19 @@//!//! # Same-Repo PRs//!-//! When `isCrossRepository` is `false`, the PR's branch exists in `origin`:+//! When `base.repo == head.repo`, the PR's branch exists in the primary remote://!-//! 1. Resolve `headRefName` (e.g., `"feature-auth"`)+//! 1. Resolve `head.ref` (e.g., `"feature-auth"`)//! 2. Check if worktree exists for that branch → switch to it//! 3. Otherwise, create worktree for the branch (DWIM from remote)-//! 4. Pushing works normally: `git push origin feature-auth`+//! 4. Pushing works normally: `git push`//!//! This is equivalent to `wt switch feature-auth` — the `pr:` syntax is just//! a convenience for looking up the branch name.//!//! # Fork PRs//!-//! When `isCrossRepository` is `true`, the branch exists in a fork, not `origin`.+//! When `base.repo != head.repo`, the branch exists in a fork, not the base repo.//!//! ## The Problem: PR Refs Are Read-Only//!@@ -86,37 +87,41 @@//! named remote. This means we can set up push tracking without adding remotes://!//! ```text-//! branch.feature.remote = origin-//! branch.feature.merge = refs/pull/101/head-//! branch.feature.pushRemote = [email protected]:contributor/repo.git+//! branch.contributor/feature.remote = upstream+//! branch.contributor/feature.merge = refs/pull/101/head+//! branch.contributor/feature.pushRemote = [email protected]:contributor/repo.git//! ```//!//! This configuration gives us:-//! - `git pull` fetches from origin's PR ref (stays up to date with PR)+//! - `git pull` fetches from the base repo's PR ref (stays up to date with PR)//! - `git push` pushes to the fork URL (updates the PR)//! - No stray remotes cluttering `git remote -v`//!//! ## Checkout Flow (Fork PRs)//!//! ```text-//! 1. Get PR metadata from gh+//! 1. Get PR metadata from gh api//! │//! ▼-//! 2. Fetch PR head from origin-//! git fetch origin pull/101/head+//! 2. Find remote for base repo (where PR refs live)+//! e.g., upstream → github.com/owner/repo//! │//! ▼-//! 3. Create local branch from FETCH_HEAD+//! 3. Fetch PR head from that remote+//! git fetch upstream pull/101/head+//! │+//! ▼+//! 4. Create local branch from FETCH_HEAD//! git branch <local-branch> FETCH_HEAD//! │//! ▼-//! 4. Configure branch tracking-//! git config branch.<local-branch>.remote origin+//! 5. Configure branch tracking+//! git config branch.<local-branch>.remote upstream//! git config branch.<local-branch>.merge refs/pull/101/head//! git config branch.<local-branch>.pushRemote <fork-url>//! │//! ▼-//! 5. Create worktree for the branch+//! 6. Create worktree for the branch//! ```//!//! ## Local Branch Naming@@ -163,8 +168,8 @@//! ↳ Run gh repo set-default --view to check which repo is being queried//! ```//!-//! This often happens when `origin` points to a fork but `gh` hasn't been-//! configured to look at the upstream repo. Fix with `gh repo set-default`.+//! This often happens when the primary remote points to a fork but `gh` hasn't+//! been configured to look at the upstream repo. Fix with `gh repo set-default`.//!//! ## gh Not Authenticated//!@@ -227,9 +232,9 @@//!//! ## Repository Resolution//!-//! `gh pr view` needs to know which GitHub repo to query. For fork workflows-//! where `origin` points to a fork, `gh` needs to know to look at the parent-//! repo for PRs.+//! `gh api` needs to know which GitHub repo to query. For fork workflows+//! where the primary remote points to a fork, `gh` needs to know to look at+//! the parent repo for PRs.//!//! The `gh` CLI handles this via `gh repo set-default`://!@@ -247,12 +252,12 @@//! **Diagnostics:** `wt config show` should display the resolved repo so users//! understand which repo PR lookups will query.//!-//! ## Required gh Fields+//! ## GitHub API Fields//!-//! ```bash-//! gh pr view <number> --json \-//! headRefName,headRepository,headRepositoryOwner,isCrossRepository,url-//! ```+//! We use `gh api repos/{owner}/{repo}/pulls/<number>` which returns:+//! - `head.ref`, `head.repo.owner.login`, `head.repo.name` — PR branch info+//! - `base.repo.owner.login`, `base.repo.name` — target repo (where PR refs live)+//! - `html_url` — PR web URL//!//! ## Remote URL Construction//!@@ -266,7 +271,7 @@//! https://github.com/<owner>/<repo>.git//! ```//!-//! We match the protocol of the existing `origin` remote to be consistent+//! We match the protocol of the existing primary remote to be consistent//! with the user's authentication setup.//!//! ## Caching@@ -280,7 +285,7 @@//!//! - PR number parsing from `pr:<number>` syntax//! - Local branch name generation-//! - URL construction matching origin protocol+//! - URL construction matching primary remote protocol//!//! ## Integration Tests (with mock gh)//!@@ -298,6 +303,8 @@use anyhow::{Context, bail};use serde::Deserialize;+use super::GitRemoteUrl;+use super::error::GitError;use crate::shell_exec::Cmd;/// Information about a PR retrieved from GitHub.@@ -311,26 +318,36 @@ pub struct PrInfo {pub head_owner: String,/// The name of the head repository.pub head_repo: String,+ /// The owner of the base repository (where the PR was opened).+ pub base_owner: String,+ /// The name of the base repository.+ pub base_repo: String,/// Whether this is a cross-repository (fork) PR.pub is_cross_repository: bool,/// The PR's web URL.pub url: String,}-/// Raw JSON response from `gh pr view`.+/// Raw JSON response from `gh api repos/{owner}/{repo}/pulls/{number}`.+#[derive(Debug, Deserialize)]+struct GhApiPrResponse {+ head: GhPrRef,+ base: GhPrRef,+ html_url: String,+}+#[derive(Debug, Deserialize)]-#[serde(rename_all = "camelCase")]-struct GhPrResponse {- head_ref_name: String,- head_repository: GhRepository,- head_repository_owner: GhOwner,- is_cross_repository: bool,- url: String,+struct GhPrRef {+ #[serde(rename = "ref")]+ ref_name: String,+ /// The repository for this ref. Can be `null` if the fork was deleted.+ repo: Option<GhPrRepo>,}#[derive(Debug, Deserialize)]-struct GhRepository {+struct GhPrRepo {name: String,+ owner: GhOwner,}#[derive(Debug, Deserialize)]@@ -348,6 +365,9 @@ pub fn parse_pr_ref(input: &str) -> Option<u32> {/// Fetch PR information from GitHub using the `gh` CLI.///+/// Uses `gh api` to query the GitHub API directly, which provides+/// both head and base repository information.+////// # Errors////// Returns an error if:@@ -355,14 +375,11 @@ pub fn parse_pr_ref(input: &str) -> Option<u32> {/// - The PR doesn't exist/// - The JSON response is malformedpub fn fetch_pr_info(pr_number: u32, repo_root: &std::path::Path) -> anyhow::Result<PrInfo> {+ // Use gh api with {owner}/{repo} placeholders - gh resolves these from repo context+ let api_path = format!("repos/{{owner}}/{{repo}}/pulls/{}", pr_number);+let output = match Cmd::new("gh")- .args([- "pr",- "view",- &pr_number.to_string(),- "--json",- "headRefName,headRepository,headRepositoryOwner,isCrossRepository,url",- ])+ .args(["api", &api_path]).current_dir(repo_root).env("GH_PROMPT_DISABLED", "1").run()@@ -377,7 +394,7 @@ pub fn fetch_pr_info(pr_number: u32, repo_root: &std::path::Path) -> anyhow::Res{bail!("GitHub CLI (gh) not installed; install from https://cli.github.com/");}- return Err(anyhow::Error::from(e).context("Failed to run gh pr view"));+ return Err(anyhow::Error::from(e).context("Failed to run gh api"));}};@@ -385,11 +402,8 @@ pub fn fetch_pr_info(pr_number: u32, repo_root: &std::path::Path) -> anyhow::Reslet stderr = String::from_utf8_lossy(&output.stderr);let stderr_lower = stderr.to_lowercase();- // PR not found (various phrasings across gh versions)- if stderr_lower.contains("could not resolve")- || stderr_lower.contains("not found")- || stderr_lower.contains("no pull request")- {+ // PR not found (HTTP 404)+ if stderr_lower.contains("not found") || stderr_lower.contains("404") {bail!("PR #{} not found", pr_number);}@@ -398,12 +412,16 @@ pub fn fetch_pr_info(pr_number: u32, repo_root: &std::path::Path) -> anyhow::Res|| stderr_lower.contains("logged in")|| stderr_lower.contains("auth login")|| stderr_lower.contains("not logged")+ || stderr_lower.contains("401"){bail!("GitHub CLI not authenticated; run gh auth login");}// Rate limiting- if stderr_lower.contains("rate limit") || stderr_lower.contains("api rate") {+ if stderr_lower.contains("rate limit")+ || stderr_lower.contains("api rate")+ || stderr_lower.contains("403")+ {bail!("GitHub API rate limit exceeded; wait a few minutes and retry");}@@ -415,32 +433,61 @@ pub fn fetch_pr_info(pr_number: u32, repo_root: &std::path::Path) -> anyhow::Resbail!("Network error connecting to GitHub; check your internet connection");}- bail!("gh pr view failed: {}", stderr.trim());+ // Unknown error - show full output in gutter for debugging+ return Err(GitError::GhApiError {+ message: format!("gh api failed for PR #{}", pr_number),+ stderr: stderr.trim().to_string(),+ }+ .into());}- let response: GhPrResponse = serde_json::from_slice(&output.stdout).with_context(|| {+ let response: GhApiPrResponse = serde_json::from_slice(&output.stdout).with_context(|| {format!(- "Failed to parse gh pr view JSON for PR #{}. \- This may indicate a gh version incompatibility or GitHub API change.",+ "Failed to parse GitHub API response for PR #{}. \+ This may indicate a GitHub API change.",pr_number)})?;// Validate required fields are not empty- if response.head_ref_name.is_empty() {+ if response.head.ref_name.is_empty() {bail!("PR #{} has empty branch name; the PR may be in an invalid state",pr_number);}+ // Extract base repo (should always be present - the PR is opened against an existing repo)+ let base_repo = response.base.repo.context(+ "PR base repository is null; this is unexpected and may indicate a GitHub API issue",+ )?;++ // Extract head repo (can be null if the fork was deleted)+ let head_repo = response.head.repo.ok_or_else(|| {+ anyhow::anyhow!(+ "PR #{} source repository was deleted. \+ The fork that this PR was opened from no longer exists, \+ so the branch cannot be checked out.",+ pr_number+ )+ })?;++ // Compute is_cross_repository by comparing base and head repos (case-insensitive)+ let is_cross_repository = !base_repo+ .owner+ .login+ .eq_ignore_ascii_case(&head_repo.owner.login)+ || !base_repo.name.eq_ignore_ascii_case(&head_repo.name);+Ok(PrInfo {number: pr_number,- head_ref_name: response.head_ref_name,- head_owner: response.head_repository_owner.login,- head_repo: response.head_repository.name,- is_cross_repository: response.is_cross_repository,- url: response.url,+ head_ref_name: response.head.ref_name,+ head_owner: head_repo.owner.login,+ head_repo: head_repo.name,+ base_owner: base_repo.owner.login,+ base_repo: base_repo.name,+ is_cross_repository,+ url: response.html_url,})}@@ -455,15 +502,20 @@ pub fn local_branch_name(pr: &PrInfo) -> String {pr.head_ref_name.clone()}-/// Construct the remote URL for a fork, matching the protocol of the primary remote.+/// Construct the remote URL for a fork, matching the protocol and host of the reference URL.///-/// If remote uses SSH (`[email protected]:`), returns SSH URL.-/// If remote uses HTTPS (`https://github.com/`), returns HTTPS URL.-pub fn fork_remote_url(owner: &str, repo: &str, remote_url: &str) -> String {- if remote_url.starts_with("git@") || remote_url.contains("ssh://") {- format!("[email protected]:{}/{}.git", owner, repo)+/// If reference uses SSH (`git@host:`), returns SSH URL.+/// If reference uses HTTPS (`https://host/`), returns HTTPS URL.+/// Falls back to `github.com` if the reference URL cannot be parsed.+pub fn fork_remote_url(owner: &str, repo: &str, reference_url: &str) -> String {+ let host = GitRemoteUrl::parse(reference_url)+ .map(|u| u.host().to_string())+ .unwrap_or_else(|| "github.com".to_string());++ if reference_url.starts_with("git@") || reference_url.contains("ssh://") {+ format!("git@{}:{}/{}.git", host, owner, repo)} else {- format!("https://github.com/{}/{}.git", owner, repo)+ format!("https://{}/{}/{}.git", host, owner, repo)}}@@ -532,6 +584,8 @@ mod tests {head_ref_name: "feature-auth".to_string(),head_owner: "owner".to_string(),head_repo: "repo".to_string(),+ base_owner: "owner".to_string(),+ base_repo: "repo".to_string(),is_cross_repository: false,url: "https://github.com/owner/repo/pull/101".to_string(),};@@ -547,6 +601,8 @@ mod tests {head_ref_name: "feature-auth".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,url: "https://github.com/owner/repo/pull/101".to_string(),};@@ -564,4 +620,24 @@ mod tests {let url = fork_remote_url("contributor", "repo", "https://github.com/owner/repo.git");assert_eq!(url, "https://github.com/contributor/repo.git");}++ #[test]+ fn test_fork_remote_url_github_enterprise_ssh() {+ let url = fork_remote_url(+ "contributor",+ "repo",+ "[email protected]:owner/repo.git",+ );+ assert_eq!(url, "[email protected]:contributor/repo.git");+ }++ #[test]+ fn test_fork_remote_url_github_enterprise_https() {+ let url = fork_remote_url(+ "contributor",+ "repo",+ "https://github.example.com/owner/repo.git",+ );+ assert_eq!(url, "https://github.example.com/contributor/repo.git");+ }}diff --git a/src/git/repository/remotes.rs b/src/git/repository/remotes.rsindex fa330ee03..49897cc3f 100644--- a/src/git/repository/remotes.rs+++ b/src/git/repository/remotes.rs@@ -65,6 +65,34 @@ impl Repository {.filter(|url| !url.is_empty())}+ /// Find a remote that points to a specific owner/repo.+ ///+ /// Searches all configured remotes and returns the name of the first one+ /// whose URL matches the given owner and repo (case-insensitive for owner).+ ///+ /// Returns `None` if no matching remote is found.+ pub fn find_remote_for_repo(&self, owner: &str, repo: &str) -> Option<String> {+ // Get all remotes with URLs+ let output = self+ .run_command(&["config", "--get-regexp", r"remote\..+\.url"])+ .ok()?;++ for line in output.lines() {+ // Parse "remote.<name>.url <value>" format+ if let Some(rest) = line.strip_prefix("remote.")+ && let Some((name, url)) = rest.split_once(".url ")+ && let Some(parsed) = GitRemoteUrl::parse(url)+ // Case-insensitive comparison (GitHub owner/repo names are case-insensitive)+ && parsed.owner().eq_ignore_ascii_case(owner)+ && parsed.repo().eq_ignore_ascii_case(repo)+ {+ return Some(name.to_string());+ }+ }++ None+ }+/// Get the URL for the primary remote, if configured.////// Result is cached in the repository's shared cache (same for all clones).diff --git a/src/git/url.rs b/src/git/url.rsindex 500fb3d87..0017a9375 100644--- a/src/git/url.rs+++ b/src/git/url.rs@@ -83,6 +83,11 @@ impl GitRemoteUrl {})}+ /// The host (e.g., "github.com", "gitlab.example.com").+ pub fn host(&self) -> &str {+ &self.host+ }+/// The repository owner or organization (e.g., "owner", "company-org").pub fn owner(&self) -> &str {&self.ownerdiff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex 9975976e9..932e04f73 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -1266,6 +1266,11 @@ fn test_switch_create_no_hint_with_custom_worktree_path(repo: TestRepo) {use crate::common::mock_commands::{MockConfig, MockResponse, copy_mock_binary};/// Helper to set up mock gh for PR tests with custom PR response.+///+/// The response should be in `gh api repos/{owner}/{repo}/pulls/{number}` format:+/// - `head.ref`, `head.repo.owner.login`, `head.repo.name`+/// - `base.repo.owner.login`, `base.repo.name`+/// - `html_url`fn setup_mock_gh_for_pr(repo: &TestRepo, gh_response: Option<&str>) -> std::path::PathBuf {let mock_bin = repo.root_path().join("mock-bin");fs::create_dir_all(&mock_bin).unwrap();@@ -1279,7 +1284,7 @@ fn setup_mock_gh_for_pr(repo: &TestRepo, gh_response: Option<&str>) -> std::pathMockConfig::new("gh").version("gh version 2.0.0 (mock)")- .command("pr", MockResponse::file("pr_response.json"))+ .command("api", MockResponse::file("pr_response.json")).command("_default", MockResponse::exit(1)).write(&mock_bin);}@@ -1321,18 +1326,23 @@ fn test_switch_pr_create_conflict(repo: TestRepo) {});}-/// Test same-repo PR checkout (isCrossRepository: false)+/// Test same-repo PR checkout (base.repo == head.repo)#[rstest]fn test_switch_pr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {// Create a feature branch and push itrepo.add_worktree("feature-auth");+ // gh api repos/{owner}/{repo}/pulls/{number} formatlet gh_response = r#"{- "headRefName": "feature-auth",- "headRepository": {"name": "test-repo"},- "headRepositoryOwner": {"login": "owner"},- "isCrossRepository": false,- "url": "https://github.com/owner/test-repo/pull/101"+ "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));@@ -1345,7 +1355,7 @@ fn test_switch_pr_same_repo(#[from(repo_with_remote)] mut repo: TestRepo) {});}-/// Test fork PR checkout (isCrossRepository: true)+/// Test fork PR checkout (base.repo != head.repo)#[rstest]fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {// Create a PR ref on the remote that can be fetched@@ -1371,12 +1381,49 @@ fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {// Go back to mainrepo.run_git(&["checkout", "main"]);+ // Get the bare remote's actual URL before we modify origin+ let bare_url = String::from_utf8_lossy(+ &repo+ .git_command()+ .args(["config", "remote.origin.url"])+ .output()+ .unwrap()+ .stdout,+ )+ .trim()+ .to_string();++ // Set origin URL to GitHub-style so find_remote_for_repo() can match owner/test-repo+ repo.run_git(&[+ "remote",+ "set-url",+ "origin",+ "https://github.com/owner/test-repo.git",+ ]);++ // Configure git to redirect github.com URLs to the local bare remote.+ // This is necessary because:+ // 1. origin must have a GitHub URL for find_remote_for_repo() to match owner/repo+ // 2. But we need git fetch to actually succeed using the local bare remote+ // Git's url.<base>.insteadOf transparently rewrites the fetch URL.+ repo.run_git(&[+ "config",+ &format!("url.{}.insteadOf", bare_url),+ "https://github.com/owner/test-repo.git",+ ]);++ // gh api repos/{owner}/{repo}/pulls/{number} format+ // head.repo is the fork (contributor/test-repo), base.repo is the upstream (owner/test-repo)let gh_response = r#"{- "headRefName": "feature-fix",- "headRepository": {"name": "test-repo"},- "headRepositoryOwner": {"login": "contributor"},- "isCrossRepository": true,- "url": "https://github.com/owner/test-repo/pull/42"+ "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));@@ -1389,6 +1436,48 @@ fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {});}+/// Test fork PR when origin points to fork (no remote for base repo)+///+/// User scenario:+/// 1. User forked upstream-owner/repo to contributor/repo+/// 2. User cloned their fork, so origin points to contributor/repo+/// 3. User tries to checkout PR from upstream-owner/repo+/// 4. No remote exists for the base repo -> error with hint to add upstream+#[rstest]+fn test_switch_pr_fork_no_upstream_remote(#[from(repo_with_remote)] repo: TestRepo) {+ // Set origin to point to the FORK (contributor's repo), not the base repo+ repo.run_git(&[+ "remote",+ "set-url",+ "origin",+ "https://github.com/contributor/test-repo.git",+ ]);++ // gh api response says base.repo is owner/test-repo (the upstream)+ // but origin points to contributor/test-repo (the fork)+ // So find_remote_for_repo("owner", "test-repo") will fail+ 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_no_upstream", cmd);+ });+}+/// Test error when PR is not found#[rstest]fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {@@ -1398,13 +1487,12 @@ fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {// Copy mock-stub binary as "gh"copy_mock_binary(&mock_bin, "gh");- // Configure gh to return error for PR not found (errors go to stderr)+ // Configure gh api to return error for PR not found (errors go to stderr)MockConfig::new("gh").version("gh version 2.0.0 (mock)").command(- "pr",- MockResponse::stderr("Could not resolve to a PullRequest with the number 9999")- .with_exit_code(1),+ "api",+ MockResponse::stderr("gh api: Not Found (HTTP 404)").with_exit_code(1),).command("_default", MockResponse::exit(1)).write(&mock_bin);@@ -1417,6 +1505,33 @@ fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {});}+/// Test error when fork was deleted (head.repo is null)+#[rstest]+fn test_switch_pr_deleted_fork(#[from(repo_with_remote)] repo: TestRepo) {+ // gh api repos/{owner}/{repo}/pulls/{number} format with null head.repo+ // This happens when the fork that the PR was opened from has been deleted+ let gh_response = r#"{+ "head": {+ "ref": "feature-fix",+ "repo": null+ },+ "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_deleted_fork", cmd);+ });+}+/// Test that --base flag conflicts with pr: syntax#[rstest]fn test_switch_pr_base_conflict(repo: TestRepo) {@@ -1445,12 +1560,17 @@ fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo"refs/pull/42/head",]);+ // gh api repos/{owner}/{repo}/pulls/{number} formatlet gh_response = r#"{- "headRefName": "feature-fix",- "headRepository": {"name": "test-repo"},- "headRepositoryOwner": {"login": "contributor"},- "isCrossRepository": true,- "url": "https://github.com/owner/test-repo/pull/42"+ "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));@@ -1481,12 +1601,17 @@ fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: Tes"refs/pull/99/head", // Different PR!]);+ // gh api repos/{owner}/{repo}/pulls/{number} formatlet gh_response = r#"{- "headRefName": "feature-fix",- "headRepository": {"name": "test-repo"},- "headRepositoryOwner": {"login": "contributor"},- "isCrossRepository": true,- "url": "https://github.com/owner/test-repo/pull/42"+ "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));@@ -1508,12 +1633,17 @@ fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Testrepo.run_git(&["branch", branch_name, "main"]);// No config set - branch exists but doesn't track anything+ // gh api repos/{owner}/{repo}/pulls/{number} formatlet gh_response = r#"{- "headRefName": "feature-fix",- "headRepository": {"name": "test-repo"},- "headRepositoryOwner": {"login": "contributor"},- "isCrossRepository": true,- "url": "https://github.com/owner/test-repo/pull/42"+ "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));@@ -1534,11 +1664,11 @@ fn test_switch_pr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {copy_mock_binary(&mock_bin, "gh");- // Configure gh to return auth error+ // Configure gh api to return auth errorMockConfig::new("gh").version("gh version 2.0.0 (mock)").command(- "pr",+ "api",MockResponse::stderr("To use GitHub CLI in a non-interactive context, please run gh auth login",)@@ -1563,12 +1693,13 @@ fn test_switch_pr_rate_limit(#[from(repo_with_remote)] repo: TestRepo) {copy_mock_binary(&mock_bin, "gh");- // Configure gh to return rate limit error+ // Configure gh api to return rate limit error (HTTP 403)MockConfig::new("gh").version("gh version 2.0.0 (mock)").command(- "pr",- MockResponse::stderr("API rate limit exceeded for user").with_exit_code(1),+ "api",+ MockResponse::stderr("gh api: API rate limit exceeded for user (HTTP 403)")+ .with_exit_code(1),).command("_default", MockResponse::exit(1)).write(&mock_bin);@@ -1589,10 +1720,10 @@ fn test_switch_pr_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {copy_mock_binary(&mock_bin, "gh");- // Configure gh to return invalid JSON+ // Configure gh api to return invalid JSONMockConfig::new("gh").version("gh version 2.0.0 (mock)")- .command("pr", MockResponse::output("not valid json {{{"))+ .command("api", MockResponse::output("not valid json {{{")).command("_default", MockResponse::exit(1)).write(&mock_bin);@@ -1612,11 +1743,11 @@ fn test_switch_pr_network_error(#[from(repo_with_remote)] repo: TestRepo) {copy_mock_binary(&mock_bin, "gh");- // Configure gh to return network error+ // Configure gh api to return network errorMockConfig::new("gh").version("gh version 2.0.0 (mock)").command(- "pr",+ "api",MockResponse::stderr("connection refused: network is unreachable").with_exit_code(1),).command("_default", MockResponse::exit(1))@@ -1638,13 +1769,14 @@ fn test_switch_pr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {copy_mock_binary(&mock_bin, "gh");- // Configure gh to return an unrecognized error+ // Configure gh api to return an unrecognized multi-line error+ // (realistic errors from gh often include context on multiple lines)+ let error_message = "error: unexpected API response\n\+ code: 500\n\+ message: Internal server error";MockConfig::new("gh").version("gh version 2.0.0 (mock)")- .command(- "pr",- MockResponse::stderr("something completely unexpected happened").with_exit_code(1),- )+ .command("api", MockResponse::stderr(error_message).with_exit_code(1)).command("_default", MockResponse::exit(1)).write(&mock_bin);@@ -1664,18 +1796,22 @@ fn test_switch_pr_empty_branch(#[from(repo_with_remote)] repo: TestRepo) {copy_mock_binary(&mock_bin, "gh");- // Configure gh to return valid JSON but with empty branch name+ // Configure gh to return valid JSON but with empty branch name (head.ref is "")let gh_response = r#"{- "headRefName": "",- "headRepository": {"name": "test-repo"},- "headRepositoryOwner": {"login": "contributor"},- "isCrossRepository": false,- "url": "https://github.com/owner/test-repo/pull/101"+ "head": {+ "ref": "",+ "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/101"}"#;MockConfig::new("gh").version("gh version 2.0.0 (mock)")- .command("pr", MockResponse::output(gh_response))+ .command("api", MockResponse::output(gh_response)).command("_default", MockResponse::exit(1)).write(&mock_bin);diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_deleted_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_deleted_fork.snapnew file mode 100644index 000000000..028bcf6da--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_deleted_fork.snap@@ -0,0 +1,38 @@+---+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: ""+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching PR #42...[39m+[31m✗[39m [31mPR #42 source repository was deleted. The fork that this PR was opened from no longer exists, so the branch cannot be checked out.[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_empty_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_empty_branch.snapindex bf8159b02..56eda849d 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_empty_branch.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_empty_branch.snap@@ -33,5 +33,5 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #101...[39m[31m✗[39m [31mPR #101 has empty branch name; the PR may be in an invalid state[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snapindex f762c595b..73367cebe 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap@@ -33,7 +33,7 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #42 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #42...[39m[2m○[22m Push configured to fork: [90mhttps://github.com/contributor/test-repo.git[39m[32m✓[39m [32mCreated branch [1mfeature-fix[22m (tracking [1mPR #42[22m) and worktree @ [1m_REPO_.feature-fix[22m[39m[33m▲[39m [33mCannot change directory — shell integration not installed[39mdiff --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 2389f67e7..a620bbe85 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@@ -13,6 +13,7 @@ info: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@@ -33,6 +34,6 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #42 from [1morigin[22m...[39m+[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[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 2389f67e7..a620bbe85 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@@ -13,6 +13,7 @@ info: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@@ -33,6 +34,6 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #42 from [1morigin[22m...[39m+[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[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_same_pr.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_same_pr.snapindex 1b9af035e..947e9677b 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_same_pr.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_existing_same_pr.snap@@ -13,6 +13,7 @@ info: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@@ -33,7 +34,7 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #42 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #42...[39m[2m○[22m Branch [1mfeature-fix[22m already configured for PR #42[32m✓[39m [32mCreated worktree for [1mfeature-fix[22m @ [1m_REPO_.feature-fix[22m[39m[33m▲[39m [33mCannot change directory — shell integration not installed[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_no_upstream.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_no_upstream.snapnew file mode 100644index 000000000..06c7ea54f--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork_no_upstream.snap@@ -0,0 +1,39 @@+---+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: ""+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: false+exit_code: 1+----- stdout -----++----- stderr -----+[36m◎[39m [36mFetching PR #42...[39m+[31m✗[39m [31mNo remote found for [1mowner/test-repo[22m[39m+[2m↳[22m [2mAdd the remote: [90mgit remote add upstream https://github.com/owner/test-repo.git[39m[22mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_invalid_json.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_invalid_json.snapindex 16cf92803..709cab81c 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_invalid_json.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_invalid_json.snap@@ -33,6 +33,6 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m-[31m✗[39m [31mFailed to parse gh pr view JSON for PR #101. This may indicate a gh version incompatibility or GitHub API change.[39m+[36m◎[39m [36mFetching PR #101...[39m+[31m✗[39m [31mFailed to parse GitHub API response for PR #101. This may indicate a GitHub API change.[39m[107m [0m expected ident at line 1 column 2diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_network_error.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_network_error.snapindex a4edc1741..5f4ab87e0 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_network_error.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_network_error.snap@@ -33,5 +33,5 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #101...[39m[31m✗[39m [31mNetwork error connecting to GitHub; check your internet connection[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_not_authenticated.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_not_authenticated.snapindex a7dda903f..ea48ecdbe 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_not_authenticated.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_not_authenticated.snap@@ -33,5 +33,5 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #101...[39m[31m✗[39m [31mGitHub CLI not authenticated; run gh auth login[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_not_found.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_not_found.snapindex 58b4fe14d..fd5e727a5 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_not_found.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_not_found.snap@@ -33,5 +33,5 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #9999 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #9999...[39m[31m✗[39m [31mPR #9999 not found[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_rate_limit.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_rate_limit.snapindex fd4135d05..66d47708f 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_rate_limit.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_rate_limit.snap@@ -33,5 +33,5 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #101...[39m[31m✗[39m [31mGitHub API rate limit exceeded; wait a few minutes and retry[39mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_same_repo.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_same_repo.snapindex c656d0639..e46c89326 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_same_repo.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_same_repo.snap@@ -33,6 +33,6 @@ exit_code: 0----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m+[36m◎[39m [36mFetching PR #101...[39m[33m▲[39m [33mWorktree for [1mfeature-auth[22m @ [1m_REPO_.feature-auth[22m, but cannot 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_unknown_error.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_unknown_error.snapindex 383d8d745..940d626c3 100644--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_unknown_error.snap+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_unknown_error.snap@@ -33,5 +33,8 @@ exit_code: 1----- stdout ---------- stderr ------[36m◎[39m [36mFetching PR #101 from [1morigin[22m...[39m-[31m✗[39m [31mgh pr view failed: something completely unexpected happened[39m+[36m◎[39m [36mFetching PR #101...[39m+[31m✗[39m [31mgh api failed for PR #101[39m+[107m [0m error: unexpected API response+[107m [0m code: 500+[107m [0m message: Internal server error