git_worktree_cli/core/
utils.rs

1//! Core utility functions
2//!
3//! This module contains utility functions used throughout the core module.
4
5use std::path::Path;
6
7/// Check if a path looks like a git SSH URL
8pub fn is_git_ssh_url(url: &str) -> bool {
9    url.starts_with("git@") || url.contains(":")
10}
11
12/// Convert SSH URL to HTTPS URL for cloning
13pub fn ssh_to_https_url(url: &str) -> String {
14    if url.starts_with("git@") {
15        // Convert git@github.com:user/repo.git to https://github.com/user/repo.git
16        url.replace(":", "/").replace("git@", "https://")
17    } else {
18        url.to_string()
19    }
20}
21
22/// Get the repository name from a URL
23pub fn get_repo_name_from_url(url: &str) -> Option<String> {
24    let path = url.strip_suffix(".git").unwrap_or(url);
25
26    Path::new(path)
27        .file_name()
28        .and_then(|name| name.to_str())
29        .map(|s| s.to_string())
30}
31
32/// Check if a branch name is a main branch (shouldn't be deleted)
33pub fn is_main_branch(branch_name: &str) -> bool {
34    matches!(branch_name, "main" | "master" | "develop" | "dev")
35}