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 ¶
- type DiffSpec
- type RemoteRef
- type Repository
- func (r *Repository) BlobID(ctx context.Context, rev, path string) (string, error)
- func (r *Repository) Diff(ctx context.Context, spec DiffSpec) ([]byte, error)
- func (r *Repository) HeadOID(ctx context.Context) (string, error)
- func (r *Repository) MergeBase(ctx context.Context, a, b string) (string, error)
- func (r *Repository) OriginRef(ctx context.Context) (RemoteRef, error)
- func (r *Repository) RemoteRef(ctx context.Context, name string) (RemoteRef, error)
- func (r *Repository) ResolveRev(ctx context.Context, name string) bool
- func (r *Repository) ShowFile(ctx context.Context, rev, path string) ([]byte, error)
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.
type RemoteRef ¶
RemoteRef identifies the host, owner, and repository of a git remote.
func ParseRemoteURL ¶
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
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 ¶
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
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) ResolveRev ¶
func (r *Repository) ResolveRev(ctx context.Context, name string) bool
ResolveRev reports whether name resolves to a revision in the repo.