gitfacts

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package gitfacts reads the few facts about a checkout the manager digest's state entry carries (card 162, manager-digest plan §5.3): the commit HEAD names and the branch it is on, read from git's own files with no process started; the commits a session made since it started, which only git itself can list, so `git log` is run — an argument array, the allow-listed child environment, never a shell, a short deadline, and nothing but its stdout read; and whether a path is ignored, which `git check-ignore` answers. Every failure leaves the caller's facts as they were: a checkout without git, a repository with no commit yet and a `.git` nobody can read all answer "nothing known", never an error a hook would print.

Index

Constants

View Source
const (
	// MaxLogCommits caps one `git log`: a session that made more commits
	// since it started keeps the newest ones, which the digest's own cap
	// (40 lines) never exceeds anyway.
	MaxLogCommits = 100

	// MaxSubjectChars caps a commit subject the entry carries, in code
	// points, with protocol.TruncationMarker when cut.
	MaxSubjectChars = 200
)

The bounds of what one git call may hand back.

Variables

View Source
var ErrNoGit = errors.New("gitfacts: no git on PATH")

ErrNoGit is the error of a Runner whose environment's PATH has no git.

Functions

func Head(top string) (hash, branch string)

Head reads what HEAD names in the checkout at top, from git's own files: the commit hash, and the branch when HEAD is symbolic ("" when detached). A repository whose HEAD names a branch with no commit yet answers the branch and no hash; anything unreadable answers nothing at all. No process is started: this runs at every prompt.

func Made added in v0.45.1

func Made(top string, since time.Time) map[string]bool

Made is the commits HEAD's reflog in the checkout shows were made there at or after since (card 172), read from git's own file with no process started: the new side of each entry a commit, an amend, a cherry-pick, a revert, `am`, a rebase step that writes a commit, or a merge that made a merge commit (a `pull` or `merge` entry that is not a fast-forward). A fast-forward, a checkout and a reset only move HEAD to commits made elsewhere. Nil when the reflog cannot be read (git writes none when core.logAllRefUpdates is off): nothing is then known made. Only the newest maxOutputBytes of the file are read; a session that moved HEAD more often than that keeps the newest moves.

Types

type Commit

type Commit struct {
	Hash    string
	Subject string
	Card    int
	At      time.Time
}

A Commit is one commit `git log` listed: the full hash, the subject (sanitised and capped), the card number the subject starts with (the repository's `<card>: <summary>` convention, 0 when it starts with none) and the commit time.

type Runner

type Runner struct {
	Top     string
	Environ []string
	Timeout time.Duration
}

A Runner runs git in one checkout: the toplevel, the environment the child's allow-listed one is built from (the hook's or the command's own, in os.Environ form) and the deadline each call gets. Git is found on that environment's PATH, never on this process's.

func (Runner) AuthorEmail

func (r Runner) AuthorEmail(ctx context.Context) (string, error)

AuthorEmail is `user.email` as git resolves it for the checkout: the value the commits a session makes there carry, so Log can keep to them. "" when none is configured.

func (Runner) Ignored

func (r Runner) Ignored(ctx context.Context, path string) (bool, error)

Ignored reports whether git ignores path in the checkout — the answer `git check-ignore` gives (exit 0 ignored, 1 not), with the path given after `--` so it is never read as an option. When path lies beyond a symbolic link inside the checkout (card 172: a second checkout on one machine links its synced folder to the first one's), git refuses the path itself (`beyond a symbolic link`, exit 128) and would commit only the link, so the link is the path asked about.

func (Runner) Log

func (r Runner) Log(ctx context.Context, since, author string) ([]Commit, error)

Log lists the commits reachable from HEAD and not from since (the `since..HEAD` range), newest first as git lists them, at most MaxLogCommits; with author set, only those whose author line contains it, matched as fixed text. An empty since lists nothing: the entry's start head is what makes a range, and a session with none made no commit Brigade could attribute.

Jump to

Keyboard shortcuts

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