11 releases

0.4.4 Nov 5, 2022
0.4.2 May 30, 2022
0.4.0 Nov 14, 2021
0.3.1 Jan 27, 2021
0.1.0 Feb 6, 2020

#418 in Parser implementations

Download history 1583/week @ 2024-02-15 1171/week @ 2024-02-22 1057/week @ 2024-02-29 1244/week @ 2024-03-07 1204/week @ 2024-03-14 1308/week @ 2024-03-21 1350/week @ 2024-03-28 834/week @ 2024-04-04 1376/week @ 2024-04-11 1488/week @ 2024-04-18 1095/week @ 2024-04-25 1251/week @ 2024-05-02 991/week @ 2024-05-09 1357/week @ 2024-05-16 1374/week @ 2024-05-23 767/week @ 2024-05-30

4,634 downloads per month
Used in 22 crates (20 directly)

MIT license

22KB
292 lines

git-url-parse

Minimum Supported Rust Version Crates.io Crates.io Github actions build status docs.rs licence 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

~8–11MB
~233K SLoC