git

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package git wraps the installed git executable. We deliberately shell out to the user's git rather than reimplementing transport, so their existing authentication, remotes, filters, attributes, diff drivers, and config all apply. This package owns repository semantics; nothing above it should exec git directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffSpec

type DiffSpec struct {
	// Context is the number of unified context lines (-U). Defaults to 3 when 0.
	Context int
	// Staged compares the index against HEAD (git diff --staged).
	Staged bool
	// Base, when set, compares merge-base(Base, HEAD)..HEAD (git diff Base...HEAD).
	Base string
	// RevA/RevB, when both set, compare two explicit revisions.
	RevA string
	RevB string
}

DiffSpec selects which comparison to produce.

func (DiffSpec) Title

func (s DiffSpec) Title() string

Title renders a short human description of what a spec compares.

type RemoteRef

type RemoteRef struct {
	Host  string
	Owner string
	Repo  string
}

RemoteRef identifies the host, owner, and repository of a git remote.

func ParseRemoteURL

func ParseRemoteURL(raw string) (RemoteRef, error)

ParseRemoteURL extracts host/owner/repo from a git remote URL. It accepts scp-like SSH ("git@github.com:owner/repo.git"), ssh:// URLs, and https:// URLs (with or without a trailing ".git"). The owner is the path up to the last segment, supporting nested groups (e.g. GitLab subgroups).

type Repository

type Repository struct {
	Root string
}

Repository is a handle to a git working tree rooted at Root.

func Open

func Open(ctx context.Context, dir string) (*Repository, error)

Open locates the repository that contains dir (or the current directory when dir is empty) and returns a handle to it.

func (*Repository) BlobID added in v0.0.4

func (r *Repository) BlobID(ctx context.Context, rev, path string) (string, error)

BlobID returns the object id of path at rev — the content identity the file cache keys on, so a change upstream changes the key instead of requiring invalidation.

func (*Repository) Diff

func (r *Repository) Diff(ctx context.Context, spec DiffSpec) ([]byte, error)

Diff runs the appropriate git diff for spec and returns the raw unified patch. The flags force a stable, parseable format regardless of user config: no color, no external diff drivers, default a/ b/ prefixes, rename detection.

func (*Repository) HeadOID

func (r *Repository) HeadOID(ctx context.Context) (string, error)

HeadOID returns the full object id of HEAD.

func (*Repository) MergeBase added in v0.0.5

func (r *Repository) MergeBase(ctx context.Context, a, b string) (string, error)

MergeBase returns the merge base of two revisions — the old side of a three-dot (base...HEAD) comparison.

func (*Repository) OriginRef

func (r *Repository) OriginRef(ctx context.Context) (RemoteRef, error)

OriginRef returns the parsed "origin" remote of the repository.

func (*Repository) RemoteRef

func (r *Repository) RemoteRef(ctx context.Context, name string) (RemoteRef, error)

RemoteRef returns the parsed URL of the named remote.

func (*Repository) ResolveRev

func (r *Repository) ResolveRev(ctx context.Context, name string) bool

ResolveRev reports whether name resolves to a revision in the repo.

func (*Repository) ShowFile added in v0.0.4

func (r *Repository) ShowFile(ctx context.Context, rev, path string) ([]byte, error)

ShowFile returns the content of path at rev ("" reads the working tree file, ":" the index) — the raw material of the full-file context view.

Jump to

Keyboard shortcuts

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