Skip to content

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

Consolidate parsing and utility functions into shared modules (#389)

Maximilian Roos484b2ebe0c36
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index 02ca51d4c..bfef0602e 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -114,8 +114,8 @@ pub fn build_hook_context(
if let Ok(remote) = ctx.repo.primary_remote() {
map.insert("remote".into(), remote.to_string());
// Add remote URL for conditional hook execution (e.g., GitLab vs GitHub)
- if let Ok(url) = ctx.repo.run_command(&["remote", "get-url", remote]) {
- map.insert("remote_url".into(), url.trim().into());
+ if let Some(url) = ctx.repo.remote_url(remote) {
+ map.insert("remote_url".into(), url);
}
if let Some(branch) = ctx.branch
&& let Ok(Some(upstream)) = ctx.repo.upstream_branch(branch)
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index fa7bcdc18..0cf5a3284 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -184,7 +184,7 @@ pub fn handle_configure_shell(
.any(|r| r.shell == Shell::Zsh && !matches!(r.action, ConfigAction::AlreadyExists));
let should_check_compinit = zsh_was_configured
&& (shell_filter == Some(Shell::Zsh)
- || (shell_filter.is_none() && shell::is_current_shell_zsh()));
+ || (shell_filter.is_none() && shell::current_shell() == Some(Shell::Zsh)));
// Probe user's zsh to check if compinit is enabled.
// Only flag if we positively detect it's missing (Some(false)).
diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rs
index 7d7ab878b..ba9ac3cfc 100644
--- a/src/commands/list/ci_status.rs
+++ b/src/commands/list/ci_status.rs
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize, de::DeserializeOwned};
use std::fs;
use std::path::PathBuf;
use std::process::Command;
-use worktrunk::git::{GitRemoteUrl, Repository};
+use worktrunk::git::{Repository, parse_owner_repo, parse_remote_host, parse_remote_owner};
use worktrunk::path::sanitize_for_filename;
use worktrunk::shell_exec::run;
use worktrunk::utils::get_now;
@@ -37,10 +37,7 @@ pub fn get_platform_for_repo(repo_root: &str) -> Option<CiPlatform> {
/// Get the origin remote URL for a repository.
fn get_remote_url_for_repo(repo_root: &str) -> Option<String> {
let repo = Repository::at(repo_root);
- repo.run_command(&["remote", "get-url", "origin"])
- .ok()
- .map(|output| output.trim().to_string())
- .filter(|output| !output.is_empty())
+ repo.remote_url("origin")
}
/// Get the GitLab hostname for a repository by parsing its origin remote URL.
@@ -57,41 +54,6 @@ pub fn get_gitlab_host_for_repo(repo_root: &str) -> Option<String> {
}
}
-/// Extract owner from a git remote URL.
-///
-/// Used for client-side filtering of PRs/MRs by source repository. When multiple users
-/// have PRs with the same branch name (e.g., everyone has a `feature` branch), we need
-/// to identify which PR comes from *our* fork/remote, not just which PR we authored.
-///
-/// # Why not use `--author`?
-///
-/// The `gh pr list --author` flag filters by who *created* the PR, not whose fork
-/// the PR comes *from*. These are usually the same, but not always:
-/// - Maintainers may create PRs from contributor forks
-/// - Bots may create PRs on behalf of users
-/// - Organization repos: `--author company` doesn't match individual user PRs
-///
-/// # Why client-side filtering?
-///
-/// Neither `gh` nor `glab` CLI support server-side filtering by source repository.
-/// The `gh pr list --head` flag only accepts branch name, not `owner:branch` format.
-/// So we fetch PRs matching the branch name, then filter by `headRepositoryOwner`.
-fn parse_remote_owner(url: &str) -> Option<String> {
- GitRemoteUrl::parse(url).map(|u| u.owner().to_string())
-}
-
-/// Extract owner and repository name from a git remote URL.
-fn parse_owner_repo(url: &str) -> Option<(String, String)> {
- GitRemoteUrl::parse(url).map(|u| (u.owner().to_string(), u.repo().to_string()))
-}
-
-/// Extract hostname from a git remote URL.
-///
-/// Used to check auth status against a specific GitLab host instead of the default.
-fn parse_remote_host(url: &str) -> Option<String> {
- GitRemoteUrl::parse(url).map(|u| u.host().to_string())
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -163,130 +125,6 @@ mod tests {
);
}
- /// Test URL parsing for various git remote formats.
- ///
- /// This is critical for PR/MR filtering - if we parse the wrong owner,
- /// we'll show CI status for the wrong PRs.
- #[test]
- fn test_parse_remote_owner() {
- // GitHub HTTPS
- assert_eq!(
- parse_remote_owner("https://github.com/max-sixty/worktrunk.git"),
- Some("max-sixty".to_string())
- );
- assert_eq!(
- parse_remote_owner(" https://github.com/owner/repo\n"),
- Some("owner".to_string())
- );
-
- // GitHub SSH (git@ form) - most common for developers
- assert_eq!(
- parse_remote_owner("[email protected]:max-sixty/worktrunk.git"),
- Some("max-sixty".to_string())
- );
-
- // GitHub SSH (ssh:// form)
- assert_eq!(
- parse_remote_owner("ssh://[email protected]/owner/repo.git"),
- Some("owner".to_string())
- );
- assert_eq!(
- parse_remote_owner("ssh://github.com/owner/repo.git"),
- Some("owner".to_string())
- );
-
- // GitLab HTTPS
- assert_eq!(
- parse_remote_owner("https://gitlab.com/owner/repo.git"),
- Some("owner".to_string())
- );
- assert_eq!(
- parse_remote_owner("https://gitlab.example.com/owner/repo.git"),
- Some("owner".to_string())
- );
-
- // GitLab SSH
- assert_eq!(
- parse_remote_owner("[email protected]:owner/repo.git"),
- Some("owner".to_string())
- );
-
- // Bitbucket
- assert_eq!(
- parse_remote_owner("https://bitbucket.org/owner/repo.git"),
- Some("owner".to_string())
- );
- assert_eq!(
- parse_remote_owner("[email protected]:owner/repo.git"),
- Some("owner".to_string())
- );
-
- // Organization repos - owner is the org, not the user
- assert_eq!(
- parse_remote_owner("https://github.com/company-org/project.git"),
- Some("company-org".to_string())
- );
-
- // HTTP (legacy, common on self-hosted)
- assert_eq!(
- parse_remote_owner("http://github.com/owner/repo.git"),
- Some("owner".to_string())
- );
-
- // Malformed URLs
- assert_eq!(parse_remote_owner("https://github.com/"), None);
- assert_eq!(parse_remote_owner("[email protected]:"), None);
- assert_eq!(parse_remote_owner(""), None);
- }
-
- #[test]
- fn test_parse_remote_host() {
- // HTTPS
- assert_eq!(
- parse_remote_host("https://gitlab.com/owner/repo.git"),
- Some("gitlab.com".to_string())
- );
- assert_eq!(
- parse_remote_host("https://gitlab.example.com/owner/repo.git"),
- Some("gitlab.example.com".to_string())
- );
- assert_eq!(
- parse_remote_host(" https://github.com/owner/repo\n"),
- Some("github.com".to_string())
- );
-
- // HTTP (legacy, common on self-hosted)
- assert_eq!(
- parse_remote_host("http://gitlab.internal.company.com/owner/repo.git"),
- Some("gitlab.internal.company.com".to_string())
- );
-
- // SSH (git@ form)
- assert_eq!(
- parse_remote_host("[email protected]:owner/repo.git"),
- Some("gitlab.com".to_string())
- );
- assert_eq!(
- parse_remote_host("[email protected]:owner/repo.git"),
- Some("gitlab.example.com".to_string())
- );
-
- // SSH (ssh:// form)
- assert_eq!(
- parse_remote_host("ssh://[email protected]/owner/repo.git"),
- Some("gitlab.example.com".to_string())
- );
- assert_eq!(
- parse_remote_host("ssh://gitlab.example.com/owner/repo.git"),
- Some("gitlab.example.com".to_string())
- );
-
- // Malformed URLs
- assert_eq!(parse_remote_host("https://"), None);
- assert_eq!(parse_remote_host("git@"), None);
- assert_eq!(parse_remote_host(""), None);
- }
-
#[test]
fn test_ttl_jitter_range_and_determinism() {
// Check range: TTL should be in [30, 60)
@@ -649,50 +487,6 @@ mod tests {
assert_eq!(aggregate_github_checks(&checks), CiStatus::Failed);
}
- #[test]
- fn test_parse_owner_repo() {
- // GitHub HTTPS
- assert_eq!(
- parse_owner_repo("https://github.com/owner/repo.git"),
- Some(("owner".to_string(), "repo".to_string()))
- );
- assert_eq!(
- parse_owner_repo("https://github.com/owner/repo"),
- Some(("owner".to_string(), "repo".to_string()))
- );
- assert_eq!(
- parse_owner_repo(" https://github.com/owner/repo.git\n"),
- Some(("owner".to_string(), "repo".to_string()))
- );
-
- // GitHub SSH (git@ form)
- assert_eq!(
- parse_owner_repo("[email protected]:owner/repo.git"),
- Some(("owner".to_string(), "repo".to_string()))
- );
- assert_eq!(
- parse_owner_repo("[email protected]:owner/repo"),
- Some(("owner".to_string(), "repo".to_string()))
- );
-
- // GitHub SSH (ssh:// form)
- assert_eq!(
- parse_owner_repo("ssh://[email protected]/owner/repo.git"),
- Some(("owner".to_string(), "repo".to_string()))
- );
-
- // GitLab
- assert_eq!(
- parse_owner_repo("https://gitlab.com/owner/repo.git"),
- Some(("owner".to_string(), "repo".to_string()))
- );
-
- // Malformed URLs
- assert_eq!(parse_owner_repo("https://github.com/owner/"), None);
- assert_eq!(parse_owner_repo("[email protected]:owner/"), None);
- assert_eq!(parse_owner_repo(""), None);
- }
-
#[test]
fn test_parse_gitlab_status() {
// Running states
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rs
index 6bfe21c00..cc3e73a00 100644
--- a/src/commands/list/collect.rs
+++ b/src/commands/list/collect.rs
@@ -819,7 +819,7 @@ pub fn collect(
);
// Single-line invariant: use safe width to prevent line wrapping
- let max_width = super::layout::get_safe_list_width();
+ let max_width = crate::display::get_terminal_width();
// Create collection options from skip set
let options = super::collect_progressive_impl::CollectOptions {
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index d7addb6b0..b9a8a0996 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -185,10 +185,6 @@ pub use super::columns::DiffVariant;
/// Width of short commit hash display (first 8 hex characters)
const COMMIT_HASH_WIDTH: usize = 8;
-/// Get terminal width for list rendering.
-pub fn get_safe_list_width() -> usize {
- get_terminal_width()
-}
/// Ensures a column width is at least as wide as its header.
///
@@ -849,7 +845,7 @@ pub fn calculate_layout_from_basics(
calculate_layout_with_width(
items,
skip_tasks,
- get_safe_list_width(),
+ get_terminal_width(),
main_worktree_path,
url_template,
)
diff --git a/src/commands/select.rs b/src/commands/select.rs
index 5645ebf61..18134bc76 100644
--- a/src/commands/select.rs
+++ b/src/commands/select.rs
@@ -791,7 +791,7 @@ pub fn handle_select() -> anyhow::Result<()> {
// List width depends on preview position:
// - Right layout: skim splits ~50% for list, ~50% for preview
// - Down layout: list gets full width, preview is below
- let terminal_width = super::list::layout::get_safe_list_width();
+ let terminal_width = crate::display::get_terminal_width();
let skim_list_width = match state.initial_layout {
PreviewLayout::Right => terminal_width / 2,
PreviewLayout::Down => terminal_width,
@@ -1074,62 +1074,6 @@ mod tests {
assert!(output.contains("3: main…±"));
}
- #[test]
- fn test_parse_numstat_line_basic() {
- // Tab-separated: added<TAB>deleted<TAB>filename
- let result = parse_numstat_line("10\t5\tfile.rs");
- assert_eq!(result, Some((10, 5)));
- }
-
- #[test]
- fn test_parse_numstat_line_insertions_only() {
- let result = parse_numstat_line("15\t0\tfile.rs");
- assert_eq!(result, Some((15, 0)));
- }
-
- #[test]
- fn test_parse_numstat_line_deletions_only() {
- let result = parse_numstat_line("0\t8\tfile.rs");
- assert_eq!(result, Some((0, 8)));
- }
-
- #[test]
- fn test_parse_numstat_line_binary_file() {
- // Binary files show "-" instead of numbers
- let result = parse_numstat_line("-\t-\timage.png");
- assert_eq!(result, None);
- }
-
- #[test]
- fn test_parse_numstat_line_with_graph_prefix() {
- // Git graph prefixes the numstat line with graph characters
- let result = parse_numstat_line("| 10\t5\tfile.rs");
- assert_eq!(result, Some((10, 5)));
-
- // First numstat line after commit has "* | " prefix
- let result = parse_numstat_line("* | 11\t0\tCargo.toml");
- assert_eq!(result, Some((11, 0)));
-
- // Subsequent numstat lines have "| " prefix
- let result = parse_numstat_line("| 17\t3\tsrc/main.rs");
- assert_eq!(result, Some((17, 3)));
-
- // With ANSI colors (--color=always adds escape codes to graph)
- // ESC[31m = red, ESC[m = reset
- let esc = '\x1b';
- let ansi_colored = format!("{esc}[31m|{esc}[m 11\t0\tCargo.toml");
- let result = parse_numstat_line(&ansi_colored);
- assert_eq!(result, Some((11, 0)));
- }
-
- #[test]
- fn test_parse_numstat_line_not_numstat() {
- // Not a numstat line
- assert_eq!(parse_numstat_line("* abc1234 Fix bug"), None);
- assert_eq!(parse_numstat_line(""), None);
- assert_eq!(parse_numstat_line("regular text"), None);
- }
-
// format_log_output tests use dependency injection for deterministic time formatting.
// The format_log_output_with_formatter function accepts a time formatter closure.
diff --git a/src/git/diff.rs b/src/git/diff.rs
index b1c740291..5ed20406d 100644
--- a/src/git/diff.rs
+++ b/src/git/diff.rs
@@ -262,6 +262,66 @@ mod tests {
assert!(result.is_empty()); // Should skip non-numeric
}
+ // ============================================================================
+ // parse_numstat_line Tests
+ // ============================================================================
+
+ #[test]
+ fn test_parse_numstat_line_basic() {
+ // Tab-separated: added<TAB>deleted<TAB>filename
+ let result = parse_numstat_line("10\t5\tfile.rs");
+ assert_eq!(result, Some((10, 5)));
+ }
+
+ #[test]
+ fn test_parse_numstat_line_insertions_only() {
+ let result = parse_numstat_line("15\t0\tfile.rs");
+ assert_eq!(result, Some((15, 0)));
+ }
+
+ #[test]
+ fn test_parse_numstat_line_deletions_only() {
+ let result = parse_numstat_line("0\t8\tfile.rs");
+ assert_eq!(result, Some((0, 8)));
+ }
+
+ #[test]
+ fn test_parse_numstat_line_binary_file() {
+ // Binary files show "-" instead of numbers
+ let result = parse_numstat_line("-\t-\timage.png");
+ assert_eq!(result, None);
+ }
+
+ #[test]
+ fn test_parse_numstat_line_with_graph_prefix() {
+ // Git graph prefixes the numstat line with graph characters
+ let result = parse_numstat_line("| 10\t5\tfile.rs");
+ assert_eq!(result, Some((10, 5)));
+
+ // First numstat line after commit has "* | " prefix
+ let result = parse_numstat_line("* | 11\t0\tCargo.toml");
+ assert_eq!(result, Some((11, 0)));
+
+ // Subsequent numstat lines have "| " prefix
+ let result = parse_numstat_line("| 17\t3\tsrc/main.rs");
+ assert_eq!(result, Some((17, 3)));
+
+ // With ANSI colors (--color=always adds escape codes to graph)
+ // ESC[31m = red, ESC[m = reset
+ let esc = '\x1b';
+ let ansi_colored = format!("{esc}[31m|{esc}[m 11\t0\tCargo.toml");
+ let result = parse_numstat_line(&ansi_colored);
+ assert_eq!(result, Some((11, 0)));
+ }
+
+ #[test]
+ fn test_parse_numstat_line_not_numstat() {
+ // Not a numstat line
+ assert_eq!(parse_numstat_line("* abc1234 Fix bug"), None);
+ assert_eq!(parse_numstat_line(""), None);
+ assert_eq!(parse_numstat_line("regular text"), None);
+ }
+
// ============================================================================
// DiffStats Tests
// ============================================================================
diff --git a/src/git/mod.rs b/src/git/mod.rs
index 36d769a37..966bb642e 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -42,7 +42,7 @@ pub use error::{
};
pub use parse::{parse_porcelain_z, parse_untracked_files};
pub use repository::{Repository, ResolvedWorktree, set_base_path};
-pub use url::GitRemoteUrl;
+pub use url::{GitRemoteUrl, parse_owner_repo, parse_remote_host, parse_remote_owner};
/// Why branch content is considered integrated into the target branch.
///
/// Used by both `wt list` (for status symbols) and `wt remove` (for messages).
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 3c40d8396..33f2f8b47 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -167,6 +167,14 @@ impl Repository {
.unwrap_or(false)
}
+ /// Get the URL for a remote, if configured.
+ pub fn remote_url(&self, remote: &str) -> Option<String> {
+ self.run_command(&["remote", "get-url", remote])
+ .ok()
+ .map(|url| url.trim().to_string())
+ .filter(|url| !url.is_empty())
+ }
+
/// Check if a local git branch exists.
pub fn local_branch_exists(&self, branch: &str) -> anyhow::Result<bool> {
Ok(self
@@ -1608,12 +1616,12 @@ impl Repository {
// Try to get the remote URL first
let remote = self.primary_remote()?;
- if let Ok(url) = self.run_command(&["remote", "get-url", remote]) {
+ if let Some(url) = self.remote_url(remote) {
if let Some(parsed) = GitRemoteUrl::parse(url.trim()) {
return Ok(parsed.project_identifier());
}
// Fallback for URLs that don't fit host/owner/repo model (e.g., with ports)
- let url = url.trim().strip_suffix(".git").unwrap_or(url.trim());
+ let url = url.strip_suffix(".git").unwrap_or(url.as_str());
// Handle ssh:// format with port: ssh://git@host:port/path -> host/port/path
if let Some(ssh_part) = url.strip_prefix("ssh://") {
let ssh_part = ssh_part.strip_prefix("git@").unwrap_or(ssh_part);
diff --git a/src/git/url.rs b/src/git/url.rs
index 686c9b0ad..555b4a018 100644
--- a/src/git/url.rs
+++ b/src/git/url.rs
@@ -118,6 +118,39 @@ impl GitRemoteUrl {
}
}
+/// Extract owner from a git remote URL.
+///
+/// Used for client-side filtering of PRs/MRs by source repository. When multiple users
+/// have PRs with the same branch name (e.g., everyone has a `feature` branch), we need
+/// to identify which PR comes from *our* fork/remote, not just which PR we authored.
+///
+/// # Why not use `--author`?
+///
+/// The `gh pr list --author` flag filters by who *created* the PR, not whose fork
+/// the PR comes *from*. These are usually the same, but not always:
+/// - Maintainers may create PRs from contributor forks
+/// - Bots may create PRs on behalf of users
+/// - Organization repos: `--author company` doesn't match individual user PRs
+///
+/// # Why client-side filtering?
+///
+/// Neither `gh` nor `glab` CLI support server-side filtering by source repository.
+/// The `gh pr list --head` flag only accepts branch name, not `owner:branch` format.
+/// So we fetch PRs matching the branch name, then filter by `headRepositoryOwner`.
+pub fn parse_remote_owner(url: &str) -> Option<String> {
+ GitRemoteUrl::parse(url).map(|u| u.owner().to_string())
+}
+
+/// Extract owner and repository name from a git remote URL.
+pub fn parse_owner_repo(url: &str) -> Option<(String, String)> {
+ GitRemoteUrl::parse(url).map(|u| (u.owner().to_string(), u.repo().to_string()))
+}
+
+/// Extract hostname from a git remote URL.
+pub fn parse_remote_host(url: &str) -> Option<String> {
+ GitRemoteUrl::parse(url).map(|u| u.host().to_string())
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -198,6 +231,135 @@ mod tests {
assert_eq!(url.repo(), "project");
}
+ #[test]
+ fn test_parse_remote_owner() {
+ assert_eq!(
+ parse_remote_owner("https://github.com/max-sixty/worktrunk.git"),
+ Some("max-sixty".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner(" https://github.com/owner/repo\n"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("[email protected]:max-sixty/worktrunk.git"),
+ Some("max-sixty".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("ssh://[email protected]/owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("ssh://github.com/owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("https://gitlab.com/owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("https://gitlab.example.com/owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("[email protected]:owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("https://bitbucket.org/owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("[email protected]:owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("https://github.com/company-org/project.git"),
+ Some("company-org".to_string())
+ );
+ assert_eq!(
+ parse_remote_owner("http://github.com/owner/repo.git"),
+ Some("owner".to_string())
+ );
+ assert_eq!(parse_remote_owner("https://github.com/"), None);
+ assert_eq!(parse_remote_owner("[email protected]:"), None);
+ assert_eq!(parse_remote_owner(""), None);
+ }
+
+ #[test]
+ fn test_parse_remote_host() {
+ assert_eq!(
+ parse_remote_host("https://gitlab.com/owner/repo.git"),
+ Some("gitlab.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host("https://gitlab.example.com/owner/repo.git"),
+ Some("gitlab.example.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host(" https://github.com/owner/repo\n"),
+ Some("github.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host("http://gitlab.internal.company.com/owner/repo.git"),
+ Some("gitlab.internal.company.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host("[email protected]:owner/repo.git"),
+ Some("gitlab.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host("[email protected]:owner/repo.git"),
+ Some("gitlab.example.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host("ssh://[email protected]/owner/repo.git"),
+ Some("gitlab.example.com".to_string())
+ );
+ assert_eq!(
+ parse_remote_host("ssh://gitlab.example.com/owner/repo.git"),
+ Some("gitlab.example.com".to_string())
+ );
+ assert_eq!(parse_remote_host("https://"), None);
+ assert_eq!(parse_remote_host("git@"), None);
+ assert_eq!(parse_remote_host(""), None);
+ }
+
+ #[test]
+ fn test_parse_owner_repo() {
+ assert_eq!(
+ parse_owner_repo("https://github.com/owner/repo.git"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(
+ parse_owner_repo("https://github.com/owner/repo"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(
+ parse_owner_repo(" https://github.com/owner/repo.git\n"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(
+ parse_owner_repo("[email protected]:owner/repo.git"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(
+ parse_owner_repo("[email protected]:owner/repo"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(
+ parse_owner_repo("ssh://[email protected]/owner/repo.git"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(
+ parse_owner_repo("https://gitlab.com/owner/repo.git"),
+ Some(("owner".to_string(), "repo".to_string()))
+ );
+ assert_eq!(parse_owner_repo("https://github.com/owner/"), None);
+ assert_eq!(parse_owner_repo("[email protected]:owner/"), None);
+ assert_eq!(parse_owner_repo(""), None);
+ }
+
#[test]
fn test_project_identifier() {
let cases = [
diff --git a/src/shell.rs b/src/shell.rs
index ad475257f..13dd1e064 100644
--- a/src/shell.rs
+++ b/src/shell.rs
@@ -676,16 +676,6 @@ pub fn current_shell() -> Option<Shell> {
}
}
-/// Check if the current shell is zsh (based on $SHELL environment variable).
-///
-/// Used to determine if the user's primary shell is zsh when running `install`
-/// without a specific shell argument. If they're a zsh user, we show compinit
-/// hints; if they're using bash/fish, we skip the hint since zsh isn't their
-/// daily driver.
-pub fn is_current_shell_zsh() -> bool {
- current_shell() == Some(Shell::Zsh)
-}
-
#[cfg(test)]
mod tests {
use super::*;