2 releases

0.5.1 Aug 18, 2023
0.5.0 Jul 2, 2023

#1309 in Parser implementations

Download history 51/week @ 2024-01-23 57/week @ 2024-01-30 61/week @ 2024-02-06 24/week @ 2024-02-13 89/week @ 2024-02-20 102/week @ 2024-02-27 65/week @ 2024-03-05 60/week @ 2024-03-12 135/week @ 2024-03-19 63/week @ 2024-03-26 46/week @ 2024-04-02 28/week @ 2024-04-09 166/week @ 2024-04-16 188/week @ 2024-04-23

442 downloads per month
Used in 2 crates

MIT license

25KB
456 lines

parse-git-url

Build Status

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=parse_git_url cargo run --example multi
$ RUST_LOG=parse_git_url cargo run --example trim_auth

Simple usage and output

$ cargo run --example readme
use parse_git_url::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,
    },
)

Acknowledgments

This repository has been forked from tjtelan/git-url-parse-rs. All credit goes to the original author.

Dependencies

~2MB
~66K SLoC