{"modulePath":"github.com/CommitBrief/commitbrief","version":"v1.23.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package git\n\n## Constants\n\n```go\nconst (\n\t// DefaultMaxCommits bounds how many matching commits are folded into one\n\t// review. A broad filter (`--author me` on a year-old repo) would\n\t// otherwise assemble a diff far past any model's context window.\n\tDefaultMaxCommits = 200\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrNotARepo = errors.New(\"git: not inside a git repository\")\n\tErrNoGitCLI = errors.New(\"git: `git` binary not found on PATH\")\n)\n```\n\n## Functions\n\n```go\nfunc Commit(ctx context.Context, repoRoot, message string) (string, error)\n```\nCommit creates a commit from the currently staged changes with the given message, returning git's summary line(s) (e.g. \"\\[main abc1234] feat: …\").\n\nThis 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).\n\nThe 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.\n\n```go\nfunc DefaultBranch(ctx context.Context, repoRoot string) string\n```\nDefaultBranch resolves the repo's base branch: the target of refs/remotes/origin/HEAD when it exists, else the first of main/master/trunk that does, else the current HEAD. It never fails — a topology view with an imperfect base is far more useful than an error.\n\n```go\nfunc FilteredDiff(ctx context.Context, repoRoot string, f CommitFilter) (Diff, Selection, error)\n```\nFilteredDiff selects the commits matching f and returns their concatenated patches together with the selection metadata. It is read-only: \\`git log\\`, \\`git for-each-ref\\`, \\`git rev-list\\`, \\`git show\\`.\n\n```go\nfunc FindRepo(start string) (string, error)\n```\n\n```go\nfunc PatchesFor(ctx context.Context, repoRoot string, commits []CommitMeta) (string, error)\n```\nPatchesFor is phase B: the concatenated patches of the given commits, in the order given.\n\n\\`git show\\` is used rather than \\`git log -p\\` because we need per-commit framing we control. A raw \\`git log -p\\` interleaves the commit message indented by four spaces, and internal/diff's parser reads a leading-space line as hunk CONTEXT — a message body would be silently absorbed into the previous hunk. Emitting a bare record separator as the format and slicing each block from its first \\`diff --git\\` removes that whole class of problem.\n\n\\`-m --first-parent\\` is what makes a merge commit produce a patch at all (git shows nothing for a merge otherwise); it is a no-op on ordinary commits.\n\n```go\nfunc RefsByCommit(ctx context.Context, repoRoot string) (map[string][]string, error)\n```\nRefsByCommit maps a commit hash to the short names of every branch and tag pointing at it, for the graph's \\`(main, v1.2.0)\\` labels.\n\nBest-effort: a repo with no refs, or a git that refuses the query, yields an empty map rather than an error — labels are decoration, and a graph without them is still a graph.\n\n```go\nfunc WalkLimit() int\n```\nWalkLimit reports the fixed ceiling on how many commits one selection inspects (see walkLimit), for callers that tell the user when it was hit.\n\n## Types\n\n```go\ntype Branch struct {\n\tName    string    // short ref name, e.g. \"main\" or \"origin/feature/x\"\n\tHash    string    // commit the ref points at\n\tRemote  bool      // true for refs/remotes/*\n\tSubject string    // the tip commit's subject\n\tAuthor  string    // the tip commit's author name\n\tDate    time.Time // the tip commit's author date\n\tAhead   int       // commits on this ref that the base lacks\n\tBehind  int       // commits on the base that this ref lacks\n\tIsBase  bool      // this ref IS the base; Ahead/Behind are 0 by definition\n}\n```\nBranch is one ref plus its position relative to the base branch.\n\n```go\nfunc BranchTopology(ctx context.Context, repoRoot, base string) ([]Branch, error)\n```\nBranchTopology returns every local and remote-tracking branch, each measured against base. A base of \"\" is resolved with DefaultBranch.\n\nAhead/behind are computed per ref with \\`git rev-list --left-right --count base...ref\\`, which is symmetric-difference counting — exactly what \"3 ahead, 12 behind\" means to a human. Refs are ordered base-first, then local, then remote, then by name, so the output is deterministic.\n\n```go\ntype CLIRepo struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewCLIRepo(root string) (*CLIRepo, error)\n```\n\n```go\nfunc (r *CLIRepo) Diff(args []string) (Diff, error)\n```\nDiff is the generic \\`git diff \\\u003cargs\u003e\\` 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.\n\n```go\nfunc (r *CLIRepo) Root() string\n```\n\n```go\nfunc (r *CLIRepo) StagedDiff() (Diff, error)\n```\n\n```go\nfunc (r *CLIRepo) UnstagedDiff() (Diff, error)\n```\n\n```go\ntype CommitFilter struct {\n\t// Authors / Committers match case-insensitively against BOTH the name and\n\t// the email, so `--author ayse` and `--author ayse@example.com` both work.\n\t// Multiple values are OR'd; the two kinds are AND'd with each other.\n\tAuthors    []string\n\tCommitters []string\n\n\t// Since / Until bound the author date. Zero means unbounded. Until is\n\t// expected to already carry the end-of-day time (the CLI expands\n\t// --end-date so the named day is inclusive).\n\tSince time.Time\n\tUntil time.Time\n\n\t// Text matches the commit subject+body, and additionally the NAME of a\n\t// branch/remote ref — a ref whose short name contains Text contributes\n\t// the commits unique to it (phase A′).\n\tText string\n\n\t// Merges includes merge commits in the selection. Off by default: a\n\t// merge's changes are already carried by the commits it merges, and its\n\t// patch is noise.\n\tMerges bool\n\n\t// MaxCommits caps the selection; 0 means DefaultMaxCommits.\n\tMaxCommits int\n\n\t// Rev is the revision range to walk, e.g. [\"main..HEAD\"]. Empty means\n\t// [\"HEAD\"] — the implicit history walk.\n\tRev []string\n}\n```\nCommitFilter is the commit-level narrowing requested on the command line. The zero value selects nothing and reports Active() == false, which is how the pipeline decides to keep using the ordinary \\`git diff\\` path.\n\n```go\nfunc (f CommitFilter) Active() bool\n```\nActive reports whether any \\*selecting\\* filter is set. Merges and MaxCommits are deliberately excluded: they only modify a selection, they never create one, so \\`--merges\\` alone must not silently turn a staged review into a history walk. The CLI rejects a modifier used on its own.\n\n```go\ntype CommitMeta struct {\n\tHash           string    // full 40-hex hash; empty for RangeCommits records\n\tParents        []string  // full parent hashes (%P); empty for RangeCommits records\n\tShort          string    // abbreviated hash, e.g. \"a1b2c3d\"\n\tAuthor         string    // author name (%an)\n\tAuthorEmail    string    // author email (%ae)\n\tCommitter      string    // committer name (%cn)\n\tCommitterEmail string    // committer email (%ce)\n\tDate           time.Time // author date (%aI), parsed from strict ISO 8601\n\tSubject        string    // first line of the commit message\n\tBody           string    // remainder of the commit message (may be empty)\n\tFiles          []string  // post-change paths touched by this commit\n}\n```\nCommitMeta is one commit's human-relevant metadata. It carries no diff body — patches are fetched separately (via the Diff() passthrough for a range, or PatchesFor for a selected commit set) — only the identity, the author's subject/body (the \"commit message\"), and the paths the commit touched (so the model can map a logical area back to the commit responsible for it).\n\nTwo producers fill it, and they populate different subsets:\n\n  - RangeCommits (the \\`commitbrief summary\\` manifest) sets Short, Subject, Body, Files. The identity/date fields stay zero — the manifest never needed them.\n  - SelectCommits (the commit-level filters) sets every field, because author/committer/date matching happens on this struct and the commit graph (ADR-0037) needs Parents to lay out its lanes.\n\n```go\nfunc RangeCommits(ctx context.Context, repoRoot string, logArgs []string) ([]CommitMeta, error)\n```\nRangeCommits 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.\n\nMerge 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.\n\nBest-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.\n\n```go\ntype Diff struct {\n\tContent string\n\tOrigin  Origin\n\tArgs    map[string]string\n}\n```\n\n```go\nfunc (d Diff) Empty() bool\n```\n\n```go\ntype DispatchOptions struct {\n\tLogger *slog.Logger\n}\n```\n\n```go\ntype DispatchRepo struct {\n\t// contains filtered or unexported fields\n}\n```\nDispatchRepo is the Repo the CLI layer holds. \\`exec git\\` (CLIRepo) is the only diff backend (ADR-0002 §Update 2026-10-20, second entry). When no \\`git\\` binary is on PATH the repo still opens — commands that never ask for a diff keep working — and every diff method reports ErrNoGitCLI.\n\n```go\nfunc Open(root string, opts DispatchOptions) (*DispatchRepo, error)\n```\nOpen resolves the repository root enclosing root (ErrNotARepo when there is none) and binds the \\`git\\` CLI backend when the binary is available.\n\n```go\nfunc (d *DispatchRepo) Diff(args []string) (Diff, error)\n```\n\n```go\nfunc (d *DispatchRepo) Root() string\n```\n\n```go\nfunc (d *DispatchRepo) StagedDiff() (Diff, error)\n```\n\n```go\nfunc (d *DispatchRepo) UnstagedDiff() (Diff, error)\n```\n\n```go\ntype Origin string\n```\n\n```go\nconst (\n\tOriginStaged   Origin = \"staged\"\n\tOriginUnstaged Origin = \"unstaged\"\n\tOriginCommit   Origin = \"commit\"\n\tOriginDiff     Origin = \"diff\" // `commitbrief diff \u003cargs...\u003e` passthrough\n\t// OriginFiltered marks a diff assembled from an explicitly selected set\n\t// of commits (the --author / --start-date / --end-date / --text filters).\n\t// Unlike every other origin its content is a CONCATENATION of per-commit\n\t// patches, so the same path may appear as several file entries.\n\tOriginFiltered Origin = \"filtered\"\n)\n```\n\n```go\ntype Repo interface {\n\tStagedDiff() (Diff, error)\n\tUnstagedDiff() (Diff, error)\n\t// Diff is the generic `git diff \u003cargs\u003e` passthrough used by the\n\t// `commitbrief diff` subcommand. args are forwarded verbatim\n\t// after `--no-color --no-ext-diff` so the renderer/parser see\n\t// stable unified-diff output. Without a `git` binary on PATH the\n\t// implementation returns ErrNoGitCLI.\n\tDiff(args []string) (Diff, error)\n\tRoot() string\n}\n```\n\n```go\ntype Selection struct {\n\tCommits []CommitMeta // newest first\n\n\t// Walked is how many commits phase A inspected.\n\tWalked int\n\t// Truncated is set when more commits matched than MaxCommits allowed.\n\tTruncated bool\n\t// WalkTruncated is set when the history held more than walkLimit commits,\n\t// meaning the older ones were never inspected at all. Exactly walkLimit\n\t// commits is not truncation.\n\tWalkTruncated bool\n}\n```\nSelection is the outcome of a commit walk: the matching commits plus enough accounting for the caller to report honestly what was and wasn't covered.\n\n```go\nfunc SelectCommits(ctx context.Context, repoRoot string, f CommitFilter) (Selection, error)\n```\nSelectCommits runs phases A and A′ and returns the matching commits, newest first, capped at f.MaxCommits.\n\n","path":"github.com/CommitBrief/commitbrief/internal/git","name":"git","synopsis":"","isRedistributable":true}
