git

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: GPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.New("git: operation not supported on this backend")
	ErrNotARepo    = errors.New("git: not inside a git repository")
	ErrNoGitCLI    = errors.New("git: `git` binary not on PATH and go-git fallback unavailable")
)

Functions

func Commit added in v1.5.0

func Commit(ctx context.Context, repoRoot, message string) (string, error)

Commit creates a commit from the currently staged changes with the given message, returning git's summary line(s) (e.g. "[main abc1234] feat: …").

This is the one place the tool writes to git (ADR-0019, superseding ADR-0015 §6's read-only stance for the authoring path). It is reached only after the `commit` command has the user's explicit confirmation (or --yes).

The message is fed via stdin (`git commit -F -`) rather than `-m` so that multi-line bodies and arbitrary content commit verbatim without any shell-quoting or newline pitfalls, and so the behaviour is identical across platforms. Commit hooks run as usual (no --no-verify) — a failing pre-commit hook surfaces as an error here.

func FindRepo

func FindRepo(start string) (string, error)

Types

type CLIRepo

type CLIRepo struct {
	// contains filtered or unexported fields
}

func NewCLIRepo

func NewCLIRepo(root string) (*CLIRepo, error)

func (*CLIRepo) BranchDiff

func (r *CLIRepo) BranchDiff(target string) (Diff, error)

func (*CLIRepo) CommitDiff

func (r *CLIRepo) CommitDiff(hash string) (Diff, error)

func (*CLIRepo) Diff added in v0.9.0

func (r *CLIRepo) Diff(args []string) (Diff, error)

Diff is the generic `git diff <args>` passthrough used by the `commitbrief diff` subcommand. We always inject `--no-color` and `--no-ext-diff` so the parser/renderer pipeline sees the same stable unified-diff shape the other Diff*() helpers produce. The caller is responsible for validating args (e.g. requiring at least one positional ref) — empty args yields `git diff` (i.e. unstaged), which is identical to UnstagedDiff() and discouraged.

func (*CLIRepo) FileDiff

func (r *CLIRepo) FileDiff(path string) (Diff, error)

func (*CLIRepo) RangeDiff

func (r *CLIRepo) RangeDiff(target, feature string) (Diff, error)

func (*CLIRepo) Root

func (r *CLIRepo) Root() string

func (*CLIRepo) StagedDiff

func (r *CLIRepo) StagedDiff() (Diff, error)

func (*CLIRepo) UnstagedDiff

func (r *CLIRepo) UnstagedDiff() (Diff, error)

type CommitMeta added in v1.6.0

type CommitMeta struct {
	Short   string   // abbreviated hash, e.g. "a1b2c3d"
	Subject string   // first line of the commit message
	Body    string   // remainder of the commit message (may be empty)
	Files   []string // post-change paths touched by this commit
}

CommitMeta is one commit's human-relevant metadata, used by the `commitbrief summary` command to attribute logical changes to the commit(s) that introduced them. It carries no diff body — the cumulative range diff is fetched separately via the Diff() passthrough — only the short hash, the author's subject/body (the "commit message" the summary is asked to take into account), and the paths the commit touched (so the model can map a logical area back to the commit responsible for it).

func RangeCommits added in v1.6.0

func RangeCommits(ctx context.Context, repoRoot string, logArgs []string) ([]CommitMeta, error)

RangeCommits returns the commit manifest for a log range (e.g. {"main..develop"} or {"HEAD~3..HEAD"}). It is read-only — `git log` only — and the caller is expected to have already derived a clean two-endpoint range from the user's diff arguments (see deriveLogRange in the cli package); arbitrary single refs would make `git log` walk all of history.

Merge commits are excluded (--no-merges): their diffs are already covered by the cumulative range diff and their subjects ("Merge branch …") add noise rather than intent. The result is capped at maxRangeCommits.

Best-effort by contract: a non-zero git exit (bad range, shallow clone, etc.) returns an error the caller may treat as "no manifest" and degrade to a diff-only summary rather than failing the whole command.

type Diff

type Diff struct {
	Content string
	Origin  Origin
	Args    map[string]string
}

func (Diff) Empty

func (d Diff) Empty() bool

type DispatchOptions

type DispatchOptions struct {
	Logger *slog.Logger
}

type DispatchRepo

type DispatchRepo struct {
	// contains filtered or unexported fields
}

func Open

func Open(root string, opts DispatchOptions) (*DispatchRepo, error)

func (*DispatchRepo) BranchDiff

func (d *DispatchRepo) BranchDiff(target string) (Diff, error)

func (*DispatchRepo) CommitDiff

func (d *DispatchRepo) CommitDiff(hash string) (Diff, error)

func (*DispatchRepo) Diff added in v0.9.0

func (d *DispatchRepo) Diff(args []string) (Diff, error)

func (*DispatchRepo) FileDiff

func (d *DispatchRepo) FileDiff(path string) (Diff, error)

func (*DispatchRepo) RangeDiff

func (d *DispatchRepo) RangeDiff(target, feature string) (Diff, error)

func (*DispatchRepo) Root

func (d *DispatchRepo) Root() string

func (*DispatchRepo) StagedDiff

func (d *DispatchRepo) StagedDiff() (Diff, error)

func (*DispatchRepo) UnstagedDiff

func (d *DispatchRepo) UnstagedDiff() (Diff, error)

type GoGitRepo

type GoGitRepo struct {
	// contains filtered or unexported fields
}

func NewGoGitRepo

func NewGoGitRepo(root string) (*GoGitRepo, error)

func (*GoGitRepo) BranchDiff

func (g *GoGitRepo) BranchDiff(target string) (Diff, error)

func (*GoGitRepo) CommitDiff

func (g *GoGitRepo) CommitDiff(hash string) (Diff, error)

func (*GoGitRepo) Diff added in v0.9.0

func (g *GoGitRepo) Diff([]string) (Diff, error)

Diff (arbitrary `git diff <args>` passthrough) is intentionally unsupported on the go-git backend — re-implementing every git diff CLI shorthand (HEAD, A..B, A...B, --merge-base, etc.) by hand would balloon the surface area and drift. DispatchRepo falls back to the CLI here.

func (*GoGitRepo) FileDiff

func (g *GoGitRepo) FileDiff(string) (Diff, error)

func (*GoGitRepo) RangeDiff

func (g *GoGitRepo) RangeDiff(target, feature string) (Diff, error)

func (*GoGitRepo) Root

func (g *GoGitRepo) Root() string

func (*GoGitRepo) StagedDiff

func (g *GoGitRepo) StagedDiff() (Diff, error)

func (*GoGitRepo) UnstagedDiff

func (g *GoGitRepo) UnstagedDiff() (Diff, error)

type Origin

type Origin string
const (
	OriginStaged   Origin = "staged"
	OriginUnstaged Origin = "unstaged"
	OriginFile     Origin = "file"
	OriginCommit   Origin = "commit"
	OriginRange    Origin = "range"
	OriginBranch   Origin = "branch"
	OriginDiff     Origin = "diff" // `commitbrief diff <args...>` passthrough
)

type Repo

type Repo interface {
	StagedDiff() (Diff, error)
	UnstagedDiff() (Diff, error)
	FileDiff(path string) (Diff, error)
	CommitDiff(hash string) (Diff, error)
	RangeDiff(target, feature string) (Diff, error)
	BranchDiff(target string) (Diff, error)
	// Diff is the generic `git diff <args>` passthrough used by the
	// `commitbrief diff` subcommand. args are forwarded verbatim
	// after `--no-color --no-ext-diff` so the renderer/parser see
	// stable unified-diff output. Backends that can't faithfully
	// implement arbitrary git arg combinations may return
	// ErrUnsupported; the DispatchRepo then falls through to the
	// CLI path.
	Diff(args []string) (Diff, error)
	Root() string
}

Jump to

Keyboard shortcuts

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