Skip to content

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

Honor resolved paths and forge settings (#4495)

Maximilian Roos4416f64e4698
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 2998abc64..b3d309f69 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -1157,14 +1157,17 @@ fn render_fish_legacy_migration(
/// Zsh-only: warn when compinit isn't enabled, since the integration
/// installs completions but they won't load without compinit.
-fn render_zsh_compinit_warning(out: &mut String) -> anyhow::Result<()> {
+fn render_zsh_compinit_warning(out: &mut String, path: &Path, cmd: &str) -> anyhow::Result<()> {
if probe_zsh_compdef(ZshStartupScope::UserOnly) != Some(false) {
return Ok(());
}
writeln!(
out,
"{}",
- warning_message("Completions won't work; add to ~/.zshrc before the wt line:")
+ warning_message(format!(
+ "Completions won't work; add to {} before the {cmd} line:",
+ format_path_for_display(path)
+ ))
)?;
writeln!(
out,
@@ -1278,7 +1281,7 @@ fn render_already_configured(
let needs_install = match shell {
Shell::Zsh => {
- render_zsh_compinit_warning(out)?;
+ render_zsh_compinit_warning(out, &result.path, cmd)?;
false
}
Shell::Fish => render_fish_completion_status(out, cmd)?,
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index 7e68bcbcb..1d718edcb 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -20,7 +20,6 @@ use std::env;
use std::io::{self, IsTerminal, Read};
use std::path::{Component, Path, PathBuf};
-use ansi_str::AnsiStr;
use anyhow::{Context, Result};
use worktrunk::git::{Repository, WorkingTree, WorktreeId};
use worktrunk::styling::{
@@ -797,16 +796,7 @@ pub fn run(format: StatuslineFormat) -> Result<()> {
if let Some(worktree) = &worktree
&& worktree.git_dir().is_ok()
{
- let git_segments = git_status_segments(worktree)?;
-
- // In claude-code mode, skip branch segment if directory matches worktrunk template
- let git_segments = if let Some(ref dir) = dir_str {
- filter_redundant_branch(git_segments, dir)
- } else {
- git_segments
- };
-
- segments.extend(git_segments);
+ segments.extend(git_status_segments(worktree, dir_str.as_deref())?);
}
// Model name (claude-code mode only) - priority 1 (same as Branch).
@@ -993,34 +983,53 @@ fn run_json() -> Result<()> {
}
}
-/// Filter out branch segment if directory already shows it via worktrunk template.
-fn filter_redundant_branch(segments: Vec<StatuslineSegment>, dir: &str) -> Vec<StatuslineSegment> {
+/// Omit a branch visible in a directory whose configured path still names it.
+/// Keep it when the checkout no longer matches that configured path, and in
+/// the main worktree, whose name was never derived from its current branch.
+fn filter_redundant_branch(
+ segments: Vec<StatuslineSegment>,
+ dir: &str,
+ repo: &Repository,
+ branch: &str,
+ path: &Path,
+) -> Vec<StatuslineSegment> {
use super::list::columns::ColumnKind;
- // Find the branch segment by its column kind (not priority, which could be shared)
- if let Some(branch_seg) = segments.iter().find(|s| s.kind == Some(ColumnKind::Branch)) {
- // Strip ANSI codes in case branch becomes styled in future
- let raw_branch = branch_seg.content.ansi_strip();
- // Normalize branch name for comparison (slashes become dashes in paths)
- let normalized_branch = worktrunk::config::sanitize_branch_name(&raw_branch);
- let pattern = format!(".{normalized_branch}");
-
- if dir.ends_with(&pattern) {
- // Directory already shows branch via worktrunk template, skip branch segment
- return segments
- .into_iter()
- .filter(|s| s.kind != Some(ColumnKind::Branch))
- .collect();
- }
+ let linked_worktree = repo
+ .repo_path()
+ .is_ok_and(|repo_path| !worktrunk::path::paths_match(path, repo_path));
+ let expected_path = linked_worktree
+ && super::worktree::compute_worktree_path(repo, branch, repo.user_config())
+ .is_ok_and(|expected| worktrunk::path::paths_match(path, &expected));
+ if expected_path && directory_shows_branch(dir, branch) {
+ return segments
+ .into_iter()
+ .filter(|s| s.kind != Some(ColumnKind::Branch))
+ .collect();
}
segments
}
+/// Check only the final displayed component; parent names may be abbreviated.
+fn directory_shows_branch(dir: &str, branch: &str) -> bool {
+ let normalized_branch = worktrunk::config::sanitize_branch_name(branch);
+ let name = dir.rsplit('/').next().unwrap_or(dir);
+ name.match_indices(&normalized_branch).any(|(start, _)| {
+ let end = start + normalized_branch.len();
+ let before = name[..start].chars().next_back();
+ let after = name[end..].chars().next();
+ before.is_none_or(|c| !c.is_alphanumeric()) && after.is_none_or(|c| !c.is_alphanumeric())
+ })
+}
+
/// Get git status as prioritized segments for the current worktree.
///
/// CI status and the dev-server URL render as underlined OSC 8 hyperlinks.
-fn git_status_segments(worktree: &WorkingTree) -> Result<Vec<StatuslineSegment>> {
+fn git_status_segments(
+ worktree: &WorkingTree,
+ visible_dir: Option<&str>,
+) -> Result<Vec<StatuslineSegment>> {
use super::list::columns::ColumnKind;
let repo = worktree.repo();
@@ -1050,12 +1059,22 @@ fn git_status_segments(worktree: &WorkingTree) -> Result<Vec<StatuslineSegment>>
// Never empty: the branch segment is unconditional, so there is no
// emptier case to fall back to.
- Ok(item.format_statusline_segments())
+ let segments = item.format_statusline_segments();
+ // Deduplicate only an inventory worktree whose default branch was already
+ // resolved above. A foreign directory's fallback must not start detection
+ // (which may contact a remote) just to decide whether to hide its branch.
+ Ok(match (visible_dir, item.branch(), item.worktree_path()) {
+ (Some(dir), Some(branch), Some(path)) => {
+ filter_redundant_branch(segments, dir, repo, branch, path)
+ }
+ _ => segments,
+ })
}
#[cfg(test)]
mod tests {
use super::*;
+ use ansi_str::AnsiStr;
#[test]
fn test_format_directory_fish_style() {
@@ -1166,24 +1185,22 @@ mod tests {
assert!(ClaudeCodeContext::parse("{invalid}").is_none());
}
- #[test]
- fn test_branch_deduplication_with_slashes() {
- // Simulate the actual scenario:
- // - Directory: ~/w/insta.claude-fix-snapshot-merge-conflicts-xyz
- // - Branch: claude/fix-snapshot-merge-conflicts-xyz
- let dir = "~/w/insta.claude-fix-snapshot-merge-conflicts-xyz";
- let branch = "claude/fix-snapshot-merge-conflicts-xyz";
-
- let normalized_branch = worktrunk::config::sanitize_branch_name(branch);
- let pattern = format!(".{normalized_branch}");
-
- assert!(
- dir.ends_with(&pattern),
- "Directory '{}' should end with pattern '{}' (normalized from branch '{}')",
- dir,
- pattern,
- branch
- );
+ #[rstest::rstest]
+ #[case("~/w/repo.feature", "feature", false)]
+ #[case("~/w/feature", "feature", false)]
+ #[case("~/w/repo-feature", "feature", false)]
+ #[case("~/w/feature-repo", "feature", false)]
+ #[case("~/w/repo.claude-fix", "claude/fix", false)]
+ #[case("~/w/repo-featured", "feature", true)]
+ #[case("~/w/repo-misfeature", "feature", true)]
+ #[case("~/w/repo.feature/src", "feature", true)]
+ #[case("~/w/checkout", "feature", true)]
+ fn test_branch_deduplication(
+ #[case] dir: &str,
+ #[case] branch: &str,
+ #[case] keeps_branch: bool,
+ ) {
+ assert_eq!(!directory_shows_branch(dir, branch), keeps_branch);
}
/// Width fitting must never cut inside a linked segment's OSC 8 sequence.
diff --git a/src/commands/step/prune.rs b/src/commands/step/prune.rs
index 530f97208..11c8dbbcd 100644
--- a/src/commands/step/prune.rs
+++ b/src/commands/step/prune.rs
@@ -371,15 +371,15 @@ fn try_remove(
/// One candidate skipped because its project hooks aren't yet approved.
/// Carries enough context for the end-of-run hint to print a per-candidate
-/// `wt -C <path> remove` line and annotate candidates whose own
-/// `.config/wt.toml` differs from the invoking worktree's (so the user knows
-/// `wt config approvals add` from current can't approve their hooks).
+/// `wt -C <path> remove` line and annotate candidates whose resolved project
+/// config differs from the invoking worktree's (so the user knows `wt config
+/// approvals add` from current can't approve their hooks).
struct SkippedApproval {
/// `Some` for candidates whose plan removes a worktree (the only
/// `(approval required)` source — branch-only plans and stale-detached
/// entries run no hooks).
path: Option<PathBuf>,
- /// True when the candidate's `.config/wt.toml` doesn't match the
+ /// True when the candidate's resolved project config doesn't match the
/// invoking worktree's bytes — `wt config approvals add` from current
/// approves only invoking's templates, so this candidate needs the
/// per-worktree `wt -C <path> remove` form to surface its own hooks.
@@ -1167,7 +1167,7 @@ pub fn step_prune(
};
// The invoking worktree's project-config bytes — load once so the per-
// candidate "(different hooks on branch)" annotation in the skip hint
- // can compare each candidate's own `.config/wt.toml` against this
+ // can compare each candidate's resolved project config against this
// baseline. Byte-equal is approximate (whitespace differences flag too)
// but the result drives a hint, not behavior.
let invoking_project_bytes = repo
@@ -1324,8 +1324,11 @@ pub fn step_prune(
.to_string();
let _ = job_tx.send(RemovalJob::PrintSkip(line));
let differs = path.as_deref().is_some_and(|wt_path| {
- let candidate_bytes =
- std::fs::read(wt_path.join(".config").join("wt.toml")).ok();
+ let candidate_bytes = Repository::at(wt_path)
+ .and_then(|candidate_repo| candidate_repo.project_config_path())
+ .ok()
+ .flatten()
+ .and_then(|p| std::fs::read(p).ok());
candidate_bytes != invoking_project_bytes
});
skipped_approval.push(SkippedApproval { path, differs });
@@ -1445,7 +1448,7 @@ struct ApprovalHintBlock {
/// Build the headline+gutter pairs for `(approval required)` skips: a
/// `wt config approvals add` block listing the unapproved templates from the
/// invoking worktree's config, and a per-worktree `wt -C <path> remove` block
-/// for the skipped candidates. Candidates whose own `.config/wt.toml` differs
+/// for the skipped candidates. Candidates whose resolved project config differs
/// from the invoking worktree get a `(different hooks on branch)` annotation —
/// `wt config approvals add` from current approves only current's templates,
/// so the per-worktree form is the only path for them.
diff --git a/src/git/remote_ref/gitea.rs b/src/git/remote_ref/gitea.rs
index 41d0f89a2..7e61ed2b0 100644
--- a/src/git/remote_ref/gitea.rs
+++ b/src/git/remote_ref/gitea.rs
@@ -122,6 +122,7 @@ struct TeaPrRef {
struct TeaPrRepo {
name: String,
owner: TeaOwner,
+ clone_url: String,
}
#[derive(Debug, Deserialize)]
@@ -241,10 +242,7 @@ pub(super) fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result
.eq_ignore_ascii_case(&head_repo.owner.login)
|| !base_repo.name.eq_ignore_ascii_case(&head_repo.name);
- let host = extract_host_from_html_url(&response.html_url)?;
-
- let fork_push_url =
- is_cross_repo.then(|| fork_remote_url(&host, &head_repo.owner.login, &head_repo.name));
+ let fork_push_url = is_cross_repo.then_some(head_repo.clone_url);
Ok(RemoteRefInfo {
number: pr_number,
@@ -257,11 +255,11 @@ pub(super) fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result
url: response.html_url,
fork_push_url,
platform_data: PlatformData::Gitea {
- host,
head_owner: head_repo.owner.login,
head_repo: head_repo.name,
base_owner: base_repo.owner.login,
base_repo: base_repo.name,
+ base_clone_url: base_repo.clone_url,
},
})
}
@@ -307,11 +305,6 @@ fn is_real_branch_name(s: &str) -> bool {
&& !s.starts_with("pull/")
}
-/// Construct the remote URL for a Gitea repository.
-pub fn fork_remote_url(host: &str, owner: &str, repo: &str) -> String {
- format!("https://{}/{}/{}.git", host, owner, repo)
-}
-
/// Whether `tea` has a login configured for `host`.
///
/// Login discovery is local-only; the shared login probe below owns that
diff --git a/src/git/remote_ref/github.rs b/src/git/remote_ref/github.rs
index 9e3f1f879..187255f2f 100644
--- a/src/git/remote_ref/github.rs
+++ b/src/git/remote_ref/github.rs
@@ -213,8 +213,8 @@ pub(super) fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result
}
/// Get the git protocol preference from `gh` (GitHub CLI).
-fn use_ssh_protocol() -> bool {
- cli_config_value("gh", &["git_protocol"]).as_deref() == Some("ssh")
+fn use_ssh_protocol(host: &str) -> bool {
+ cli_config_value("gh", &["git_protocol", "--host", host]).as_deref() == Some("ssh")
}
/// Whether `gh` has an authentication token configured for `host`.
@@ -233,7 +233,7 @@ pub fn is_authed_for(host: &str) -> bool {
/// Construct the remote URL for a fork repository.
pub fn fork_remote_url(host: &str, owner: &str, repo: &str) -> String {
- if use_ssh_protocol() {
+ if use_ssh_protocol(host) {
format!("git@{}:{}/{}.git", host, owner, repo)
} else {
format!("https://{}/{}/{}.git", host, owner, repo)
diff --git a/src/git/remote_ref/gitlab.rs b/src/git/remote_ref/gitlab.rs
index 5000df5ec..b4b2bd0a9 100644
--- a/src/git/remote_ref/gitlab.rs
+++ b/src/git/remote_ref/gitlab.rs
@@ -152,6 +152,7 @@ pub fn fetch_gitlab_project_urls(
repo_root: &Path,
) -> anyhow::Result<GitLabForkUrls> {
let PlatformData::GitLab {
+ host,
source_project_id,
target_project_id,
..
@@ -179,7 +180,7 @@ pub fn fetch_gitlab_project_urls(
})?;
// Compute URLs based on protocol preference
- let use_ssh = git_protocol() == "ssh";
+ let use_ssh = git_protocol(host) == "ssh";
let fork_push_url = if use_ssh {
source_ssh.or(source_http)
} else {
@@ -253,15 +254,15 @@ pub fn is_authed_for(host: &str) -> bool {
}
/// Get the git protocol configured in `glab` (GitLab CLI).
-pub fn git_protocol() -> String {
- cli_config_value("glab", &["git_protocol"])
+fn git_protocol(host: &str) -> String {
+ cli_config_value("glab", &["git_protocol", "--host", host])
.filter(|p| p == "ssh" || p == "https")
.unwrap_or_else(|| "https".to_string())
}
/// Construct the remote URL for a GitLab project, respecting protocol preference.
pub fn fork_remote_url(host: &str, owner: &str, repo: &str) -> String {
- if git_protocol() == "ssh" {
+ if git_protocol(host) == "ssh" {
format!("git@{host}:{owner}/{repo}.git")
} else {
format!("https://{host}/{owner}/{repo}.git")
diff --git a/src/git/remote_ref/info.rs b/src/git/remote_ref/info.rs
index 5b4e98f2a..c4704ab07 100644
--- a/src/git/remote_ref/info.rs
+++ b/src/git/remote_ref/info.rs
@@ -24,8 +24,6 @@ pub enum PlatformData {
},
/// Gitea-specific data.
Gitea {
- /// Gitea host (e.g., "gitea.com", "git.example.com").
- host: String,
/// Owner of the head (source) repository.
head_owner: String,
/// Name of the head (source) repository.
@@ -34,6 +32,8 @@ pub enum PlatformData {
base_owner: String,
/// Name of the base (target) repository.
base_repo: String,
+ /// Clone URL supplied by Gitea, including its scheme, port, and path.
+ base_clone_url: String,
},
/// GitLab-specific data.
GitLab {
@@ -227,11 +227,11 @@ mod tests {
url: "https://git.example.com/owner/repo/pulls/42".to_string(),
fork_push_url: Some("https://git.example.com/contributor/repo.git".to_string()),
platform_data: PlatformData::Gitea {
- host: "git.example.com".to_string(),
head_owner: "contributor".to_string(),
head_repo: "repo".to_string(),
base_owner: "owner".to_string(),
base_repo: "repo".to_string(),
+ base_clone_url: "https://git.example.com/owner/repo.git".to_string(),
},
};
assert_eq!(info.ref_type(), RefType::Pr);
@@ -324,11 +324,11 @@ mod tests {
url: "https://git.example.com/owner/repo/pulls/101".to_string(),
fork_push_url: Some("https://git.example.com/contributor/repo.git".to_string()),
platform_data: PlatformData::Gitea {
- host: "git.example.com".to_string(),
head_owner: "contributor".to_string(),
head_repo: "repo".to_string(),
base_owner: "owner".to_string(),
base_repo: "repo".to_string(),
+ base_clone_url: "https://git.example.com/owner/repo.git".to_string(),
},
};
assert_eq!(
diff --git a/src/git/remote_ref/mod.rs b/src/git/remote_ref/mod.rs
index d337a4c86..a65d420cf 100644
--- a/src/git/remote_ref/mod.rs
+++ b/src/git/remote_ref/mod.rs
@@ -229,8 +229,8 @@ pub(super) fn cli_config_value(tool: &str, args: &[&str]) -> Option<String> {
///
/// Matches by owner/repo only (host is not required to match). This handles
/// SSH host aliases where the local hostname differs from the API hostname.
-/// The suggested URL in the error respects each platform's configured git
-/// protocol (SSH vs HTTPS).
+/// The suggested URL comes from the API when available, otherwise it respects
+/// the platform's configured git protocol (SSH vs HTTPS).
pub fn find_remote(repo: &Repository, info: &RemoteRefInfo) -> Result<String, GitError> {
// Azure DevOps URLs don't fit the host/owner/repo shape that `find_remote_for_repo`
// assumes (the parser stores `{org}/{project}/_git` in owner). Use the dedicated
@@ -275,12 +275,7 @@ pub fn find_remote(repo: &Repository, info: &RemoteRefInfo) -> Result<String, Gi
base_repo,
..
} => github::fork_remote_url(host, base_owner, base_repo),
- PlatformData::Gitea {
- host,
- base_owner,
- base_repo,
- ..
- } => gitea::fork_remote_url(host, base_owner, base_repo),
+ PlatformData::Gitea { base_clone_url, .. } => base_clone_url.clone(),
PlatformData::GitLab {
host,
base_owner,
diff --git a/src/main.rs b/src/main.rs
index 62440e12c..3c087ccb9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -597,7 +597,7 @@ fn handle_config_shell_command(action: ConfigShellCommand, yes: bool) -> anyhow:
} => {
// Auto-write to shell config files and completions
let cmd = cmd.unwrap_or_else(binary_name);
- handle_configure_shell(shell, yes, dry_run, cmd)
+ handle_configure_shell(shell, yes, dry_run, cmd.clone())
.map_err(anyhow::Error::from)
.and_then(|scan_result| {
// Exit with error if no shells configured
@@ -613,7 +613,7 @@ fn handle_config_shell_command(action: ConfigShellCommand, yes: bool) -> anyhow:
if dry_run {
return Ok(());
}
- crate::output::print_shell_install_result(&scan_result);
+ crate::output::print_shell_install_result(&scan_result, &cmd);
Ok(())
})
}
diff --git a/src/output/shell_integration.rs b/src/output/shell_integration.rs
index 7fa351a85..e38c1c1f4 100644
--- a/src/output/shell_integration.rs
+++ b/src/output/shell_integration.rs
@@ -322,7 +322,10 @@ fn print_config_action_result(action: &ConfigAction, message: String) {
/// - Restart hint for current shell
///
/// Used by both `wt config shell install` and the interactive prompt after `wt switch`.
-pub fn print_shell_install_result(scan_result: &crate::commands::configure_shell::ScanResult) {
+pub fn print_shell_install_result(
+ scan_result: &crate::commands::configure_shell::ScanResult,
+ cmd: &str,
+) {
// Count shells that became (more) configured
let shells_configured_count = scan_result
.configured
@@ -410,10 +413,18 @@ pub fn print_shell_install_result(scan_result: &crate::commands::configure_shell
}
// Zsh compinit advisory
- if scan_result.zsh_needs_compinit {
+ if scan_result.zsh_needs_compinit
+ && let Some(result) = scan_result
+ .configured
+ .iter()
+ .find(|result| result.shell == Shell::Zsh)
+ {
+ let path = format_path_for_display(&result.path);
eprintln!(
"{}",
- warning_message("Completions require compinit; add to ~/.zshrc before the wt line:",)
+ warning_message(format!(
+ "Completions require compinit; add to {path} before the {cmd} line:"
+ ))
);
eprintln!(
"{}",
@@ -554,7 +565,7 @@ pub fn prompt_shell_integration(
let install_result = apply_confirmed_shell_config(scan, None, binary_name)
.map_err(|e| e.context("Failed to configure shell integration"))?;
- print_shell_install_result(&install_result);
+ print_shell_install_result(&install_result, binary_name);
Ok(true)
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index efcee6652..a36b57592 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -639,6 +639,10 @@ pub fn add_standard_env_redactions(settings: &mut insta::Settings) {
settings.add_redaction(".env.PWD", "[PWD]");
// Mock commands directory (temp path for mock gh/glab binaries)
settings.add_redaction(".env.WORKTRUNK_TEST_MOCK_CONFIG_DIR", "[TEST_MOCK_CONFIG]");
+ settings.add_redaction(
+ ".env.WORKTRUNK_TEST_MOCK_CALL_LOG_DIR",
+ "[TEST_MOCK_CALL_LOG]",
+ );
// Nushell vendor-autoload override (temp path pinned by shell-integration tests)
settings.add_redaction(
".env.WORKTRUNK_TEST_NU_VENDOR_AUTOLOAD_DIR",
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 390775453..ac9b28dcd 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -753,16 +753,20 @@ fn test_config_show_zsh_compinit_warning(mut repo: TestRepo, temp_home: TempDir)
fs::create_dir_all(&global_config_dir).unwrap();
fs::write(global_config_dir.join("config.toml"), "").unwrap();
- // Create .zshrc WITHOUT compinit - completions won't work
+ // Use a custom zsh config directory so the advisory must name the same
+ // file as the integration detector.
+ let zdotdir = canonical_temp_home(&temp_home).join("zsh-config");
+ fs::create_dir_all(&zdotdir).unwrap();
fs::write(
- temp_home.path().join(".zshrc"),
+ zdotdir.join(".zshrc"),
r#"# wt integration but no compinit!
if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
"#,
)
.unwrap();
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let mut settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.add_redaction(".env.ZDOTDIR", "[TEST_ZDOTDIR]");
settings.bind(|| {
let mut cmd = repo.wt_command();
// Force compinit warning for deterministic tests across environments
@@ -770,6 +774,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
set_xdg_config_path(&mut cmd, temp_home.path());
+ cmd.env("ZDOTDIR", &zdotdir);
assert_cmd_snapshot!(cmd);
});
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 0fbd2169c..22c605b91 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -3577,8 +3577,10 @@ fn test_configure_shell_absolute_zdotdir_is_honoured(repo: TestRepo, temp_home:
set_temp_home_env(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/zsh");
cmd.env("ZDOTDIR", &zdotdir);
- cmd.env("WORKTRUNK_TEST_COMPINIT_CONFIGURED", "1");
- cmd.args(["config", "shell", "install", "zsh", "--yes"]);
+ cmd.env("WORKTRUNK_TEST_COMPINIT_MISSING", "1");
+ cmd.args([
+ "config", "shell", "install", "zsh", "--yes", "--cmd", "git-wt",
+ ]);
cmd.current_dir(repo.root_path());
let output = cmd.output().expect("install command should run");
@@ -3589,6 +3591,17 @@ fn test_configure_shell_absolute_zdotdir_is_honoured(repo: TestRepo, temp_home:
String::from_utf8_lossy(&output.stderr),
);
+ setup_home_snapshot_settings(&temp_home).bind(|| {
+ insta::assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"
+ ✓ Added shell extension & completions for zsh @ _PARENT_/zsh-config/.zshrc
+
+ ✓ Configured 1 shell
+ ▲ Completions require compinit; add to _PARENT_/zsh-config/.zshrc before the git-wt line:
+   autoload -Uz compinit && compinit
+ ↳ Restart shell to activate shell integration
+ ");
+ });
+
let zdotdir_contents = fs::read_to_string(zdotdir.join(".zshrc")).unwrap();
assert!(
zdotdir_contents.contains("config shell init zsh"),
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index 1bf7bbd18..1357288fe 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -464,6 +464,55 @@ fn test_statusline_reflects_checked_out_branch(mut repo: TestRepo) {
);
}
+/// A configured custom name can stand in for its branch, but must stop doing
+/// so after Git checks out a different branch in that directory.
+#[rstest]
+fn test_statusline_custom_layout_preserves_branch_drift(mut repo: TestRepo) {
+ repo.write_test_config(
+ "worktree-path = \"{{ repo_path }}/../{{ repo }}-{{ branch | sanitize }}\"\n",
+ );
+ let path = repo.root_path().parent().unwrap().join("repo-feature-auth");
+ let path = repo.add_worktree_at_path("feature-auth", &path);
+ let mut output = format!(
+ "configured layout:\n{}",
+ run_statusline_from_dir(&repo, &["--format=claude-code"], None, &path)
+ );
+ for branch in ["feature", "auth"] {
+ let checkout = repo
+ .git_command()
+ .args(["switch", "-c", branch])
+ .current_dir(&path)
+ .run()
+ .unwrap();
+ assert!(checkout.status.success());
+ output.push_str(&format!(
+ "\nafter git switch {branch}:\n{}",
+ run_statusline_from_dir(&repo, &["--format=claude-code"], None, &path)
+ ));
+ }
+
+ repo.run_git(&["switch", "-c", "repo"]);
+ output.push_str(&format!(
+ "\nprimary worktree:\n{}",
+ run_statusline(&repo, &["--format=claude-code"], None)
+ ));
+ claude_code_snapshot_settings().bind(|| {
+ assert_snapshot!(output, @"
+ configured layout:
+  [PATH]-feature-auth _
+
+ after git switch feature:
+  [PATH]-feature-auth feature _
+
+ after git switch auth:
+  [PATH]-feature-auth auth _
+
+ primary worktree:
+  [PATH] repo ^
+ ");
+ });
+}
+
#[rstest]
fn test_statusline_detached_head(mut repo: TestRepo) {
// Create a feature worktree
diff --git a/tests/integration_tests/step_prune.rs b/tests/integration_tests/step_prune.rs
index f86069cd3..0ec0e185a 100644
--- a/tests/integration_tests/step_prune.rs
+++ b/tests/integration_tests/step_prune.rs
@@ -1570,6 +1570,41 @@ fn test_prune_pre_remove_needs_approval(mut repo: TestRepo) {
);
}
+/// Approval hints compare the effective config source: an absolute override
+/// shares hooks across worktrees, while a relative override follows each root.
+#[rstest]
+#[case::absolute("prune_approval_absolute_project_config", true)]
+#[case::relative("prune_approval_relative_project_config", false)]
+fn test_prune_approval_project_config_override(
+ mut repo: TestRepo,
+ #[case] snapshot_name: &str,
+ #[case] absolute: bool,
+) {
+ let wt_path = repo.add_worktree("merged");
+ repo.commit("Advance default branch");
+ let config_name = "shared-hooks.toml";
+ let config_path = repo.root_path().join(config_name);
+ std::fs::write(&config_path, "pre-remove = \"exit 89\"\n").unwrap();
+ let override_path = if absolute {
+ config_path
+ } else {
+ config_name.into()
+ };
+
+ let mut cmd = make_snapshot_cmd(
+ &repo,
+ "step",
+ &["prune", "--foreground", "--min-age=0s"],
+ None,
+ );
+ cmd.env("WORKTRUNK_PROJECT_CONFIG_PATH", override_path);
+ assert_cmd_snapshot!(snapshot_name, cmd);
+ assert!(
+ wt_path.exists(),
+ "the unapproved worktree must remain in place"
+ );
+}
+
/// An unmerged worktree is outside prune's removal set, so the `pre-remove` it
/// would run is never part of the approval gate.
#[rstest]
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 848aea65f..435106b2e 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -3714,14 +3714,37 @@ fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {
"html_url": "https://github.com/owner/test-repo/pull/42"
}"#;
- let mock_bin = setup_mock_gh_for_pr(&repo, gh_response);
+ let mock_bin = repo.root_path().join("mock-bin");
+ fs::create_dir_all(&mock_bin).unwrap();
+
+ // The CLI supplies the protocol; record its arguments to verify that the
+ // lookup selects the API host rather than a global preference.
+ MockConfig::new("gh")
+ .command("api", MockResponse::output(gh_response))
+ .command("config get git_protocol", MockResponse::output("ssh\n"))
+ .command("_default", MockResponse::exit(1))
+ .write(&mock_bin);
+ let call_log = tempfile::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
configure_mock_cli_env(&mut cmd, &mock_bin);
+ cmd.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path());
assert_cmd_snapshot!("switch_pr_fork", cmd);
});
+ let calls = fs::read_to_string(call_log.path().join("gh.calls")).unwrap();
+ assert_eq!(
+ calls
+ .lines()
+ .find(|line| line.starts_with("config get git_protocol")),
+ Some("config get git_protocol --host github.com")
+ );
+ assert_eq!(
+ repo.git_output(&["config", "branch.feature-fix.pushRemote"])
+ .trim(),
+ "[email protected]:contributor/test-repo.git"
+ );
}
/// A failed fork `pr:N` switch leaves a branch it did not create alone.
@@ -5732,12 +5755,12 @@ fn test_switch_pr_gitea_create_conflict(#[from(repo_with_remote)] repo: TestRepo
"head": {
"label": "feature-auth",
"ref": "feature-auth",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
}"#;
@@ -5805,12 +5828,12 @@ fn test_switch_pr_gitea_same_repo(#[from(repo_with_remote)] mut repo: TestRepo)
"head": {
"label": "feature-auth",
"ref": "feature-auth",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
}"#;
@@ -5879,12 +5902,12 @@ fn test_switch_pr_gitea_fork(#[from(repo_with_remote)] repo: TestRepo) {
"head": {
"label": "contributor:feature-fix",
"ref": "feature-fix",
- "repo": {"name": "test-repo", "owner": {"login": "contributor"}}
+ "repo": {"name": "test-repo", "owner": {"login": "contributor"}, "clone_url": "http://gitea.example.com:3000/gitea/contributor/test-repo.git"}
},
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"html_url": "https://gitea.example.com/owner/test-repo/pulls/42"
}"#;
@@ -5897,6 +5920,51 @@ fn test_switch_pr_gitea_fork(#[from(repo_with_remote)] repo: TestRepo) {
configure_mock_cli_env(&mut cmd, &mock_bin);
assert_cmd_snapshot!("switch_pr_gitea_fork", cmd);
});
+ assert_eq!(
+ repo.git_output(&["config", "branch.feature-fix.pushRemote"])
+ .trim(),
+ "http://gitea.example.com:3000/gitea/contributor/test-repo.git"
+ );
+}
+
+/// A renamed base repository can resolve through the API while no configured
+/// remote matches its current owner. The recovery hint must retain Gitea's
+/// canonical clone URL rather than reconstructing it from the PR's web URL.
+#[rstest]
+fn test_switch_pr_gitea_missing_remote_uses_api_clone_url(
+ #[from(repo_with_remote)] repo: TestRepo,
+) {
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://gitea.example.com/old-owner/test-repo.git",
+ ]);
+
+ let tea_response = r#"{
+ "title": "Add feature fix for edge case",
+ "user": {"login": "contributor"},
+ "state": "open",
+ "head": {
+ "label": "contributor:feature-fix",
+ "ref": "feature-fix",
+ "repo": {"name": "test-repo", "owner": {"login": "contributor"}, "clone_url": "http://gitea.example.com:3000/gitea/contributor/test-repo.git"}
+ },
+ "base": {
+ "label": "main",
+ "ref": "main",
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "http://gitea.example.com:3000/gitea/owner/test-repo.git"}
+ },
+ "html_url": "https://gitea.example.com/owner/test-repo/pulls/42"
+ }"#;
+ let mock_bin = setup_mock_tea(&repo, "200 OK", tea_response);
+
+ let settings = setup_snapshot_settings(&repo);
+ settings.bind(|| {
+ let mut cmd = make_snapshot_cmd(&repo, "switch", &["pr:42"], None);
+ configure_mock_cli_env(&mut cmd, &mock_bin);
+ assert_cmd_snapshot!("switch_pr_gitea_missing_remote_uses_api_clone_url", cmd);
+ });
}
/// A missing PR reaches the user as Gitea's own message.
@@ -5974,12 +6042,12 @@ fn test_switch_pr_gitea_forge_platform(#[from(repo_with_remote)] repo: TestRepo)
"head": {
"label": "feature-auth",
"ref": "feature-auth",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://git.internal.example.com/owner/test-repo.git"}
},
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://git.internal.example.com/owner/test-repo.git"}
},
"html_url": "https://git.internal.example.com/owner/test-repo/pulls/101"
}"#;
@@ -6146,12 +6214,12 @@ fn test_switch_pr_self_hosted_tea_authed_dispatches_to_gitea(
"head": {
"label": "feature-auth",
"ref": "feature-auth",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://forge.selfhosted.test/owner/test-repo.git"}
},
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://forge.selfhosted.test/owner/test-repo.git"}
},
"html_url": "https://forge.selfhosted.test/owner/test-repo/pulls/101"
}"#;
@@ -6444,12 +6512,12 @@ fn test_switch_pr_gitea_no_source_branch(#[from(repo_with_remote)] repo: TestRep
"head": {
"label": "",
"ref": "",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
}"#;
@@ -6488,7 +6556,7 @@ fn test_switch_pr_gitea_deleted_fork(#[from(repo_with_remote)] repo: TestRepo) {
"base": {
"label": "main",
"ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}
},
"html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
}"#;
@@ -6611,9 +6679,9 @@ fn test_switch_pr_gitea_no_status_line(#[from(repo_with_remote)] repo: TestRepo)
"user": {"login": "alice"},
"state": "open",
"head": {"label": "feature", "ref": "feature",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}},
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}},
"base": {"label": "main", "ref": "main",
- "repo": {"name": "test-repo", "owner": {"login": "owner"}}},
+ "repo": {"name": "test-repo", "owner": {"login": "owner"}, "clone_url": "https://gitea.example.com/owner/test-repo.git"}},
"html_url": "https://gitea.example.com/owner/test-repo/pulls/101"
}"#,
),
@@ -7757,6 +7825,13 @@ fn test_switch_mr_fork(#[from(repo_with_remote)] repo: TestRepo) {
"https://gitlab.com/owner/test-repo.git",
]);
+ repo.run_git(&[
+ "config",
+ "--add",
+ &format!("url.{}.insteadOf", bare_url),
+ "[email protected]:owner/test-repo.git",
+ ]);
+
// Set up mock glab with separate responses for MR API and project APIs.
// Mock playback supports compound keys like "api projects/456" to match
// different API paths.
@@ -7804,15 +7879,30 @@ fn test_switch_mr_fork(#[from(repo_with_remote)] repo: TestRepo) {
"api projects/123",
MockResponse::output(target_project_response),
)
+ .command("config get git_protocol", MockResponse::output("ssh\n"))
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
+ let call_log = tempfile::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["mr:42"], None);
configure_mock_cli_env(&mut cmd, &mock_bin);
+ cmd.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path());
assert_cmd_snapshot!("switch_mr_fork", cmd);
});
+ let calls = fs::read_to_string(call_log.path().join("glab.calls")).unwrap();
+ assert_eq!(
+ calls
+ .lines()
+ .find(|line| line.starts_with("config get git_protocol")),
+ Some("config get git_protocol --host gitlab.com")
+ );
+ assert_eq!(
+ repo.git_output(&["config", "branch.feature-fix.pushRemote"])
+ .trim(),
+ "[email protected]:contributor/test-repo.git"
+ );
}
/// A failing `glab api projects/<id>` surfaces glab's own verdict.
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap
index ac2dee224..d996aa9f7 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap
@@ -54,6 +54,7 @@ info:
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+ ZDOTDIR: "[TEST_ZDOTDIR]"
---
success: true
exit_code: 0
@@ -69,9 +70,9 @@ exit_code: 0
▲ Shell integration not active
  Invoked as: [PROJECT_ROOT]/target/[BUILD_MODE]/wt
-○ zsh: Already configured shell extension & completions @ ~/.zshrc:2
+○ zsh: Already configured shell extension & completions @ _PARENT_/zsh-config/.zshrc:2
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
-▲ Completions won't work; add to ~/.zshrc before the wt line:
+▲ Completions won't work; add to _PARENT_/zsh-config/.zshrc before the wt line:
  autoload -Uz compinit && compinit
OTHER
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_approval_absolute_project_config.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_approval_absolute_project_config.snap
new file mode 100644
index 000000000..db1dbc945
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_approval_absolute_project_config.snap
@@ -0,0 +1,69 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--foreground"
+ - "--min-age=0s"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_ALLOW_PROTOCOL: file
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_AUTHOR_EMAIL: [email protected]
+ GIT_AUTHOR_NAME: Test User
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_EMAIL: [email protected]
+ GIT_COMMITTER_NAME: Test User
+ GIT_CONFIG_COUNT: "2"
+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
+ GIT_CONFIG_KEY_0: user.useConfigOnly
+ GIT_CONFIG_KEY_1: rerere.enabled
+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
+ GIT_CONFIG_VALUE_0: "true"
+ GIT_CONFIG_VALUE_1: "false"
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_PROJECT_CONFIG_PATH: "[TEST_PROJECT_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Skipped merged (approval required)
+↳ Pre-approve hooks for the current worktree with wt config approvals add:
+  pre-remove: exit 89
+↳ Or remove specific worktrees individually:
+  wt -C _REPO_.merged remove
diff --git a/tests/snapshots/integration__integration_tests__step_prune__prune_approval_relative_project_config.snap b/tests/snapshots/integration__integration_tests__step_prune__prune_approval_relative_project_config.snap
new file mode 100644
index 000000000..2444803ba
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__step_prune__prune_approval_relative_project_config.snap
@@ -0,0 +1,69 @@
+---
+source: tests/integration_tests/step_prune.rs
+info:
+ program: wt
+ args:
+ - step
+ - prune
+ - "--foreground"
+ - "--min-age=0s"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_ALLOW_PROTOCOL: file
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_AUTHOR_EMAIL: [email protected]
+ GIT_AUTHOR_NAME: Test User
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_EMAIL: [email protected]
+ GIT_COMMITTER_NAME: Test User
+ GIT_CONFIG_COUNT: "2"
+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
+ GIT_CONFIG_KEY_0: user.useConfigOnly
+ GIT_CONFIG_KEY_1: rerere.enabled
+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
+ GIT_CONFIG_VALUE_0: "true"
+ GIT_CONFIG_VALUE_1: "false"
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_PROJECT_CONFIG_PATH: "[TEST_PROJECT_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Skipped merged (approval required)
+↳ Pre-approve hooks for the current worktree with wt config approvals add:
+  pre-remove: exit 89
+↳ Or remove specific worktrees individually:
+  wt -C _REPO_.merged remove (different hooks on branch)
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_mr_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_mr_fork.snap
index 94e8a8616..2bad11338 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_mr_fork.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_mr_fork.snap
@@ -43,6 +43,7 @@ info:
WORKTRUNK_TEST_EPOCH: "1735776000"
WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CALL_LOG_DIR: "[TEST_MOCK_CALL_LOG]"
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
@@ -62,7 +63,7 @@ exit_code: 0
◎ Fetching MR !42...
  Add feature fix for edge case (!42)
  by @contributor · opened · feature-fix · https://gitlab.com/owner/test-repo/-/merge_requests/42
-○ Push configured to fork: https://gitlab.com/contributor/test-repo.git
+○ Push configured to fork: [[email protected]:contributor/test-repo.git
✓ Created branch feature-fix (tracking MR !42) and worktree @ _REPO_.feature-fix
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap
index 2fdfd8a31..b4b38ab81 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_fork.snap
@@ -43,6 +43,7 @@ info:
WORKTRUNK_TEST_EPOCH: "1735776000"
WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CALL_LOG_DIR: "[TEST_MOCK_CALL_LOG]"
WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
@@ -62,7 +63,7 @@ exit_code: 0
◎ Fetching PR #42...
  Add feature fix for edge case (#42)
  by @contributor · open · contributor:feature-fix · https://github.com/owner/test-repo/pull/42
-○ Push configured to fork: https://github.com/contributor/test-repo.git
+○ Push configured to fork: [[email protected]:contributor/test-repo.git
✓ Created branch feature-fix (tracking PR #42) and worktree @ _REPO_.feature-fix
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap
index 707f57482..eef89d862 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_fork.snap
@@ -62,7 +62,7 @@ exit_code: 0
◎ Fetching PR #42...
  Add feature fix for edge case (#42)
  by @contributor · open · contributor:feature-fix · https://gitea.example.com/owner/test-repo/pulls/42
-○ Push configured to fork: https://gitea.example.com/contributor/test-repo.git
+○ Push configured to fork: http://gitea.example.com:3000/gitea/contributor/test-repo.git
✓ Created branch feature-fix (tracking PR #42) and worktree @ _REPO_.feature-fix
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_missing_remote_uses_api_clone_url.snap b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_missing_remote_uses_api_clone_url.snap
new file mode 100644
index 000000000..ae90bca36
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__switch__switch_pr_gitea_missing_remote_uses_api_clone_url.snap
@@ -0,0 +1,66 @@
+---
+source: tests/integration_tests/switch.rs
+info:
+ program: wt
+ args:
+ - switch
+ - "pr:42"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLAUDE_CONFIG_DIR: "[TEST_CLAUDE_CONFIG]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_ALLOW_PROTOCOL: file
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_AUTHOR_EMAIL: [email protected]
+ GIT_AUTHOR_NAME: Test User
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_EMAIL: [email protected]
+ GIT_COMMITTER_NAME: Test User
+ GIT_CONFIG_COUNT: "2"
+ GIT_CONFIG_GLOBAL: /nonexistent/wt/gitconfig
+ GIT_CONFIG_KEY_0: user.useConfigOnly
+ GIT_CONFIG_KEY_1: rerere.enabled
+ GIT_CONFIG_SYSTEM: /nonexistent/wt/gitconfig
+ GIT_CONFIG_VALUE_0: "true"
+ GIT_CONFIG_VALUE_1: "false"
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ LLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_CODEX_INSTALLED: "0"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
+ WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_PROBE_TIMEOUT_MS: "60000"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: false
+exit_code: 1
+----- stdout -----
+
+----- stderr -----
+◎ Fetching PR #42...
+  Add feature fix for edge case (#42)
+  by @contributor · open · contributor:feature-fix · https://gitea.example.com/owner/test-repo/pulls/42
+✗ No remote found for owner/test-repo
+↳ Add the remote: git remote add upstream http://gitea.example.com:3000/gitea/owner/test-repo.git