Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: add github enterprise hostname parsing to wt switch logic (#1408)
Tom40810feabfd8
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rsindex ff09d09e3..6925c862b 100644--- a/src/commands/worktree/switch.rs+++ b/src/commands/worktree/switch.rs@@ -75,8 +75,7 @@ fn resolve_remote_ref(progress_message(cformat!("Fetching {} {symbol}{number}...", ref_type.name())));- let repo_root = repo.repo_path()?;- let info = provider.fetch_info(number, repo_root)?;+ let info = provider.fetch_info(number, repo)?;// Display context with URL (as gutter under fetch progress)eprintln!("{}", format_with_gutter(&format_ref_context(&info), None));diff --git a/src/git/remote_ref/github.rs b/src/git/remote_ref/github.rsindex f610b1ae7..9776fb069 100644--- a/src/git/remote_ref/github.rs+++ b/src/git/remote_ref/github.rs@@ -3,14 +3,13 @@//! Implements `RemoteRefProvider` for GitHub Pull Requests using the `gh` CLI.use std::io::ErrorKind;-use std::path::Path;use anyhow::{Context, bail};use serde::Deserialize;use super::{PlatformData, RemoteRefInfo, RemoteRefProvider};-use crate::git::RefType;use crate::git::error::GitError;+use crate::git::{self, RefType, Repository};use crate::shell_exec::Cmd;/// GitHub Pull Request provider.@@ -22,8 +21,8 @@ impl RemoteRefProvider for GitHubProvider {RefType::Pr}- fn fetch_info(&self, number: u32, repo_root: &Path) -> anyhow::Result<RemoteRefInfo> {- fetch_pr_info(number, repo_root)+ fn fetch_info(&self, number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo> {+ fetch_pr_info(number, repo)}fn ref_path(&self, number: u32) -> String {@@ -77,11 +76,21 @@ struct GhOwner {}/// Fetch PR information from GitHub using the `gh` CLI.-fn fetch_pr_info(pr_number: u32, repo_root: &Path) -> anyhow::Result<RemoteRefInfo> {+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.+ // Falls back to gh's default (github.com) if the remote URL can't be parsed.+ let hostname = repo+ .primary_remote_url()+ .and_then(|url| git::GitRemoteUrl::parse(&url))+ .map(|parsed| parsed.host().to_string())+ .unwrap_or_else(|| "github.com".to_string());+let api_path = format!("repos/{{owner}}/{{repo}}/pulls/{}", pr_number);let output = match Cmd::new("gh")- .args(["api", &api_path])+ .args(["api", &api_path, "--hostname", &hostname]).current_dir(repo_root).env("GH_PROMPT_DISABLED", "1").run()diff --git a/src/git/remote_ref/gitlab.rs b/src/git/remote_ref/gitlab.rsindex 7f46fcce0..8f8fafad5 100644--- a/src/git/remote_ref/gitlab.rs+++ b/src/git/remote_ref/gitlab.rs@@ -28,8 +28,8 @@ use anyhow::{Context, bail};use serde::Deserialize;use super::{PlatformData, RemoteRefInfo, RemoteRefProvider};-use crate::git::RefType;use crate::git::error::GitError;+use crate::git::{RefType, Repository};use crate::shell_exec::Cmd;/// GitLab Merge Request provider.@@ -41,7 +41,8 @@ impl RemoteRefProvider for GitLabProvider {RefType::Mr}- fn fetch_info(&self, number: u32, repo_root: &Path) -> anyhow::Result<RemoteRefInfo> {+ fn fetch_info(&self, number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo> {+ let repo_root = repo.repo_path()?;fetch_mr_info(number, repo_root)}diff --git a/src/git/remote_ref/mod.rs b/src/git/remote_ref/mod.rsindex bfb4c0603..38845328e 100644--- a/src/git/remote_ref/mod.rs+++ b/src/git/remote_ref/mod.rs@@ -40,7 +40,7 @@ pub use info::{PlatformData, RemoteRefInfo};use std::path::Path;-use crate::git::RefType;+use crate::git::{RefType, Repository};/// Provider trait for platform-specific PR/MR operations.///@@ -58,7 +58,7 @@ pub trait RemoteRefProvider {/// - The CLI tool is not installed or not authenticated/// - The ref doesn't exist/// - The JSON response is malformed- fn fetch_info(&self, number: u32, repo_root: &Path) -> anyhow::Result<RemoteRefInfo>;+ fn fetch_info(&self, number: u32, repo: &Repository) -> anyhow::Result<RemoteRefInfo>;/// Get the git ref path for this ref (e.g., "pull/123/head" or "merge-requests/42/head").fn ref_path(&self, number: u32) -> String;