gitremote

package
v0.50.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package gitremote parses git remote URLs into their owner / repo / host components across standard HTTPS, SSH URL, and SCP-style remotes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigSet added in v0.43.0

func ConfigSet(dir, key, value string) error

ConfigSet writes a repo-local (`git config`, no --global/--system) key to value for the git repository at dir. Used to install merge-driver definitions (merge.<name>.name, merge.<name>.driver) that must apply only to this clone, never to the operator's global git config.

func CurrentBranch added in v0.28.0

func CurrentBranch(dir string) (string, error)

CurrentBranch returns the short name of the branch currently checked out at dir (e.g. "main", "feature/foo"). It returns an error when dir is not a git repository, or when HEAD is detached (not pointing at a branch) — a detached HEAD has no branch name to report, and callers that need "is this invocation on branch X" (e.g. coordination-branch enforcement) should treat that error as "not on X" rather than guessing a name.

func HeadSHA added in v0.5.1

func HeadSHA(dir string) (string, error)

HeadSHA returns the 40-char hex SHA of HEAD for the git repository at dir. It returns an error when dir is not a git repository, has no commits yet, or any other `git rev-parse HEAD` failure occurs. Callers that need an always-succeed path (e.g. envelope auto-fill) should substitute their own fallback value on error rather than propagating it.

func OriginURL

func OriginURL(dir string) (string, error)

OriginURL returns the URL of the "origin" remote for the git repository at dir. Returns an error if dir is not a git repo or has no origin remote.

func TopLevel added in v0.43.0

func TopLevel(dir string) (string, error)

TopLevel returns the absolute path of the top level of the working tree containing dir (i.e. `git rev-parse --show-toplevel`). This is where .gitattributes and repo-local `git config` apply from, which may differ from a project root identified by a config file living in a subdirectory of the repository. Returns an error when dir is not inside a git working tree.

Types

type Remote

type Remote struct {
	Owner string
	Repo  string
	Host  string // e.g. "github.com"
}

Remote is a parsed git remote URL.

func Parse

func Parse(url string) (Remote, bool)

Parse extracts the owner/repo/host from a git remote URL. It returns (Remote, true) for any syntactically supported host.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL