Git Url Parse
Parses url used by git (e.g. git clone <url>
)
Features
-
🔍 Parses
git clone
compatible urls intoGitUrl
- Supports multiple Git URL schemes (SSH, HTTP, HTTPS, File)
- Inspired by RFC 3986 with adaptations to support Git urls
-
🏗️ Host provider info extraction
- Easy to implement trait
GitProvider
for custom provider parsing - Built-in support for multiple Git hosting providers
- Generic (
git@host:owner/repo.git
style urls) - GitLab
- Azure DevOps
- Generic (
- Easy to implement trait
Quick Example
use ;
use GitProvider;
use GenericProvider;
Limitations
Intended only for git repo urls. Url spec RFC 3986 is not fully implemented.
- No support for:
- Query parameters
- Fragment identifiers
- Percent-encoding
- Complex IP address formats
Install
cargo add git-url-parse
Cargo Features
log
Enable for internal debug!
output from log
serde
Enable for serde Serialize
/Deserialize
on GitUrl
url
(enabled by default)
Uses url during parsing for full url validation
Migration from 0.4.x and earlier
This crate was one of my first serious projects in Rust. Because I was still learning, it had some maintenance problems and was a bit awkward to use. In version 0.5, I rewrote most of it to fix those issues.
The GitUrl
struct is only meant to handle parsing urls used by git
, which the url crate doesn't handle. The recent updates make it so the input string is parsed and internally stored into a simple string slice (&str
). And, instead of exposing all the internal fields of the struct, those details are hidden, and we use methods to interact with it.
The GitProvider
trait helps extract common pieces of information that are often found in different url patterns using the GitUrl::provider_info
method. Several example provider parsers are included to show how this works. The result of GitUrl::parse
is more straightforward to use, but the internal details are hidden, and working with provider-specific information at the git host level is more specialized.
The most common pattern for git url paths, like /owner/repo.git
, is handled by GenericProvider
.
There's also AzureDevOpsProvider
, which is designed for Azure DevOps urls that follow the org
, project
, repo
pattern.
Finally, there's a new supported provider called GitLabProvider
, which is for GitLab urls. It supports the common owner/repo
pattern shared with GenericProvider
, and also handles GitLab’s subgroups.