pub fn parse_github_folder_url(url: &str) -> Option<ParsedGitUrl>Expand description
Parses a GitHub folder URL into its constituent parts.
Handles the official format (.../tree/branch/path) as well as common “sloppy” formats
like .../branch/path or just .../path (which assumes the default branch).
§Returns
Some(ParsedGitUrl) if the URL is a parsable GitHub folder URL, otherwise None.
§Examples
use dircat::git::{parse_github_folder_url, ParsedGitUrl};
let url = "https://github.com/rust-lang/cargo/tree/master/src/cargo";
let parsed = parse_github_folder_url(url).unwrap();
assert_eq!(parsed, ParsedGitUrl {
clone_url: "https://github.com/rust-lang/cargo.git".to_string(),
branch: "master".to_string(),
subdirectory: "src/cargo".to_string(),
});
// A "sloppy" URL without the /tree/ part assumes the default branch.
let sloppy_url = "https://github.com/rust-lang/cargo/src/cargo";
let sloppy_parsed = parse_github_folder_url(sloppy_url).unwrap();
assert_eq!(sloppy_parsed, ParsedGitUrl {
clone_url: "https://github.com/rust-lang/cargo.git".to_string(),
branch: "HEAD".to_string(), // "HEAD" indicates default branch
subdirectory: "src/cargo".to_string(),
});
// A root repository URL is not a folder URL.
assert!(parse_github_folder_url("https://github.com/rust-lang/cargo").is_none());