jeffersongoncalves/laravel-zero-git
Composer 安装命令:
composer require jeffersongoncalves/laravel-zero-git
包简介
Detect the current repository from the git remote: parse SSH/HTTPS remote URLs into host/owner/repo and build a stable slug, used by CLIs that auto-detect their workspace/repo.
README 文档
README
laravel-zero-git
Detect the current repository from its git remote. This package parses SSH and
HTTPS remote URLs into host / owner / repo, builds a stable slug, and can
read the remote of a working directory directly from git.
It is used by Laravel Zero CLIs (such as Bitbucket / Jira tools) that auto-detect their workspace and repository from the local git checkout.
Why
CLIs that operate on "the current repo" need a reliable way to turn a git
remote URL into structured data, regardless of whether the remote is an SSH or
HTTPS URL, with or without a .git suffix, with or without embedded
credentials or a port. This package centralizes that parsing in one tested,
framework-free place.
Installation
composer require jeffersongoncalves/laravel-zero-git
Requires PHP ^8.2. No other dependencies.
Usage
Parse a remote URL
use JeffersonGoncalves\LaravelZero\Git\GitRemoteParser; $info = GitRemoteParser::parse('git@github.com:acme/widgets.git'); $info->host; // "github.com" $info->owner; // "acme" $info->repo; // "widgets" $info->fullName(); // "acme/widgets" GitRemoteParser::parse('not a url'); // null
Supported shapes:
git@host:owner/repo.git(SSH scp-like)ssh://git@host:port/owner/repo.githttps://host/owner/repo(with or without.git, with or withoutuser@)
Build a stable slug
GitRemoteParser::slug('git@github.com:Acme/Widgets.git'); // "acme-widgets"
The slug is a lowercased, sanitized owner-repo string, suitable as a stable
key for per-repository config files.
Resolve from the current checkout
use JeffersonGoncalves\LaravelZero\Git\RepositoryResolver; $resolver = new RepositoryResolver(); // current working directory $info = $resolver->resolve(); // RemoteInfo|null (reads `origin`) $resolver->resolve('upstream'); // a different remote $resolver->currentRemoteUrl(); // the raw URL string, or null // Point it at a specific directory: $resolver = new RepositoryResolver('/path/to/repo');
resolve() and currentRemoteUrl() return null when the directory is not a
git repository or the remote does not exist / cannot be parsed.
Public classes
| Class | Purpose |
|---|---|
JeffersonGoncalves\LaravelZero\Git\RemoteInfo |
Readonly DTO: host, owner, repo, fullName() |
JeffersonGoncalves\LaravelZero\Git\GitRemoteParser |
parse(string): ?RemoteInfo, slug(string): ?string |
JeffersonGoncalves\LaravelZero\Git\RepositoryResolver |
resolve(?string): ?RemoteInfo, currentRemoteUrl(?string): ?string |
License
MIT. See LICENSE.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-23
