Skip to content

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

fix: six independent single-file data-safety and correctness fixes (#2784)

Maximilian Roosf68626dd039c
diff --git a/src/commands/relocate.rs b/src/commands/relocate.rs
index 9a06ce2f6..75c9f6810 100644
--- a/src/commands/relocate.rs
+++ b/src/commands/relocate.rs
@@ -383,6 +383,15 @@ impl<'a> RelocationExecutor<'a> {
.unwrap_or_default()
.to_string_lossy()
));
+ // Fail closed if the backup destination already exists: `fs::rename`
+ // can silently replace an existing file (and some empty
+ // directories) on Unix, which would destroy a prior backup.
+ if backup_path.exists() {
+ anyhow::bail!(
+ "Backup path already exists: {}",
+ format_path_for_display(&backup_path)
+ );
+ }
let src = format_path_for_display(expected_path);
let dest = format_path_for_display(&backup_path);
eprintln!(
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rs
index 5cbe67672..fc55b6ce3 100644
--- a/src/commands/worktree/switch.rs
+++ b/src/commands/worktree/switch.rs
@@ -931,9 +931,14 @@ pub fn execute_switch(
let local_branch_existed =
!create_branch && branch_handle.exists_locally().unwrap_or(false);
- // Build git worktree add command
+ // Build git worktree add command. Options come first, then
+ // `--` separates them from the path and any positional ref,
+ // so branch/base names that begin with `-` cannot be
+ // misinterpreted by git as flags. `-b <branch>` keeps the
+ // branch as the *value* of `-b`, which is safe even when
+ // the branch name starts with `-`.
let worktree_path_str = worktree_path.to_string_lossy();
- let mut args = vec!["worktree", "add", worktree_path_str.as_ref()];
+ let mut args: Vec<&str> = vec!["worktree", "add"];
// For DWIM fallback: when the branch doesn't exist locally,
// git worktree add relies on DWIM to auto-create it from a
@@ -942,12 +947,10 @@ pub fn execute_switch(
// create from the tracking ref in that case.
let tracking_ref;
- if *create_branch {
+ let trailing_ref: Option<&str> = if *create_branch {
args.push("-b");
args.push(&branch);
- if let Some(base) = base_branch {
- args.push(base);
- }
+ base_branch.as_deref()
} else if !local_branch_existed {
// Explicit -b when there's exactly one remote tracking ref.
// Git's DWIM relies on the fetch refspec including this branch,
@@ -955,13 +958,20 @@ pub fn execute_switch(
let remotes = branch_handle.remotes().unwrap_or_default();
if remotes.len() == 1 {
tracking_ref = format!("{}/{}", remotes[0], branch);
- args.extend(["-b", &branch, tracking_ref.as_str()]);
+ args.extend(["-b", &branch]);
+ Some(tracking_ref.as_str())
} else {
// Multiple or zero remotes: let git's DWIM handle (or error)
- args.push(&branch);
+ Some(branch.as_str())
}
} else {
- args.push(&branch);
+ Some(branch.as_str())
+ };
+
+ args.push("--");
+ args.push(worktree_path_str.as_ref());
+ if let Some(r) = trailing_ref {
+ args.push(r);
}
// Delayed streaming: silent if fast, shows progress if slow
@@ -1078,10 +1088,22 @@ pub fn execute_switch(
}
};
- // Compute base worktree path for hooks and result
+ // Compute base worktree path for hooks and result.
+ //
+ // `git worktree add` already mutated the worktree list, but `repo`
+ // cached it pre-create (populated by `plan_switch`). Reading
+ // `worktree_for_branch` through `repo` here would observe the stale
+ // pre-create inventory — see the caching contract in
+ // `git/repository/mod.rs`. Probe through a fresh `Repository::at`
+ // so the lookup reflects the post-create state.
let base_worktree_path = base_branch
.as_ref()
- .and_then(|b| repo.worktree_for_branch(b).ok().flatten())
+ .and_then(|b| {
+ Repository::at(repo.discovery_path())
+ .and_then(|fresh| fresh.worktree_for_branch(b))
+ .ok()
+ .flatten()
+ })
.map(|p| worktrunk::path::to_posix_path(&p.to_string_lossy()));
// PR/MR identity travels into both the pre-start hook below and the
diff --git a/src/git/remote_ref/azure.rs b/src/git/remote_ref/azure.rs
index 49922120c..47776474d 100644
--- a/src/git/remote_ref/azure.rs
+++ b/src/git/remote_ref/azure.rs
@@ -265,6 +265,16 @@ fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result<RemoteRefI
.unwrap_or(&response.source_ref_name)
.to_string();
+ // Validate at the provider boundary — same as the GitHub/GitLab/Gitea
+ // providers — so an empty or `refs/heads/`-only sourceRefName produces a
+ // clear diagnostic rather than confusing downstream git/path errors.
+ if source_branch.is_empty() {
+ bail!(
+ "Azure DevOps PR #{} has empty branch name; the PR may be in an invalid state",
+ pr_number
+ );
+ }
+
let is_cross_repo = response.fork_source.is_some();
let fork_push_url = response.fork_source.as_ref().and_then(|fork| {
diff --git a/src/git/remote_ref/gitea.rs b/src/git/remote_ref/gitea.rs
index 23ff21b15..d3dca5fba 100644
--- a/src/git/remote_ref/gitea.rs
+++ b/src/git/remote_ref/gitea.rs
@@ -18,7 +18,7 @@ use super::{
CliApiRequest, PlatformData, RemoteRefInfo, RemoteRefProvider, cli_api_error,
extract_host_from_html_url, run_cli_api,
};
-use crate::git::{self, RefType, Repository};
+use crate::git::{RefType, Repository};
/// Gitea Pull Request provider.
#[derive(Debug, Clone, Copy)]
@@ -92,14 +92,12 @@ struct TeaOwner {
fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo> {
let repo_root = repo.repo_path()?;
- // Resolve owner/repo from the primary remote URL so we pass a fully
- // expanded path to `tea api`. See module docstring for rationale.
- let remote = repo.primary_remote()?;
- let url = repo
- .remote_url(&remote)
- .ok_or_else(|| anyhow::anyhow!("Remote '{}' has no URL", remote))?;
- let parsed = git::GitRemoteUrl::parse(&url)
- .ok_or_else(|| anyhow::anyhow!("Cannot parse remote URL: {}", url))?;
+ // Resolve owner/repo from the Gitea remote — which may be non-primary in
+ // a mixed-remote repo — so we pass a fully expanded path to `tea api`.
+ // See module docstring for the raw-URL rationale.
+ let parsed = repo
+ .forge_remote_parsed_url(|u| u.is_gitea())
+ .ok_or_else(|| anyhow::anyhow!("No Gitea remote configured"))?;
let api_path = format!(
"repos/{}/{}/pulls/{}",
diff --git a/src/git/remote_ref/github.rs b/src/git/remote_ref/github.rs
index cf6233ecd..72e1b8edc 100644
--- a/src/git/remote_ref/github.rs
+++ b/src/git/remote_ref/github.rs
@@ -11,7 +11,7 @@ use super::{
CliApiRequest, PlatformData, RemoteRefInfo, RemoteRefProvider, cli_api_error, cli_config_value,
extract_host_from_html_url, run_cli_api,
};
-use crate::git::{self, RefType, Repository};
+use crate::git::{RefType, Repository};
use crate::shell_exec::Cmd;
/// GitHub Pull Request provider.
@@ -109,19 +109,18 @@ fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result<RemoteRefI
let (owner, repo_name, source) = if let Some((owner, name)) = gh_default_repo(repo_root) {
(owner, name, "gh default".to_string())
} else {
- // Extract owner/repo from primary remote URL. Uses raw URL (not
- // effective) because insteadOf may rewrite to a non-parseable path.
- // SSH aliases only affect the host, not the path — owner/repo is always real.
- let remote = repo.primary_remote()?;
- let url = repo
- .remote_url(&remote)
- .ok_or_else(|| anyhow::anyhow!("Remote '{}' has no URL", remote))?;
- let parsed = git::GitRemoteUrl::parse(&url)
- .ok_or_else(|| anyhow::anyhow!("Cannot parse remote URL: {}", url))?;
+ // Extract owner/repo from the GitHub remote — which may be a
+ // non-primary remote in a mixed-remote repo (e.g. origin=GitLab,
+ // upstream=GitHub). Uses the raw URL (not effective) because insteadOf
+ // may rewrite to a non-parseable path; SSH aliases only affect the
+ // host, not the path, so owner/repo is always real.
+ let parsed = repo
+ .forge_remote_parsed_url(|u| u.is_github())
+ .ok_or_else(|| anyhow::anyhow!("No GitHub remote configured"))?;
(
parsed.owner().to_string(),
parsed.repo().to_string(),
- remote,
+ "github remote".to_string(),
)
};
diff --git a/src/git/repository/branch.rs b/src/git/repository/branch.rs
index 2c523ea82..831094b0f 100644
--- a/src/git/repository/branch.rs
+++ b/src/git/repository/branch.rs
@@ -103,8 +103,10 @@ impl<'a> Branch<'a> {
/// This removes the tracking relationship, preventing accidental pushes
/// to the wrong branch (e.g., when a feature branch was created from origin/main).
pub fn unset_upstream(&self) -> anyhow::Result<()> {
+ // `--` separates the option from the positional branch name so a
+ // hyphen-prefixed branch cannot be misread as a flag.
self.repo
- .run_command(&["branch", "--unset-upstream", &self.name])?;
+ .run_command(&["branch", "--unset-upstream", "--", &self.name])?;
Ok(())
}
diff --git a/src/git/repository/remotes.rs b/src/git/repository/remotes.rs
index 6601a5d2b..aa85c09e0 100644
--- a/src/git/repository/remotes.rs
+++ b/src/git/repository/remotes.rs
@@ -308,6 +308,31 @@ impl Repository {
.and_then(GitRemoteUrl::parse)
}
+ /// Parsed URL of the remote that belongs to a particular forge.
+ ///
+ /// Prefers the primary remote when it matches `is_forge`, then the first
+ /// other remote whose URL matches, and finally falls back to the primary
+ /// remote's parsed URL even if it doesn't match (so callers preserve their
+ /// existing "no forge remote" error path). PR/MR lookup uses this so a
+ /// GitHub/Gitea mirror configured as a *non-primary* remote is queried
+ /// against its own owner/repo rather than the primary (e.g. GitLab/Azure)
+ /// remote's path.
+ pub fn forge_remote_parsed_url(
+ &self,
+ is_forge: impl Fn(&GitRemoteUrl) -> bool,
+ ) -> Option<GitRemoteUrl> {
+ if let Some(primary) = self.primary_remote_parsed_url()
+ && is_forge(&primary)
+ {
+ return Some(primary);
+ }
+ self.all_remote_urls()
+ .into_iter()
+ .filter_map(|(_, url)| GitRemoteUrl::parse(&url))
+ .find(&is_forge)
+ .or_else(|| self.primary_remote_parsed_url())
+ }
+
/// Detect the platform's reference type (PR for GitHub, MR for GitLab).
///
/// Hostname-matches the primary remote's effective URL (so `url.insteadOf`
diff --git a/src/git/repository/worktrees.rs b/src/git/repository/worktrees.rs
index e30f76878..784f54d03 100644
--- a/src/git/repository/worktrees.rs
+++ b/src/git/repository/worktrees.rs
@@ -135,15 +135,14 @@ impl Repository {
///
/// # TOCTOU note
///
- /// Git checks for submodules *before* checking for dirty files. If a
- /// file is modified between our `ensure_clean()` and the git command,
- /// git reports the submodule error (not the dirty error), so our
- /// submodule pre-check still leads to `--force` and bypasses git's
- /// dirty check. This is the same TOCTOU window that exists for all
- /// removal (between
- /// `ensure_clean()` and the actual delete), but for non-submodule
- /// worktrees git's own dirty check acts as an accidental backstop
- /// that we lose here. The window is milliseconds.
+ /// Git checks for submodules *before* checking for dirty files, so when
+ /// we synthesize `--force` for a submodule worktree, git's own dirty
+ /// check is bypassed. To keep failing closed on a file modified after the
+ /// caller's `ensure_clean()`, this method re-runs `ensure_clean()` itself
+ /// immediately before the synthesized-force removal — restoring the
+ /// backstop git would otherwise have provided. (For an explicit
+ /// user-requested `force`, the user opted into destructive removal, so no
+ /// re-check.)
pub fn remove_worktree(&self, path: &std::path::Path, force: bool) -> anyhow::Result<()> {
let path_str = path.to_str().ok_or_else(|| {
anyhow::Error::from(GitError::Other {
@@ -159,6 +158,16 @@ impl Repository {
self.worktree_at(path).has_initialized_submodules()?
};
if use_force && !force {
+ // Synthesized force (submodule worktree, not user-requested).
+ // `--force` will suppress git's dirty check, so re-validate
+ // cleanliness ourselves right before the destructive command —
+ // a file modified since the caller's check must still fail
+ // closed rather than be silently destroyed.
+ self.worktree_at(path).ensure_clean(
+ "remove worktree with submodules",
+ None,
+ /* force_hint */ true,
+ )?;
log::debug!("Using --force for worktree removal due to initialized submodules");
}
let mut args = vec!["worktree", "remove"];
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index d0082141d..c481fcd27 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -3052,6 +3052,88 @@ fn test_remove_foreground_with_submodules(mut repo: TestRepo) {
);
}
+/// Regression: `Repository::remove_worktree(path, force=false)` synthesizes
+/// `git worktree remove --force` for submodule worktrees, which suppresses
+/// git's own dirty-file check. The method must re-validate cleanliness
+/// itself right before the synthesized-force command so a file dirtied after
+/// the caller's planning-time check is not silently destroyed.
+#[rstest]
+fn test_remove_worktree_submodule_dirty_fails_closed(mut repo: TestRepo) {
+ use worktrunk::git::Repository;
+
+ // Submodule source.
+ let sub_source = repo.root_path().parent().unwrap().join("sub-source-dirty");
+ std::fs::create_dir_all(&sub_source).unwrap();
+ repo.run_git_in(&sub_source, &["init"]);
+ std::fs::write(sub_source.join("sub.txt"), "submodule content").unwrap();
+ repo.run_git_in(&sub_source, &["add", "sub.txt"]);
+ repo.run_git_in(&sub_source, &["commit", "-m", "sub init"]);
+
+ std::fs::write(repo.root_path().join("tracked.txt"), "original\n").unwrap();
+ repo.run_git(&["add", "tracked.txt"]);
+ repo.run_git(&["commit", "-m", "add tracked file"]);
+
+ let output = repo
+ .git_command()
+ .args([
+ "-c",
+ "protocol.file.allow=always",
+ "submodule",
+ "add",
+ sub_source.to_str().unwrap(),
+ "submod",
+ ])
+ .run()
+ .unwrap();
+ assert!(
+ output.status.success(),
+ "Failed to add submodule: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ repo.run_git(&["commit", "-m", "add submodule"]);
+
+ let worktree_path = repo.add_worktree("feature-submod-dirty");
+ let output = repo
+ .git_command()
+ .current_dir(&worktree_path)
+ .args([
+ "-c",
+ "protocol.file.allow=always",
+ "submodule",
+ "update",
+ "--init",
+ ])
+ .run()
+ .unwrap();
+ assert!(
+ output.status.success(),
+ "Failed to init submodule: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+
+ // Simulate the TOCTOU window: a tracked file is modified after the
+ // caller's clean check but before remove_worktree's destructive step.
+ std::fs::write(worktree_path.join("tracked.txt"), "DIRTIED\n").unwrap();
+
+ let repo_api = Repository::at(repo.root_path()).unwrap();
+ let result = repo_api.remove_worktree(&worktree_path, /* force */ false);
+
+ assert!(
+ result.is_err(),
+ "remove_worktree must fail closed when a submodule worktree is dirty \
+ (synthesized --force would otherwise destroy the change)"
+ );
+ assert!(
+ worktree_path.exists(),
+ "submodule worktree must be preserved, not force-removed"
+ );
+ assert_eq!(
+ std::fs::read_to_string(worktree_path.join("tracked.txt")).unwrap(),
+ "DIRTIED\n",
+ "the post-check modification must be intact (not destroyed)"
+ );
+}
+
/// Restore write permissions recursively so TempDir cleanup succeeds.
#[cfg(unix)]
fn restore_dir_permissions(dir: &std::path::Path) {
diff --git a/tests/integration_tests/step_relocate.rs b/tests/integration_tests/step_relocate.rs
index d96274447..ff84a6ee6 100644
--- a/tests/integration_tests/step_relocate.rs
+++ b/tests/integration_tests/step_relocate.rs
@@ -313,6 +313,55 @@ fn test_relocate_clobber_backs_up(repo: TestRepo) {
assert!(backup_exists, "Backup directory should exist");
}
+/// Regression: when the computed backup path already exists, relocate
+/// --clobber must fail rather than silently overwriting it. (Matches the
+/// `wt switch --clobber` contract — see test_switch_clobber_error_backup_exists.)
+#[rstest]
+fn test_relocate_clobber_error_backup_exists(repo: TestRepo) {
+ let parent = worktree_parent(&repo);
+
+ // Create a worktree at a non-standard location.
+ let wrong_path = parent.join("wrong-location");
+ repo.run_git(&[
+ "worktree",
+ "add",
+ "-b",
+ "feature",
+ wrong_path.to_str().unwrap(),
+ ]);
+
+ // Blocker file at the expected destination.
+ let expected_path = parent.join("repo.feature");
+ fs::write(&expected_path, "blocker contents").unwrap();
+
+ // Pre-create the backup path that relocate would compute. TEST_EPOCH
+ // pins the timestamp suffix so this name is deterministic.
+ // TEST_EPOCH=1735776000 -> 2025-01-02 00:00:00 UTC
+ let backup_path = parent.join("repo.feature.bak-20250102-000000");
+ fs::write(&backup_path, "existing backup").unwrap();
+
+ let output = make_snapshot_cmd(&repo, "step", &["relocate", "--clobber"], None)
+ .output()
+ .expect("relocate should run");
+ assert!(
+ !output.status.success(),
+ "relocate must fail when backup path already exists; stderr:\n{}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+
+ // Both the blocker and the existing backup must be intact.
+ assert_eq!(
+ fs::read_to_string(&expected_path).unwrap(),
+ "blocker contents",
+ "blocker file must not be moved"
+ );
+ assert_eq!(
+ fs::read_to_string(&backup_path).unwrap(),
+ "existing backup",
+ "existing backup must not be overwritten"
+ );
+}
+
/// Test that --clobber refuses to clobber an existing worktree
#[rstest]
fn test_relocate_clobber_refuses_worktree(repo: TestRepo) {
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 477375f7c..7ee365835 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -2722,6 +2722,87 @@ fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {
});
}
+/// Regression: when the GitHub remote is *non-primary* (origin is GitLab,
+/// `upstream` is GitHub), `wt switch pr:N` must derive owner/repo from the
+/// GitHub remote, not the primary. The mock answers only the upstream's API
+/// path; the old code queried the gitlab origin's path and hit `_default`.
+#[rstest]
+fn test_switch_pr_uses_nonprimary_github_remote(#[from(repo_with_remote)] mut repo: TestRepo) {
+ repo.add_worktree("feature-auth");
+ repo.run_git(&["push", "origin", "feature-auth"]);
+
+ let bare_url = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["config", "remote.origin.url"])
+ .run()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+
+ // origin is GitLab (non-GitHub) — must NOT be used for the gh api path.
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitlab.com/glowner/glrepo.git",
+ ]);
+ // GitHub lives on a non-primary remote.
+ repo.run_git(&[
+ "remote",
+ "add",
+ "upstream",
+ "https://github.com/upowner/uprepo.git",
+ ]);
+ // Redirect the GitHub URL to the local bare remote so fetch works.
+ repo.run_git(&[
+ "config",
+ &format!("url.{}.insteadOf", bare_url),
+ "https://github.com/upowner/uprepo.git",
+ ]);
+
+ let mock_bin = repo.root_path().join("mock-bin");
+ fs::create_dir_all(&mock_bin).unwrap();
+ copy_mock_binary(&mock_bin, "gh");
+ fs::write(
+ mock_bin.join("pr_response.json"),
+ r#"{
+ "title": "Fix auth",
+ "user": {"login": "alice"},
+ "state": "open",
+ "draft": false,
+ "head": {"ref": "feature-auth", "repo": {"name": "uprepo", "owner": {"login": "upowner"}}},
+ "base": {"ref": "main", "repo": {"name": "uprepo", "owner": {"login": "upowner"}}},
+ "html_url": "https://github.com/upowner/uprepo/pull/77"
+ }"#,
+ )
+ .unwrap();
+ // Only answer the *upstream* repo's API path. If owner/repo were derived
+ // from the gitlab origin, the path would differ and hit `_default` (exit 1).
+ MockConfig::new("gh")
+ .version("gh version 2.0.0 (mock)")
+ .command(
+ "api repos/upowner/uprepo/pulls/77",
+ MockResponse::file("pr_response.json"),
+ )
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+
+ let output = {
+ let mut cmd = repo.wt_command();
+ cmd.args(["switch", "pr:77"]);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ cmd.output().unwrap()
+ };
+ assert!(
+ output.status.success(),
+ "switch pr:77 must resolve via the non-primary GitHub remote; stderr:\n{}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+}
+
/// Test error when fork was deleted (head.repo is null)
#[rstest]
fn test_switch_pr_deleted_fork(#[from(repo_with_remote)] repo: TestRepo) {
@@ -4555,6 +4636,50 @@ fn test_switch_pr_azure_same_repo(#[from(repo_with_remote)] mut repo: TestRepo)
});
}
+/// Regression: an Azure PR whose `sourceRefName` is just `refs/heads/`
+/// (empty branch after stripping) must fail at the provider boundary with a
+/// clear message — matching GitHub/GitLab/Gitea — not produce a confusing
+/// downstream git/path error.
+#[rstest]
+fn test_switch_pr_azure_empty_source_branch(#[from(repo_with_remote)] repo: TestRepo) {
+ set_azure_remote_url(
+ &repo,
+ "https://dev.azure.com/myorg/myproject/_git/test-repo",
+ );
+
+ let az_response = r#"{
+ "title": "Broken PR",
+ "createdBy": {"uniqueName": "[email protected]"},
+ "status": "active",
+ "isDraft": false,
+ "sourceRefName": "refs/heads/",
+ "repository": {
+ "name": "test-repo",
+ "project": {"name": "myproject"},
+ "webUrl": "https://dev.azure.com/myorg/myproject/_git/test-repo"
+ },
+ "forkSource": null
+ }"#;
+
+ let mock_bin = setup_mock_az(&repo, Some(az_response));
+
+ let output = {
+ let mut cmd = repo.wt_command();
+ cmd.args(["switch", "pr:101"]);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ cmd.output().unwrap()
+ };
+ assert!(
+ !output.status.success(),
+ "switch must fail on an empty Azure source branch"
+ );
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("empty branch name"),
+ "expected a clear empty-branch diagnostic, got:\n{stderr}"
+ );
+}
+
/// Legacy `*.visualstudio.com` remotes encode the org in the hostname — exercises
/// the `*.visualstudio.com` branches of the Azure URL helpers end to end.
#[rstest]
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_dwim_ambiguous_remotes.snap b/tests/snapshots/integration__integration_tests__switch__switch_dwim_ambiguous_remotes.snap
index e31baa704..8a1591f8f 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_dwim_ambiguous_remotes.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_dwim_ambiguous_remotes.snap
@@ -11,13 +11,19 @@ info:
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
NO_COLOR: ""
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
@@ -30,13 +36,17 @@ info:
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_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: false
@@ -47,4 +57,4 @@ exit_code: 1
✗ Failed to create worktree for shared-feature
  fatal: invalid reference: shared-feature
↳ Failed command, exit code 128:
-  git worktree add _REPO_.shared-feature shared-feature
+  git worktree add -- _REPO_.shared-feature shared-feature
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap
index 8a27989a6..1cc57705f 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_no_remote_defaults_to_github.snap
@@ -23,6 +23,7 @@ info:
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
NO_COLOR: ""
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
@@ -54,4 +55,4 @@ exit_code: 1
----- stderr -----
◎ Fetching PR #101...
-✗ Cannot parse remote URL: ../origin.git
+✗ No GitHub remote configured
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_not_found.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_not_found.snap
index e5191f1a3..9e16ae6df 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
@@ -11,13 +11,19 @@ info:
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
NO_COLOR: ""
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
@@ -30,13 +36,17 @@ info:
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_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: false
@@ -45,4 +55,4 @@ exit_code: 1
----- stderr -----
◎ Fetching PR #9999...
-✗ PR #9999 not found on owner/test-repo (origin). If the PR is on a different repository, run `gh repo set-default` to set the default or configure a different primary remote.
+✗ PR #9999 not found on owner/test-repo (github remote). If the PR is on a different repository, run `gh repo set-default` to set the default or configure a different primary remote.