Skip to main content

normalize_git_url

Function normalize_git_url 

Source
pub fn normalize_git_url(url: &str) -> String
Expand description

Normalize a git remote URL to a canonical short form.

Converts common hosting URLs to compact identifiers:

  • git@github.com:org/repo.git -> github:org/repo
  • https://github.com/org/repo.git -> github:org/repo
  • git@gitlab.com:org/repo.git -> gitlab:org/repo
  • https://gitlab.com/org/repo.git -> gitlab:org/repo

ยงExamples

use toolpath_git::normalize_git_url;

assert_eq!(normalize_git_url("git@github.com:org/repo.git"), "github:org/repo");
assert_eq!(normalize_git_url("https://gitlab.com/org/repo"), "gitlab:org/repo");

// Unknown hosts pass through unchanged
assert_eq!(
    normalize_git_url("https://bitbucket.org/org/repo"),
    "https://bitbucket.org/org/repo",
);