12 releases

0.4.5 Sep 6, 2024
0.4.4 Nov 5, 2022
0.4.3 Oct 11, 2022
0.4.2 May 30, 2022
0.1.0 Feb 6, 2020

#155 in Parser implementations

Download history 1326/week @ 2024-10-04 1264/week @ 2024-10-11 1284/week @ 2024-10-18 972/week @ 2024-10-25 963/week @ 2024-11-01 988/week @ 2024-11-08 1053/week @ 2024-11-15 1743/week @ 2024-11-22 1624/week @ 2024-11-29 1598/week @ 2024-12-06 1938/week @ 2024-12-13 1044/week @ 2024-12-20 1734/week @ 2024-12-27 2406/week @ 2025-01-03 2325/week @ 2025-01-10 1445/week @ 2025-01-17

7,963 downloads per month
Used in 30 crates (25 directly)

MIT license

25KB
362 lines

git-url-parse

Minimum Supported Rust Version Crates.io Github actions CI status docs.rs License Maintenance

Supports common protocols as specified by the Pro Git book

See: 4.1 Git on the Server - The Protocols

Supports parsing SSH/HTTPS repo urls for:

  • Github
  • Bitbucket
  • Azure Devops

See tests/parse.rs for expected output for a variety of inputs.


URLs that use the ssh:// protocol (implicitly or explicitly) undergo a small normalization process in order to be parsed.

Internally uses Url::parse() from the Url crate after normalization.

Examples

Run example with debug output

$ RUST_LOG=git_url_parse cargo run --example multi
$ RUST_LOG=git_url_parse cargo run --example trim_auth 

Simple usage and output

$ cargo run --example readme
use git_url_parse::GitUrl;

fn main() {
    println!("SSH: {:#?}", GitUrl::parse("git@github.com:tjtelan/git-url-parse-rs.git"));
    println!("HTTPS: {:#?}", GitUrl::parse("https://github.com/tjtelan/git-url-parse-rs"));
}

Example Output

SSH: Ok(
    GitUrl {
        host: Some(
            "github.com",
        ),
        name: "git-url-parse-rs",
        owner: Some(
            "tjtelan",
        ),
        organization: None,
        fullname: "tjtelan/git-url-parse-rs",
        scheme: Ssh,
        user: Some(
            "git",
        ),
        token: None,
        port: None,
        path: "tjtelan/git-url-parse-rs.git",
        git_suffix: true,
        scheme_prefix: false,
    },
)
HTTPS: Ok(
    GitUrl {
        host: Some(
            "github.com",
        ),
        name: "git-url-parse-rs",
        owner: Some(
            "tjtelan",
        ),
        organization: None,
        fullname: "tjtelan/git-url-parse-rs",
        scheme: Https,
        user: None,
        token: None,
        port: None,
        path: "/tjtelan/git-url-parse-rs",
        git_suffix: false,
        scheme_prefix: true,
    },
)

Dependencies

~2–3MB
~57K SLoC