git

package
v0.2.0-alpha.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentBranch

func CurrentBranch(dir string) string

CurrentBranch returns the current branch name when dir is the root of a Git repository. Returns empty string if dir is not a repo, git is unavailable, or on error.

func Fetch

func Fetch(ctx context.Context, dir string) error

Fetch updates the remote-tracking refs for dir.

This is the only function here that touches the network, and it exists so that reaching the network is something a user asks for by name. Discovery, status, and provenance must never call it.

func IsRepository

func IsRepository(dir string) bool

IsRepository reports whether dir is the root of a checkout.

The check is for dir's own .git rather than asking Git, because `git status` inside a plain directory answers for the nearest enclosing repository. A plugins directory that happens to sit inside someone's home checkout would otherwise give every plugin that repository's commit.

func ReadRemoteURL

func ReadRemoteURL(ctx context.Context, dir string) string

ReadRemoteURL returns the fetch URL of dir's origin, or "" when the checkout has no remote. A plugin developed locally and never pushed is ordinary, not an error.

Types

type ChangeStatus

type ChangeStatus string
const (
	StatusAdded    ChangeStatus = "added"
	StatusModified ChangeStatus = "modified"
	StatusDeleted  ChangeStatus = "deleted"
	StatusRenamed  ChangeStatus = "renamed"
)

type ChangedFile

type ChangedFile struct {
	Path      string       `json:"path"`
	OldPath   string       `json:"old_path,omitempty"`
	Status    ChangeStatus `json:"status"`
	Additions int          `json:"additions"`
	Deletions int          `json:"deletions"`
	Patch     string       `json:"patch,omitempty"`
	Binary    bool         `json:"binary,omitempty"`
	Truncated bool         `json:"truncated,omitempty"`
}

type Status

type Status struct {
	// Commit is the full hash HEAD points at, empty on an unborn branch.
	Commit string
	// Branch is empty when HEAD is detached.
	Branch   string
	Detached bool
	// Dirty covers tracked modifications and untracked files alike: either
	// means the directory is not the commit it names.
	Dirty bool

	// HasUpstream reports whether the branch tracks one. Ahead and Behind
	// count commits against the tracking ref as it is known locally, so they
	// are only current for as long as the last fetch is.
	HasUpstream bool
	Ahead       int
	Behind      int
}

Status is what local Git metadata says about a working tree.

Nothing here contacts a remote. Plugin discovery may never make a network request, and a status read that could block on the network would put that invariant one flag away from being broken.

func ReadStatus

func ReadStatus(ctx context.Context, dir string) (Status, error)

ReadStatus reads commit, branch, and dirty state in one Git invocation.

Porcelain v2 reports all three: the header lines carry the commit and branch, and any non-header line is a change. Asking separately would cost a process per fact on a path a run repeats.

type WorkspaceDiff

type WorkspaceDiff struct {
	Workspace string        `json:"workspace"`
	Files     []ChangedFile `json:"files"`
	Error     string        `json:"error,omitempty"`
}

func ReadWorkspace

func ReadWorkspace(ctx context.Context, workspace string) (WorkspaceDiff, error)

Jump to

Keyboard shortcuts

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