Skip to content

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

Simplify forge detection with `[forge]` config section (#1826)

Maximilian Roosb33cc8e9d6e0
diff --git a/dev/wt.example.toml b/dev/wt.example.toml
index daa45ae73..dc27c616f 100644
--- a/dev/wt.example.toml
+++ b/dev/wt.example.toml
@@ -100,10 +100,11 @@
# url = "http://localhost:{{ branch | hash_port }}"
# ============================================================================
-# CI Platform Override
+# Forge (GitHub/GitLab) Settings
# ============================================================================
-# Override CI platform detection for GitHub Enterprise or self-hosted GitLab
-# with custom domains where URL detection fails.
+# Override platform detection for SSH host aliases or custom domains.
+# Set hostname for GitHub Enterprise or self-hosted GitLab API calls.
#
-# [ci]
-# platform = "github" # or "gitlab"
+# [forge]
+# platform = "github" # or "gitlab"
+# hostname = "github.example.com" # API host (GHE / self-hosted GitLab)
diff --git a/docs/content/config.md b/docs/content/config.md
index 4f427cf44..871205249 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -357,9 +357,10 @@ See [`wt hook`](@/hook.md) for hook types, execution order, template variables,
[list]
url = "http://localhost:{{ branch | hash_port }}"
-# Override CI platform detection for self-hosted instances
-[ci]
+# Override platform detection for SSH aliases or self-hosted instances
+[forge]
platform = "github" # or "gitlab"
+# hostname = "github.example.com" # API host (GHE / self-hosted GitLab)
# Add more gitignored excludes for wt step copy-ignored
[step.copy-ignored]
@@ -635,7 +636,7 @@ CI status cache.
Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
-Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `ci.platform = "github"` in `.config/wt.toml` for self-hosted instances.
+Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index e48157447..81b335d98 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -354,9 +354,10 @@ See [`wt hook`](https://worktrunk.dev/hook/) for hook types, execution order, te
[list]
url = "http://localhost:{{ branch | hash_port }}"
-# Override CI platform detection for self-hosted instances
-[ci]
+# Override platform detection for SSH aliases or self-hosted instances
+[forge]
platform = "github" # or "gitlab"
+# hostname = "github.example.com" # API host (GHE / self-hosted GitLab)
# Add more gitignored excludes for wt step copy-ignored
[step.copy-ignored]
@@ -654,7 +655,7 @@ CI status cache.
Caches GitHub/GitLab CI status for display in [`wt list`](https://worktrunk.dev/list/#ci-status).
-Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `ci.platform = "github"` in `.config/wt.toml` for self-hosted instances.
+Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 3305f6b1f..011ba11b4 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -378,7 +378,7 @@ Without a subcommand, runs `get`. Use `set` to override or `clear` to reset."#
name = "ci-status",
after_long_help = r#"Caches GitHub/GitLab CI status for display in [`wt list`](@/list.md#ci-status).
-Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `ci.platform = "github"` in `.config/wt.toml` for self-hosted instances.
+Requires `gh` (GitHub) or `glab` (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with `forge.platform = "github"` in `.config/wt.toml` for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set `forge.hostname`.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index a6abfa934..31a565805 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1924,9 +1924,10 @@ See [`wt hook`](@/hook.md) for hook types, execution order, template variables,
[list]
url = "http://localhost:{{ branch | hash_port }}"
-# Override CI platform detection for self-hosted instances
-[ci]
+# Override platform detection for SSH aliases or self-hosted instances
+[forge]
platform = "github" # or "gitlab"
+# hostname = "github.example.com" # API host (GHE / self-hosted GitLab)
# Add more gitignored excludes for wt step copy-ignored
[step.copy-ignored]
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 4a1bc6086..fa931a402 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -263,9 +263,7 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
// Check CI tool based on detected platform (with config override support)
let repo = Repository::current()?;
- let project_config = repo.load_project_config().ok().flatten();
- let platform_override = project_config.as_ref().and_then(|c| c.ci_platform());
- let platform = platform_for_repo(&repo, platform_override, None);
+ let platform = platform_for_repo(&repo, None);
match platform {
Some(CiPlatform::GitHub) => {
@@ -368,10 +366,11 @@ fn render_system_config(out: &mut String) -> anyhow::Result<bool> {
writeln!(out, "{}", error_message("Invalid config"))?;
writeln!(out, "{}", format_with_gutter(&e.to_string(), None))?;
} else {
- // Only check for unknown keys if config is valid
- out.push_str(&warn_unknown_keys::<UserConfig>(&find_unknown_user_keys(
- &contents,
- )));
+ let unknown_keys: std::collections::HashMap<_, _> = find_unknown_user_keys(&contents)
+ .into_iter()
+ .filter(|(k, _)| !worktrunk::config::DEPRECATED_SECTION_KEYS.contains(&k.as_str()))
+ .collect();
+ out.push_str(&warn_unknown_keys::<UserConfig>(&unknown_keys));
}
// Display TOML with syntax highlighting
@@ -435,10 +434,14 @@ fn render_user_config(out: &mut String, has_system_config: bool) -> anyhow::Resu
writeln!(out, "{}", error_message("Invalid config"))?;
writeln!(out, "{}", format_with_gutter(&e.to_string(), None))?;
} else {
- // Only check for unknown keys if config is valid
- out.push_str(&warn_unknown_keys::<UserConfig>(&find_unknown_user_keys(
- &contents,
- )));
+ // Only check for unknown keys if config is valid.
+ // Filter deprecated section keys to avoid duplicate warnings
+ // (deprecation system already warns about these).
+ let unknown_keys: std::collections::HashMap<_, _> = find_unknown_user_keys(&contents)
+ .into_iter()
+ .filter(|(k, _)| !worktrunk::config::DEPRECATED_SECTION_KEYS.contains(&k.as_str()))
+ .collect();
+ out.push_str(&warn_unknown_keys::<UserConfig>(&unknown_keys));
}
// Add "Current config" label when deprecations shown (to separate from diff)
diff --git a/src/commands/config/state.rs b/src/commands/config/state.rs
index 731d2a277..a936bcaf7 100644
--- a/src/commands/config/state.rs
+++ b/src/commands/config/state.rs
@@ -337,7 +337,7 @@ pub fn handle_state_get(key: &str, branch: Option<String>) -> anyhow::Result<()>
.into());
}
- let ci_branch = CiBranchName::from_branch_ref(&branch_name, is_remote, &repo);
+ let ci_branch = CiBranchName::from_branch_ref(&branch_name, is_remote);
let ci_status = PrStatus::detect(&repo, &ci_branch, &head)
.map_or(super::super::list::ci_status::CiStatus::NoCI, |s| {
s.ci_status
diff --git a/src/commands/list/ci_status/github.rs b/src/commands/list/ci_status/github.rs
index ade710228..0dfb1f392 100644
--- a/src/commands/list/ci_status/github.rs
+++ b/src/commands/list/ci_status/github.rs
@@ -10,15 +10,14 @@ use super::{
non_interactive_cmd, parse_json,
};
-/// Get the owner and repo name from any GitHub remote.
+/// Get the owner and repo name from the primary remote.
///
/// Used for GitHub API calls that require `repos/{owner}/{repo}/...` paths.
-/// Searches all remotes for a GitHub URL (API calls are repo-wide, not branch-specific).
-///
-/// Uses [`Repository::find_forge_remote`] with effective URLs to handle
-/// `url.insteadOf` aliases.
+/// Platform is already known to be GitHub when this runs, so we extract
+/// directly from the primary remote's raw URL without checking the hostname.
fn github_owner_repo(repo: &Repository) -> Option<(String, String)> {
- let (_, url) = repo.find_forge_remote(|parsed| parsed.is_github())?;
+ let remote = repo.primary_remote().ok()?;
+ let url = repo.remote_url(&remote)?;
parse_owner_repo(&url)
}
@@ -175,14 +174,23 @@ pub(super) fn detect_github_commit_checks(
let (owner, repo_name) =
github_owner_repo_for_branch(repo, branch).or_else(|| github_owner_repo(repo))?;
+ // Only pass --hostname when explicitly configured (for GHE / self-hosted)
+ let hostname = repo
+ .load_project_config()
+ .ok()
+ .flatten()
+ .and_then(|c| c.forge_hostname().map(String::from));
+
// Use GitHub's check-runs API to get all checks for this commit
+ let api_path = format!("repos/{owner}/{repo_name}/commits/{local_head}/check-runs");
+ let mut args = vec!["api", api_path.as_str()];
+ if let Some(h) = &hostname {
+ args.extend(["--hostname", h.as_str()]);
+ }
+ args.extend(["--jq", ".check_runs | map({status, conclusion})"]);
+
let output = match non_interactive_cmd("gh")
- .args([
- "api",
- &format!("repos/{owner}/{repo_name}/commits/{local_head}/check-runs"),
- "--jq",
- ".check_runs | map({status, conclusion})",
- ])
+ .args(args)
.current_dir(&repo_root)
.run()
{
diff --git a/src/commands/list/ci_status/mod.rs b/src/commands/list/ci_status/mod.rs
index 7d83d7f9e..10d0e602b 100644
--- a/src/commands/list/ci_status/mod.rs
+++ b/src/commands/list/ci_status/mod.rs
@@ -36,39 +36,17 @@ pub struct CiBranchName {
impl CiBranchName {
/// Create from a branch name with authoritative `is_remote` flag.
///
- /// For remote branches (e.g., "origin/feature"), extracts the remote name
- /// and bare branch name by finding the matching remote prefix.
+ /// For remote branches (e.g., "origin/feature"), splits at the first `/`
+ /// to extract the remote name and bare branch name.
/// For local branches, the name is already bare.
///
/// The `is_remote` flag should come from an authoritative source:
/// - `BranchRef::is_remote` (from collection phase)
/// - `git show-ref --verify refs/remotes/<branch>` (for CLI input)
- pub fn from_branch_ref(branch: &str, is_remote: bool, repo: &Repository) -> Self {
+ pub fn from_branch_ref(branch: &str, is_remote: bool) -> Self {
if is_remote {
- // Remote branch - find the remote prefix to extract bare name
- for (remote_name, _) in repo.all_remote_urls() {
- let prefix = format!("{}/", remote_name);
- if let Some(name) = branch.strip_prefix(&prefix) {
- log::debug!(
- "Remote branch {} -> remote={}, name={}",
- branch,
- remote_name,
- name
- );
- return Self {
- full_name: branch.to_string(),
- remote: Some(remote_name),
- name: name.to_string(),
- };
- }
- }
- // Fallback: couldn't find matching remote, use first segment as remote
+ // Remote branch — split "origin/feature" into remote + bare name.
if let Some((remote, name)) = branch.split_once('/') {
- log::warn!(
- "Remote branch {} has unknown remote '{}', using as-is",
- branch,
- remote
- );
return Self {
full_name: branch.to_string(),
remote: Some(remote.to_string()),
@@ -76,7 +54,7 @@ impl CiBranchName {
};
}
}
- // Local branch - name is already bare
+ // Local branch — name is already bare
Self {
full_name: branch.to_string(),
remote: None,
@@ -390,7 +368,7 @@ impl PrStatus {
///
/// Platform is determined by project config override or remote URL detection.
/// Returns `None` if the platform cannot be determined (user should set
- /// `ci.platform` in project config for non-standard hostnames).
+ /// `forge.platform` in project config for non-standard hostnames).
/// PR/MR detection always runs. Workflow/pipeline fallback only runs if `has_upstream`.
fn detect_uncached(
repo: &Repository,
@@ -398,21 +376,16 @@ impl PrStatus {
local_head: &str,
has_upstream: bool,
) -> Option<Self> {
- // Load project config for platform override (cached in Repository)
- let project_config = repo.load_project_config().ok().flatten();
- let platform_override = project_config.as_ref().and_then(|c| c.ci_platform());
-
- // Determine platform (config override, branch's remote, or any remote URL)
- // For remote branches, use their specific remote to get the correct platform
- let platform = platform_for_repo(repo, platform_override, branch.remote.as_deref());
+ // Determine platform (config override, branch's remote, or primary remote URL)
+ let platform = platform_for_repo(repo, branch.remote.as_deref());
match platform {
Some(p) => p.detect_ci(repo, branch, local_head, has_upstream),
None => {
- // Unknown platform - user should set ci.platform in project config
+ // Unknown platform — user should set forge.platform in project config
log::debug!(
"Could not detect CI platform from remote URL; \
- set ci.platform in .config/wt.toml for CI status"
+ set forge.platform in .config/wt.toml for CI status"
);
None
}
diff --git a/src/commands/list/ci_status/platform.rs b/src/commands/list/ci_status/platform.rs
index 759385618..15497f077 100644
--- a/src/commands/list/ci_status/platform.rs
+++ b/src/commands/list/ci_status/platform.rs
@@ -32,7 +32,7 @@ impl CiToolsAvailable {
/// CI platform detected from project config override or remote URL.
///
/// Platform is determined by:
-/// 1. Project config `ci.platform = "github"` or `"gitlab"` (takes precedence)
+/// 1. Project config `forge.platform` (or deprecated `ci.platform`)
/// 2. Remote URL detection (searches for "github" or "gitlab" in hostname)
#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::Display, strum::EnumString)]
#[strum(serialize_all = "lowercase")]
@@ -117,19 +117,20 @@ pub fn detect_platform_from_url(url: &str) -> Option<CiPlatform> {
/// Get the CI platform for a repository, optionally prioritizing a specific remote.
///
/// Priority order:
-/// 1. Project config `ci.platform` override (if provided)
-/// 2. The specific remote's URL (if `remote_hint` is provided)
-/// 3. Any remote URL that matches a known platform
+/// 1. Project config `forge.platform` (or deprecated `ci.platform`)
+/// 2. The specific remote's effective URL (if `remote_hint` is provided)
+/// 3. The primary remote's effective URL
///
/// For remote branches, pass the branch's remote as `remote_hint` to ensure
/// the correct platform is detected in mixed-remote repos (e.g., GitHub + GitLab).
-pub fn platform_for_repo(
- repo: &Repository,
- platform_override: Option<&str>,
- remote_hint: Option<&str>,
-) -> Option<CiPlatform> {
+pub fn platform_for_repo(repo: &Repository, remote_hint: Option<&str>) -> Option<CiPlatform> {
// Config override takes precedence
- if let Some(platform_str) = platform_override {
+ if let Some(platform_str) = repo
+ .load_project_config()
+ .ok()
+ .flatten()
+ .and_then(|c| c.forge_platform().map(str::to_string))
+ {
if let Ok(platform) = platform_str.parse::<CiPlatform>() {
log::debug!("Using CI platform from config override: {}", platform);
return Some(platform);
@@ -154,17 +155,12 @@ pub fn platform_for_repo(
return Some(platform);
}
- // Search all remotes for a supported platform.
- // Uses find_forge_remote which checks effective URLs (with insteadOf applied).
- if let Some((remote_name, url)) =
- repo.find_forge_remote(|parsed| parsed.is_github() || parsed.is_gitlab())
+ // Fall back to primary remote's effective URL.
+ if let Some(remote) = repo.primary_remote().ok()
+ && let Some(url) = repo.effective_remote_url(&remote)
+ && let Some(platform) = detect_platform_from_url(&url)
{
- let platform = detect_platform_from_url(&url)?;
- log::debug!(
- "Detected CI platform {} from remote '{}'",
- platform,
- remote_name
- );
+ log::debug!("Detected CI platform {} from remote '{}'", platform, remote);
return Some(platform);
}
diff --git a/src/commands/list/collect/tasks.rs b/src/commands/list/collect/tasks.rs
index 78b4e3141..13ff7b975 100644
--- a/src/commands/list/collect/tasks.rs
+++ b/src/commands/list/collect/tasks.rs
@@ -605,7 +605,7 @@ impl Task for CiStatusTask {
let pr_status = ctx.branch_ref.branch.as_deref().and_then(|branch| {
// Use from_branch_ref with the authoritative is_remote flag
// rather than guessing from the branch name
- let ci_branch = CiBranchName::from_branch_ref(branch, ctx.branch_ref.is_remote, repo);
+ let ci_branch = CiBranchName::from_branch_ref(branch, ctx.branch_ref.is_remote);
PrStatus::detect(repo, &ci_branch, &ctx.branch_ref.commit_sha)
});
diff --git a/src/config/deprecation.rs b/src/config/deprecation.rs
index 42272aa8f..67423d54e 100644
--- a/src/config/deprecation.rs
+++ b/src/config/deprecation.rs
@@ -69,7 +69,7 @@ const DEPRECATED_VARS: &[(&str, &str)] = &[
/// Top-level section keys that are deprecated and handled separately.
/// Callers should filter these out before calling `warn_unknown_fields` to avoid duplicate warnings.
-pub const DEPRECATED_SECTION_KEYS: &[&str] = &["commit-generation", "select"];
+pub const DEPRECATED_SECTION_KEYS: &[&str] = &["commit-generation", "select", "ci"];
/// Normalize a template string by replacing deprecated variables with their canonical names.
///
@@ -200,6 +200,8 @@ pub struct Deprecations {
pub select: bool,
/// Has `[hooks.post-create]` (renamed to `[hooks.pre-start]`)
pub post_create: bool,
+ /// Has `[ci]` section (moved to `[forge]`)
+ pub ci_section: bool,
}
impl Deprecations {
@@ -210,6 +212,7 @@ impl Deprecations {
&& !self.approved_commands
&& !self.select
&& !self.post_create
+ && !self.ci_section
}
}
@@ -224,6 +227,7 @@ pub fn detect_deprecations(content: &str) -> Deprecations {
approved_commands: find_approved_commands_deprecation(content),
select: find_select_deprecation(content),
post_create: find_post_create_deprecation(content),
+ ci_section: find_ci_section_deprecation(content),
}
}
@@ -663,6 +667,74 @@ pub fn migrate_select_to_switch_picker(content: &str) -> String {
doc.to_string()
}
+/// Check if config has a deprecated `[ci]` section without a corresponding `[forge]`.
+///
+/// Returns true if `[ci]` exists with a non-empty `platform` field and `[forge]` does not exist.
+pub fn find_ci_section_deprecation(content: &str) -> bool {
+ let Ok(doc) = content.parse::<toml_edit::DocumentMut>() else {
+ return false;
+ };
+
+ // Skip if [forge] already exists
+ if doc
+ .get("forge")
+ .is_some_and(|f| f.is_table() || f.is_inline_table())
+ {
+ return false;
+ }
+
+ // Check if [ci] exists with a non-empty platform field
+ doc.get("ci")
+ .and_then(|ci| ci.as_table())
+ .and_then(|t| t.get("platform"))
+ .is_some_and(|p| {
+ p.as_str()
+ .or_else(|| p.as_value().and_then(|v| v.as_str()))
+ .is_some_and(|s| !s.is_empty())
+ })
+}
+
+/// Migrate `[ci]` section to `[forge]`.
+///
+/// Moves `platform` from `[ci]` to `[forge]`, preserving the value.
+/// Removes `[ci]` if `platform` was its only field.
+/// Skips migration if `[forge]` already exists.
+pub fn migrate_ci_to_forge(content: &str) -> String {
+ let Ok(mut doc) = content.parse::<toml_edit::DocumentMut>() else {
+ return content.to_string();
+ };
+
+ // Skip if [forge] already exists
+ if doc
+ .get("forge")
+ .is_some_and(|f| f.is_table() || f.is_inline_table())
+ {
+ return content.to_string();
+ }
+
+ // Get platform value from [ci]
+ let platform = doc
+ .get("ci")
+ .and_then(|ci| ci.as_table())
+ .and_then(|t| t.get("platform"))
+ .and_then(|p| p.as_str())
+ .map(String::from);
+
+ let Some(platform) = platform else {
+ return content.to_string();
+ };
+
+ // Remove [ci] section (it only has platform)
+ doc.remove("ci");
+
+ // Create [forge] section with platform
+ let mut forge_table = toml_edit::Table::new();
+ forge_table.insert("platform", toml_edit::value(platform));
+ doc.insert("forge", toml_edit::Item::Table(forge_table));
+
+ doc.to_string()
+}
+
/// Copy approved-commands from config.toml to approvals.toml.
///
/// Called during migration to ensure approved-commands are preserved before
@@ -955,6 +1027,9 @@ pub fn write_migration_file(
if deprecations.post_create {
new_content = migrate_post_create_to_pre_start(&new_content);
}
+ if deprecations.ci_section {
+ new_content = migrate_ci_to_forge(&new_content);
+ }
if let Err(e) = std::fs::write(&new_path, &new_content) {
// Log write failure but don't block config loading
@@ -1085,6 +1160,17 @@ pub fn format_deprecation_warnings(info: &DeprecationInfo) -> String {
);
}
+ if info.deprecations.ci_section {
+ let _ = writeln!(
+ out,
+ "{}",
+ warning_message(format!(
+ "{} uses deprecated config section: [ci] → [forge]",
+ info.label
+ ))
+ );
+ }
+
out
}
@@ -2124,6 +2210,7 @@ approved-commands = ["npm install"]
approved_commands: true,
select: false,
post_create: false,
+ ci_section: false,
},
label: "User config".to_string(),
main_worktree_path: None,
@@ -2153,6 +2240,7 @@ approved-commands = ["npm install"]
approved_commands: true,
select: false,
post_create: false,
+ ci_section: false,
},
label: "User config".to_string(),
main_worktree_path: None,
@@ -2183,6 +2271,7 @@ approved-commands = ["npm install"]
approved_commands: true,
select: false,
post_create: false,
+ ci_section: false,
};
let result = write_migration_file(&config_path, content, &deprecations, None);
assert!(
@@ -2442,6 +2531,7 @@ branches = true
approved_commands: false,
select: true,
post_create: false,
+ ci_section: false,
},
label: "User config".to_string(),
main_worktree_path: None,
@@ -2475,6 +2565,7 @@ pager = "delta --paging=never"
approved_commands: false,
select: true,
post_create: false,
+ ci_section: false,
};
let result = write_migration_file(&config_path, content, &deprecations, None);
assert!(result.is_some(), "Should write migration file for select");
@@ -2722,6 +2813,7 @@ server = "npm run dev"
approved_commands: false,
select: false,
post_create: true,
+ ci_section: false,
},
label: "Project config".to_string(),
main_worktree_path: None,
@@ -2755,6 +2847,7 @@ server = "npm run dev"
approved_commands: false,
select: false,
post_create: true,
+ ci_section: false,
};
let result = write_migration_file(&config_path, content, &deprecations, None);
assert!(
diff --git a/src/config/project.rs b/src/config/project.rs
index 8608cb800..4762124bd 100644
--- a/src/config/project.rs
+++ b/src/config/project.rs
@@ -56,6 +56,35 @@ pub struct ProjectCiConfig {
pub platform: Option<String>,
}
+/// Project-level forge configuration.
+///
+/// Override forge detection when URL-based detection fails (e.g., SSH host
+/// aliases, GitHub Enterprise, or self-hosted GitLab with custom domains).
+///
+/// # Example
+///
+/// ```toml
+/// [forge]
+/// platform = "github" # or "gitlab"
+/// hostname = "github.example.com" # API hostname for GHE / self-hosted GitLab
+/// ```
+#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, JsonSchema)]
+pub struct ProjectForgeConfig {
+ /// Forge platform override. When set, skips URL-based platform detection.
+ ///
+ /// Values: "github" or "gitlab"
+ #[serde(default)]
+ pub platform: Option<String>,
+
+ /// API hostname for GitHub Enterprise or self-hosted GitLab.
+ ///
+ /// Only needed when the remote URL uses an SSH host alias that doesn't
+ /// resolve to the real API hostname. For standard github.com/gitlab.com
+ /// setups, this is not needed.
+ #[serde(default)]
+ pub hostname: Option<String>,
+}
+
impl ProjectListConfig {
/// Returns true if any list configuration is set.
pub fn is_configured(&self) -> bool {
@@ -65,10 +94,25 @@ impl ProjectListConfig {
impl ProjectConfig {
/// Get the CI platform override if configured.
+ ///
+ /// Deprecated: use [`forge_platform()`](Self::forge_platform) instead.
pub fn ci_platform(&self) -> Option<&str> {
self.ci.as_ref().and_then(|ci| ci.platform.as_deref())
}
+ /// Get the forge platform override, checking `[forge]` first then `[ci]`.
+ pub fn forge_platform(&self) -> Option<&str> {
+ self.forge
+ .as_ref()
+ .and_then(|f| f.platform.as_deref())
+ .or_else(|| self.ci_platform())
+ }
+
+ /// Get the forge API hostname if configured.
+ pub fn forge_hostname(&self) -> Option<&str> {
+ self.forge.as_ref().and_then(|f| f.hostname.as_deref())
+ }
+
/// Get `wt step copy-ignored` configuration if configured.
pub fn copy_ignored(&self) -> Option<&CopyIgnoredConfig> {
self.step
@@ -115,10 +159,14 @@ pub struct ProjectConfig {
#[serde(default)]
pub list: Option<ProjectListConfig>,
- /// CI configuration (platform override)
+ /// CI configuration (platform override). Deprecated: use `[forge]` instead.
#[serde(default)]
pub ci: Option<ProjectCiConfig>,
+ /// Forge configuration (platform detection override, API hostname)
+ #[serde(default)]
+ pub forge: Option<ProjectForgeConfig>,
+
/// Configuration for `wt step` subcommands.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub step: Option<StepConfig>,
@@ -346,6 +394,67 @@ platform = "gitlab"
assert!(config.platform.is_none());
}
+ // ============================================================================
+ // ForgeConfig Tests
+ // ============================================================================
+
+ #[test]
+ fn test_deserialize_forge_platform() {
+ let contents = r#"
+[forge]
+platform = "github"
+"#;
+ let config: ProjectConfig = toml::from_str(contents).unwrap();
+ assert_eq!(config.forge_platform(), Some("github"));
+ assert!(config.forge_hostname().is_none());
+ }
+
+ #[test]
+ fn test_deserialize_forge_hostname() {
+ let contents = r#"
+[forge]
+platform = "github"
+hostname = "github.example.com"
+"#;
+ let config: ProjectConfig = toml::from_str(contents).unwrap();
+ assert_eq!(config.forge_platform(), Some("github"));
+ assert_eq!(config.forge_hostname(), Some("github.example.com"));
+ }
+
+ #[test]
+ fn test_forge_platform_falls_back_to_ci() {
+ let contents = r#"
+[ci]
+platform = "gitlab"
+"#;
+ let config: ProjectConfig = toml::from_str(contents).unwrap();
+ // forge.platform not set, falls back to ci.platform
+ assert_eq!(config.forge_platform(), Some("gitlab"));
+ }
+
+ #[test]
+ fn test_forge_platform_takes_precedence_over_ci() {
+ let contents = r#"
+[ci]
+platform = "gitlab"
+
+[forge]
+platform = "github"
+"#;
+ let config: ProjectConfig = toml::from_str(contents).unwrap();
+ // forge.platform takes precedence
+ assert_eq!(config.forge_platform(), Some("github"));
+ // ci.platform still accessible directly
+ assert_eq!(config.ci_platform(), Some("gitlab"));
+ }
+
+ #[test]
+ fn test_forge_config_default() {
+ let config = ProjectForgeConfig::default();
+ assert!(config.platform.is_none());
+ assert!(config.hostname.is_none());
+ }
+
// ============================================================================
// find_unknown_keys Tests
// ============================================================================
diff --git a/src/git/remote_ref/github.rs b/src/git/remote_ref/github.rs
index 17aa8f987..897632b1c 100644
--- a/src/git/remote_ref/github.rs
+++ b/src/git/remote_ref/github.rs
@@ -78,20 +78,34 @@ struct GhOwner {
fn fetch_pr_info(pr_number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo> {
let repo_root = repo.repo_path()?;
- // Best-effort hostname extraction for GitHub Enterprise support.
- // Uses effective URL (with url.insteadOf applied) to handle custom SSH
- // hostnames (e.g., github-work → github.com for multi-key SSH setups).
- // Falls back to gh's default (github.com) if the remote URL can't be parsed.
+ // 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))?;
+
+ let api_path = format!(
+ "repos/{}/{}/pulls/{}",
+ parsed.owner(),
+ parsed.repo(),
+ pr_number
+ );
+
+ // Only pass --hostname when explicitly configured (for GHE / self-hosted).
let hostname = repo
- .primary_remote()
+ .load_project_config()
.ok()
- .and_then(|remote| repo.effective_remote_url(&remote))
- .and_then(|url| git::GitRemoteUrl::parse(&url))
- .map(|parsed| parsed.host().to_string())
- .unwrap_or_else(|| "github.com".to_string());
+ .flatten()
+ .and_then(|c| c.forge_hostname().map(String::from));
- let api_path = format!("repos/{{owner}}/{{repo}}/pulls/{}", pr_number);
- let args = ["api", api_path.as_str(), "--hostname", hostname.as_str()];
+ let mut args = vec!["api", api_path.as_str()];
+ if let Some(h) = &hostname {
+ args.extend(["--hostname", h.as_str()]);
+ }
let output = run_cli_api(CliApiRequest {
tool: "gh",
args: &args,
diff --git a/src/git/remote_ref/mod.rs b/src/git/remote_ref/mod.rs
index 7cc9f37b6..f18f86db7 100644
--- a/src/git/remote_ref/mod.rs
+++ b/src/git/remote_ref/mod.rs
@@ -130,26 +130,25 @@ pub(super) fn cli_config_value(tool: &str, key: &str) -> Option<String> {
/// Find the local remote that points to the base (target) project for a PR/MR.
///
-/// Dispatches on `PlatformData` to extract host/owner/repo, then searches
-/// configured remotes. The suggested URL in the error respects each platform's
-/// configured git protocol (SSH vs HTTPS).
+/// 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).
pub fn find_remote(repo: &Repository, info: &RemoteRefInfo) -> Result<String, GitError> {
- let (host, owner, repo_name) = match &info.platform_data {
+ let (owner, repo_name) = match &info.platform_data {
PlatformData::GitHub {
- host,
base_owner,
base_repo,
..
}
| PlatformData::GitLab {
- host,
base_owner,
base_repo,
..
- } => (host.as_str(), base_owner.as_str(), base_repo.as_str()),
+ } => (base_owner.as_str(), base_repo.as_str()),
};
- repo.find_remote_for_repo(Some(host), owner, repo_name)
+ repo.find_remote_for_repo(None, owner, repo_name)
.ok_or_else(|| {
let suggested_url = match &info.platform_data {
PlatformData::GitHub {
diff --git a/src/git/repository/remotes.rs b/src/git/repository/remotes.rs
index 5e4560239..a72c0a495 100644
--- a/src/git/repository/remotes.rs
+++ b/src/git/repository/remotes.rs
@@ -2,81 +2,96 @@
//!
//! # Forge detection
//!
-//! Worktrunk needs three pieces of information from remote URLs:
+//! Worktrunk needs three pieces of information to talk to GitHub/GitLab:
//!
-//! 1. **Platform** — GitHub or GitLab (determines which CLI/API to use)
-//! 2. **Hostname** — which server to talk to (for `gh api --hostname`,
-//! `glab auth status --hostname`)
-//! 3. **Owner/repo** — the project path (for API calls and remote matching)
+//! 1. **Platform** — GitHub or GitLab (which CLI to invoke)
+//! 2. **Owner/repo** — the project path (for API calls)
+//! 3. **API hostname** — which server to talk to (only needed for GHE /
+//! self-hosted GitLab; `gh`/`glab` default to github.com/gitlab.com)
//!
-//! All three are extracted from the remote URL's hostname via substring
-//! matching: [`is_github()`](super::GitRemoteUrl::is_github) checks if the
-//! host contains `"github"`, [`is_gitlab()`](super::GitRemoteUrl::is_gitlab)
-//! checks for `"gitlab"`. This covers `github.com`, GitHub Enterprise
-//! (`github.mycompany.com`), `gitlab.com`, and self-hosted GitLab
-//! (`gitlab.example.com`).
+//! ## Design principle
//!
-//! ## Where each piece is resolved
+//! Derive owner/repo from URL paths, not hostnames. SSH aliases only
+//! corrupt the host component — the path (`owner/repo`) is always real.
+//! Only use the hostname for platform detection (substring match), and
+//! let `gh`/`glab` default to the right API host unless overridden.
+//!
+//! **Resolution order:**
+//!
+//! 1. **Remote** — branch's remote (for remote branches) >
+//! [`primary_remote()`](Repository::primary_remote)
+//! 2. **Platform** — `forge.platform` config > hostname substring match
+//! ([`is_github()`](super::GitRemoteUrl::is_github) /
+//! [`is_gitlab()`](super::GitRemoteUrl::is_gitlab)) on effective URL
+//! 3. **Owner/repo** — parsed from the chosen remote's URL path (works
+//! regardless of hostname, including SSH aliases)
+//! 4. **API hostname** — `forge.hostname` config > omit (let CLI default)
+//!
+//! For `wt list`, steps 1-4 are sufficient — each branch uses its
+//! associated remote.
+//!
+//! For `wt switch pr:N`, the API call uses owner/repo from the primary
+//! remote's raw URL. The API response provides the base repo's identity,
+//! and [`find_remote_for_repo`] matches it back to a local remote by
+//! owner/repo (host is not required to match).
+//!
+//! ## Where each piece is used
//!
//! | Need | `wt switch pr:N` | `wt list` CI status |
//! |------|------------------|---------------------|
-//! | Platform | Implicit (user typed `pr:` or `mr:`) | [`platform_for_repo`] in `ci_status::platform` |
-//! | Hostname | [`fetch_pr_info`] extracts from effective URL | `gh`/`glab` infer from `current_dir` |
-//! | Owner/repo | API response provides it | [`github_owner_repo`] / [`find_forge_remote`] |
-//! | Remote matching | [`find_remote_for_repo`] matches API response back to local remote | Not needed |
+//! | Platform | Implicit (`pr:` = GitHub, `mr:` = GitLab) | [`platform_for_repo`] |
+//! | Owner/repo | [`fetch_pr_info`] builds API path | [`github_owner_repo`] for check-runs API |
+//! | API hostname | `forge.hostname` config, else omit | `forge.hostname` config, else omit |
+//! | Fetch remote | [`find_remote_for_repo`] by owner/repo | Not needed |
//!
//! [`platform_for_repo`]: crate::commands::list::ci_status::platform::platform_for_repo
//! [`fetch_pr_info`]: crate::git::remote_ref::github
//! [`github_owner_repo`]: crate::commands::list::ci_status::github
//!
-//! ## SSH host aliases
+//! ## Config: `[forge]` section
//!
-//! Multi-account SSH setups use host aliases (`git@github-personal:owner/repo`)
-//! where SSH resolves `github-personal` → `github.com` via `~/.ssh/config`.
-//! Git operations work, but the literal hostname breaks forge detection:
+//! All fields are optional. For most repositories (single remote, hostname
+//! contains "github" or "gitlab"), no configuration is needed.
//!
-//! - **Platform detection** fails if the alias doesn't contain `"github"` or
-//! `"gitlab"` (e.g., `work`). Override with `ci.platform` in project config.
-//! - **`gh api --hostname`** receives the alias instead of the real hostname.
-//! If the alias contains `"github"` (e.g., `github-personal`), `gh` gets
-//! `--hostname github-personal` and fails. If not (e.g., `work`), we fall
-//! back to `github.com` which works for non-Enterprise repos.
-//! - **Remote matching** fails when comparing `github.com` (from API response)
-//! against `github-personal` (from local remote URL).
+//! ```toml
+//! [forge]
+//! platform = "github" # override platform detection
+//! hostname = "github.example.com" # API hostname (GHE / self-hosted GitLab)
+//! ```
//!
-//! ### `url.insteadOf` (current solution)
+//! `ci.platform` is supported as a deprecated alias for `forge.platform`.
//!
-//! Git's `url.insteadOf` rewrites URLs before any tool sees them:
+//! ## SSH host aliases
//!
-//! ```text
-//! git config url."[email protected]:".insteadOf "git@github-personal:"
-//! ```
+//! Multi-account SSH setups use host aliases (`git@github-personal:owner/repo`)
+//! where SSH resolves `github-personal` → `github.com` via `~/.ssh/config`.
+//! Git operations work, but the literal hostname affects forge detection.
//!
-//! After this, [`effective_remote_url`](Repository::effective_remote_url)
-//! (which runs `git remote get-url`) returns the rewritten URL with the real
-//! hostname. All forge detection, API calls, and remote matching work.
+//! Owner/repo extraction is unaffected — aliases only change the host, not
+//! the path. The impact depends on the alias name:
//!
-//! Trade-off: `url.insteadOf` also affects SSH, which sees `github.com`
-//! instead of the alias and can't select the correct `IdentityFile`. Users
-//! must pair it with per-repo `core.sshCommand` to restore key routing.
+//! | Alias | Platform detection | API calls | Config needed |
+//! |-------|-------------------|-----------|---------------|
+//! | `github-personal` | Works ("github" in name) | Works (`gh` defaults to github.com) | None |
+//! | `work` (opaque) | Fails | Works (`gh` defaults to github.com) | `forge.platform` |
+//! | GHE alias | May work | Needs explicit host | `forge.hostname` (+ `forge.platform` if opaque) |
//!
-//! ### Known gap
+//! ### `url.insteadOf` (alternative)
//!
-//! SSH host aliases without `url.insteadOf` are partially unsupported. The
-//! hostname and remote matching steps fail because `effective_remote_url`
-//! returns the alias unchanged. Owner/repo extraction is unaffected (aliases
-//! only change the host, not the path). A future fix could resolve aliases
-//! via `ssh -G <host>` or a config option; see issue #1790.
+//! Git's `url.insteadOf` rewrites URLs before any tool sees them, which
+//! solves all detection problems. Trade-off: it also affects SSH, which
+//! sees `github.com` instead of the alias and can't select the correct
+//! `IdentityFile`. Users must pair it with per-repo `core.sshCommand`.
+//! The `[forge]` config avoids this trade-off.
//!
//! ## URL methods
//!
-//! - `remote_url` — raw config value, no rewriting (for non-forge uses like
-//! template variables and project identifiers)
-//! - `effective_remote_url` — `git remote get-url`, with `insteadOf` applied
-//! (cached; use for all forge detection)
-//! - `find_forge_remote(pred)` — search all remotes using effective URLs
-//! - `find_remote_for_repo(host, owner, repo)` — match API response back to
-//! local remote (checks both raw and effective URLs)
+//! - `remote_url` — raw config value, no rewriting (for non-forge uses
+//! like template variables and project identifiers)
+//! - `effective_remote_url` — `git remote get-url`, with `insteadOf`
+//! applied (cached; used for platform detection)
+//! - `find_remote_for_repo(host, owner, repo)` — match owner/repo across
+//! remotes, host used only as disambiguator
use anyhow::Context;
@@ -261,27 +276,6 @@ impl Repository {
.clone()
}
- /// Search all remotes for a URL matching a predicate.
- ///
- /// Uses effective URLs (with `url.insteadOf` rewrites applied) so that
- /// custom SSH hostnames resolve to real forge hostnames.
- ///
- /// Returns the first matching `(remote_name, url)` pair, or `None`.
- pub fn find_forge_remote<F>(&self, predicate: F) -> Option<(String, String)>
- where
- F: Fn(&GitRemoteUrl) -> bool,
- {
- for (remote_name, _) in self.all_remote_urls() {
- if let Some(url) = self.effective_remote_url(&remote_name)
- && let Some(parsed) = GitRemoteUrl::parse(&url)
- && predicate(&parsed)
- {
- return Some((remote_name, url));
- }
- }
- None
- }
-
/// Get a project identifier for approval tracking.
///
/// Uses the git remote URL if available (e.g., "github.com/user/repo"),
diff --git a/tests/integration_tests/default_branch.rs b/tests/integration_tests/default_branch.rs
index 0c3fc9cb6..e106b6003 100644
--- a/tests/integration_tests/default_branch.rs
+++ b/tests/integration_tests/default_branch.rs
@@ -394,54 +394,6 @@ fn test_effective_remote_url_is_cached(repo: TestRepo) {
assert_eq!(first, second);
}
-/// Test find_forge_remote: finds forge via effective URL with insteadOf.
-#[rstest]
-fn test_find_forge_remote_insteadof(repo: TestRepo) {
- setup_insteadof(
- &repo,
- "origin",
- "git@work-ssh:org/repo.git",
- );
-
- let git_repo = Repository::at(repo.root_path()).unwrap();
-
- let (remote_name, url) = git_repo
- .find_forge_remote(|parsed| parsed.is_github())
- .expect("Should find GitHub via insteadOf");
- assert_eq!(remote_name, "origin");
- assert_eq!(GitRemoteUrl::parse(&url).unwrap().host(), "github.com");
-
- assert!(
- git_repo
- .find_forge_remote(|parsed| parsed.is_gitlab())
- .is_none(),
- "Should not find GitLab"
- );
-}
-
-/// Test find_forge_remote: matches when URL already has known forge hostname.
-#[rstest]
-fn test_find_forge_remote_known_forge(repo: TestRepo) {
- repo.run_git(&["config", "remote.origin.url", "[email protected]:org/repo.git"]);
-
- let git_repo = Repository::at(repo.root_path()).unwrap();
- let (name, url) = git_repo
- .find_forge_remote(|parsed| parsed.is_github())
- .expect("Should find GitHub");
- assert_eq!(name, "origin");
- assert_eq!(url, "[email protected]:org/repo.git");
-}
-
-/// Test find_forge_remote: returns None when no remotes are configured.
-#[rstest]
-fn test_find_forge_remote_no_remotes(repo: TestRepo) {
- repo.run_git(&["remote", "remove", "origin"]);
-
- let git_repo = Repository::at(repo.root_path()).unwrap();
- assert!(git_repo.find_forge_remote(|p| p.is_github()).is_none());
-}
-
/// Test find_remote_for_repo: resolves through insteadOf to match owner/repo.
#[rstest]
fn test_find_remote_for_repo_insteadof(repo: TestRepo) {
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 910f1e320..044f43338 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -428,9 +428,8 @@ fn test_list_with_remotes_and_full(#[from(repo_with_remote)] repo: TestRepo) {
#[rstest]
fn test_list_with_orphaned_remote_ref(#[from(repo_with_remote)] repo: TestRepo) {
- // Create a remote-tracking ref for a non-existent remote to exercise the
- // fallback path in CiBranchName::from_branch_ref (lines 64-75)
- // This simulates a ref that remains after a remote is deleted
+ // Create a remote-tracking ref for a non-existent remote.
+ // This simulates a ref that remains after a remote is deleted.
let head_sha = repo
.git_command()
.args(["rev-parse", "HEAD"])
@@ -453,10 +452,8 @@ fn test_list_with_orphaned_remote_ref(#[from(repo_with_remote)] repo: TestRepo)
"deleted-remote should not exist"
);
- // Run with --remotes --full to trigger the fallback path
- // The orphaned ref should be parsed using split_once('/') as fallback
- // Note: We don't use snapshot testing here because the spinner character
- // in stderr is non-deterministic (timing-dependent)
+ // The orphaned ref should still appear — split_once('/') parses it correctly
+ // even though the remote no longer exists.
let output = repo
.wt_command()
.args(["list", "--remotes", "--full"])
@@ -469,12 +466,6 @@ fn test_list_with_orphaned_remote_ref(#[from(repo_with_remote)] repo: TestRepo)
stdout.contains("deleted-remote/orphaned-branch"),
"should show orphaned remote branch in output: {stdout}"
);
-
- let stderr = String::from_utf8_lossy(&output.stderr);
- assert!(
- stderr.contains("unknown remote 'deleted-remote'"),
- "should warn about unknown remote: {stderr}"
- );
}
#[rstest]
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index ee2598dd8..9370ebeff 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -1520,6 +1520,37 @@ fn test_switch_create_no_hint_with_custom_worktree_path(repo: TestRepo) {
use crate::common::mock_commands::{MockConfig, MockResponse, copy_mock_binary};
+/// Set origin to a GitHub URL so `fetch_pr_info` can parse owner/repo.
+///
+/// Saves the original bare repo URL and configures `url.insteadOf` so that
+/// `git fetch`/`git push` still work against the local bare remote.
+fn set_github_remote_url(repo: &TestRepo) {
+ let bare_url = String::from_utf8_lossy(
+ &repo
+ .git_command()
+ .args(["config", "remote.origin.url"])
+ .run()
+ .unwrap()
+ .stdout,
+ )
+ .trim()
+ .to_string();
+
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://github.com/owner/test-repo.git",
+ ]);
+
+ // Redirect GitHub URL to local bare remote for actual git operations
+ repo.run_git(&[
+ "config",
+ &format!("url.{}.insteadOf", bare_url),
+ "https://github.com/owner/test-repo.git",
+ ]);
+}
+
/// 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:
@@ -1922,6 +1953,7 @@ fn test_switch_pr_fork_no_upstream_remote(#[from(repo_with_remote)] repo: TestRe
/// Test error when PR is not found
#[rstest]
fn test_switch_pr_not_found(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -1951,6 +1983,7 @@ 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) {
+ set_github_remote_url(&repo);
// 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#"{
@@ -1992,6 +2025,7 @@ fn test_switch_pr_base_conflict(repo: TestRepo) {
/// Test fork PR where branch already exists and tracks same PR (should reuse)
#[rstest]
fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
// First, manually create the branch with correct tracking config
// Branch name matches headRefName (no owner prefix) so git push works
let branch_name = "feature-fix";
@@ -2038,6 +2072,7 @@ fn test_switch_pr_fork_existing_same_pr(#[from(repo_with_remote)] repo: TestRepo
/// Uses prefixed branch name `contributor/feature-fix` to avoid conflict
#[rstest]
fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
// Create a PR ref on the remote
repo.run_git(&["checkout", "-b", "pr-source"]);
fs::write(repo.root_path().join("pr-file.txt"), "PR content").unwrap();
@@ -2125,6 +2160,7 @@ fn test_switch_pr_fork_existing_different_pr(#[from(repo_with_remote)] repo: Tes
/// wrong repository.
#[rstest]
fn test_switch_pr_fork_existing_same_pr_wrong_remote(#[from(repo_with_remote)] mut repo: TestRepo) {
+ set_github_remote_url(&repo);
repo.setup_custom_remote("fork", "main");
// Create a PR ref on the real PR remote.
@@ -2212,6 +2248,7 @@ fn test_switch_pr_fork_existing_same_pr_wrong_remote(#[from(repo_with_remote)] m
/// Uses prefixed branch name `contributor/feature-fix` to avoid conflict
#[rstest]
fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
// Create a PR ref on the remote
repo.run_git(&["checkout", "-b", "pr-source"]);
fs::write(repo.root_path().join("pr-file.txt"), "PR content").unwrap();
@@ -2287,6 +2324,7 @@ fn test_switch_pr_fork_existing_no_tracking(#[from(repo_with_remote)] repo: Test
/// Should reuse the existing prefixed branch
#[rstest]
fn test_switch_pr_fork_prefixed_exists_same_pr(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
// Create the unprefixed branch (simulating existing local branch)
repo.run_git(&["branch", "feature-fix", "main"]);
@@ -2370,6 +2408,7 @@ fn test_switch_pr_fork_prefixed_exists_same_pr(#[from(repo_with_remote)] repo: T
/// Test fork PR where prefixed branch exists but tracks different PR (should error)
#[rstest]
fn test_switch_pr_fork_prefixed_exists_different_pr(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
// Create the unprefixed branch (simulating existing local branch)
repo.run_git(&["branch", "feature-fix", "main"]);
@@ -2439,6 +2478,7 @@ fn test_switch_pr_fork_prefixed_exists_different_pr(#[from(repo_with_remote)] re
/// Test pr: when gh is not authenticated
#[rstest]
fn test_switch_pr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -2467,6 +2507,7 @@ fn test_switch_pr_not_authenticated(#[from(repo_with_remote)] repo: TestRepo) {
/// Test pr: when hitting GitHub rate limit
#[rstest]
fn test_switch_pr_rate_limit(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -2497,6 +2538,7 @@ fn test_switch_pr_rate_limit(#[from(repo_with_remote)] repo: TestRepo) {
/// Test pr: when gh returns invalid JSON
#[rstest]
fn test_switch_pr_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -2520,6 +2562,7 @@ fn test_switch_pr_invalid_json(#[from(repo_with_remote)] repo: TestRepo) {
/// Test pr: when network error occurs
#[rstest]
fn test_switch_pr_network_error(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -2546,6 +2589,7 @@ fn test_switch_pr_network_error(#[from(repo_with_remote)] repo: TestRepo) {
/// Test pr: when gh returns unknown error
#[rstest]
fn test_switch_pr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -2573,6 +2617,7 @@ fn test_switch_pr_unknown_error(#[from(repo_with_remote)] repo: TestRepo) {
/// Test pr: when PR has empty branch name
#[rstest]
fn test_switch_pr_empty_branch(#[from(repo_with_remote)] repo: TestRepo) {
+ set_github_remote_url(&repo);
let mock_bin = repo.root_path().join("mock-bin");
fs::create_dir_all(&mock_bin).unwrap();
@@ -3365,6 +3410,13 @@ fn configure_cli_not_installed_env(cmd: &mut std::process::Command, minimal_bin:
/// Test pr: when gh CLI is not installed
#[rstest]
fn test_switch_pr_gh_not_installed(#[from(repo_with_remote)] repo: TestRepo) {
+ // Set a GitHub URL so fetch_pr_info can parse owner/repo before checking for gh
+ repo.run_git(&[
+ "remote",
+ "set-url",
+ "origin",
+ "https://github.com/owner/test-repo.git",
+ ]);
let Some(minimal_bin) = setup_minimal_bin_without_cli(&repo) else {
// Symlinks not available (Windows without Developer Mode)
eprintln!("Skipping test: symlinks not available on this system");
diff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap b/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap
index 443842b1f..9f9444bcf 100644
--- a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap
+++ b/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap
@@ -19,6 +19,7 @@ info:
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -49,6 +50,7 @@ exit_code: 0
○ Showing 5 worktrees, 1 with changes, 3 ahead
----- stderr -----
+▲ Project config has deprecated settings. Run wt config show for details or wt config update to apply updates
[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
diff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_platform_override_github.snap b/tests/snapshots/integration__integration_tests__ci_status__list_full_with_platform_override_github.snap
index dcb8d4913..64eed8cc8 100644
--- a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_platform_override_github.snap
+++ b/tests/snapshots/integration__integration_tests__ci_status__list_full_with_platform_override_github.snap
@@ -19,6 +19,7 @@ info:
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -49,3 +50,4 @@ exit_code: 0
○ Showing 5 worktrees, 1 with changes, 3 ahead
----- stderr -----
+▲ Project config has deprecated settings. Run wt config show for details or wt config update to apply updates
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_project_config_for_ci.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_project_config_for_ci.snap
index 81d23b1bc..5f2299098 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_project_config_for_ci.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_suggests_project_config_for_ci.snap
@@ -43,7 +43,22 @@ exit_code: 0
----- stderr -----
USER CONFIG @ ~/.config/worktrunk/config.toml
-▲ Key ci belongs in project config (will be ignored)
+▲ User config uses deprecated config section: [ci] → [forge]
+↳ To apply:
+  wt config update
+  diff --git a[TEMP_HOME]/.config/worktrunk/config.toml b[TEMP_HOME]/.config/worktrunk/config.toml.new
+  index 2e0e0bb..9d78d51 100644
+  --- a[TEMP_HOME]/.config/worktrunk/config.toml
+  +++ b[TEMP_HOME]/.config/worktrunk/config.toml.new
+  @@ -1,4 +1,4 @@
+  worktree-path = "../{{ repo }}.{{ branch }}"
+  
+  -[ci]
+  -platform = "github"
+  / No newline at end of file
+  +[forge]
+  +platform = "github"
+○ Current config:
  worktree-path = "../{{ repo }}.{{ branch }}"
 
  [ci]
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index 3599cd96d..1bb44384f 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -412,10 +412,11 @@ With --project, creates .config/wt.toml in the current repositor
  # url = "http://localhost:{{ branch | hash_port }}"
  
  # ============================================================================
-  # CI Platform Override
+  # Forge (GitHub/GitLab) Settings
  # ============================================================================
-  # Override CI platform detection for GitHub Enterprise or self-hosted GitLab
-  # with custom domains where URL detection fails.
+  # Override platform detection for SSH host aliases or custom domains.
+  # Set hostname for GitHub Enterprise or self-hosted GitLab API calls.
  #
-  # [ci]
-  # platform = "github" # or "gitlab"
+  # [forge]
+  # platform = "github" # or "gitlab"
+  # hostname = "github.example.com" # API host (GHE / self-hosted GitLab)
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index cce5cb19d..8a46f6f25 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -361,9 +361,10 @@ See wt hook for hook types, execution order, template variables, and exa
  [list]
  url = "http://localhost:{{ branch | hash_port }}"
 
-  # Override CI platform detection for self-hosted instances
-  [ci]
+  # Override platform detection for SSH aliases or self-hosted instances
+  [forge]
  platform = "github" # or "gitlab"
+  # hostname = "github.example.com" # API host (GHE / self-hosted GitLab)
 
  # Add more gitignored excludes for wt step copy-ignored
  [step.copy-ignored]
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
index 145fd5f83..e2e7f25d6 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
@@ -57,7 +57,7 @@ Usage: wt config state ci-status [OPTIONS] [COMMAND]
Caches GitHub/GitLab CI status for display in wt list.
-Requires gh (GitHub) or glab (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with ci.platform = "github" in .config/wt.toml for self-hosted instances.
+Requires gh (GitHub) or glab (GitLab) CLI, authenticated. Platform auto-detects from remote URL; override with forge.platform = "github" in .config/wt.toml for SSH host aliases or self-hosted instances. For GitHub Enterprise or self-hosted GitLab, also set forge.hostname.
Checks open PRs/MRs first, then branch pipelines for branches with upstream. Local-only branches (no remote tracking) show blank.