git-url-parse

A Rust parser for the URLs used by git, extracting components and host provider details.

Library
Cargo
v0.6.0
23stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
29/100Needs Attention
Development Activity0
Maintenance20
Community24
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture80
Code Quality80
Innovation68
Learning Curve82

git-url-parse is a Rust crate that parses the many URL forms accepted by git clone into a structured GitUrl type. It handles SSH, HTTP/HTTPS, and file-based schemes, including the scp-like git@host:owner/repo.git syntax that standard URL parsers cannot handle, and exposes the scheme, host, port, path, and other components through typed accessors.

Beyond raw parsing, it can extract host-provider information such as the repository owner and name, with built-in support for generic Git hosts, GitLab, and Azure DevOps, plus a GitProvider trait for adding custom providers. Optional features add serde support, url crate validation, and log-based debugging.

What You Get

  • A GitUrl::parse entry point that accepts SSH, HTTP/HTTPS, file, and scp-style git URLs.
  • Typed accessors for scheme, host, port, path, user, and other URL components.
  • Host-provider extraction (owner/repo) with built-in Generic, GitLab, and Azure DevOps providers.
  • A GitProvider trait for implementing parsing rules for custom Git hosts.
  • Optional serde (de)serialization, url-crate validation, and log debugging via cargo features.

Common Use Cases

  • Normalizing a user-supplied git remote URL to extract its host, owner, and repository name.
  • Building CI/CD or automation tooling that must understand many git URL formats.
  • Deriving provider-specific metadata (e.g. GitLab or Azure DevOps project structure) from a clone URL.

Under The Hood

Architecture - Parsing is built on the nom parser-combinator crate. The types/ module defines the core GitUrl struct (spec.rs), the error type (error.rs, via thiserror), and a provider/ submodule with a GitProvider trait plus concrete generic, gitlab, and azure_devops implementations. GitUrl::parse runs the nom grammar to split a URL into components, and provider_info() maps the parsed path onto provider-specific owner/repo semantics. getset generates the typed accessor methods.

Tech Stack - Rust 2024 edition (MSRV 1.85), depending on nom 8 for parsing, getset for accessors, and thiserror 2 for errors. Optional dependencies behind features add serde, log, and the url crate (the last enabled by default for validation).

Code Quality - The crate ships a tests/ directory covering parse, provider, auth-trimming, and url-interop scenarios, plus examples and a maintained CHANGELOG generated via git-cliff. Errors are modeled with thiserror rather than panicking, and the provider abstraction keeps host-specific logic isolated and testable.

API Design - The public surface is small and discoverable: GitUrl::parse returns a Result, component accessors read naturally (host(), path(), scheme()), and provider_info() yields typed provider structs. The README’s runnable quick example gets users productive quickly, and the GitProvider trait offers a clean extension point without complicating the common path.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search