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.

Maintainers

Package info

github.com/jeffersongoncalves/laravel-zero-git

pkg:composer/jeffersongoncalves/laravel-zero-git

Fund package maintenance!

jeffersongoncalves

Statistics

Installs: 9

Dependents: 2

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.1 2026-06-23 01:17 UTC

This package is auto-updated.

Last update: 2026-06-23 11:01:28 UTC


README

laravel-zero-git

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.git
  • https://host/owner/repo (with or without .git, with or without user@)

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.