Skip to main content

Module git

Module git 

Source
Expand description

Best-effort git-tracking integration.

git_tracked_only rules opt in to filtering matches against the repo’s tracked-paths set — i.e. the output of git ls-files. That set is computed once per Engine::run when at least one rule wants it and stashed on the rule Context.

The set is advisory: alint never refuses to run because a git invocation failed. If the directory isn’t a git repo, or git isn’t on PATH, or the repo is empty, the set is None and rules that consult it treat every walked entry as “untracked.” Rules opting into git_tracked_only therefore become silent no-ops in non-git settings — which is the right default for “absence-style” rules whose intent is “don’t let this be committed.”

Structs§

BlameCache
Per-run cache of git blame output, shared across rules so multiple git_blame_age rules over overlapping paths: re-use the parsed result instead of re-shelling-out.
BlameLine
One line of git blame --line-porcelain output: the 1-indexed final line number in the working-tree file, the authoring time of the commit that last touched the line (per .git-blame-ignore-revs, when present), and the line content with its trailing newline stripped.
CommitRecord
One commit in a <since>..HEAD range, as returned by commit_messages_in_range. sha is the abbreviated SHA from git log --abbrev-commit (typically 7 chars; git auto-extends if the prefix is ambiguous in the local repo). message is the full commit message (subject + body, separated by a blank line) with the trailing newline that git log --format=%B appends already trimmed.

Enums§

CommitRangeError
Errors that distinguish “git is here but the range is invalid” from “git isn’t here at all.” The rule layer uses this to hard- fail on misconfiguration (a bad since: ref, often a shallow- clone gotcha in CI) while silently no-op’ing in non-git directories.

Functions§

blame_lines
Run git blame --line-porcelain for rel_path (relative to root) and return one BlameLine per source line.
collect_changed_paths
Resolve the set of paths that have changed in the working tree (and optionally relative to a base ref), expressed as paths relative to root.
collect_tracked_paths
Resolve the repo’s tracked-paths set, relative to root.
commit_messages_in_range
Enumerate commits reachable from HEAD but not from since, i.e. the standard <since>..HEAD range, oldest first.
dir_has_tracked_files
Test whether dir_rel (a relative-to-root directory path) “exists in git” — defined as: at least one tracked file lives underneath it. Used by dir_exists / dir_absent when git_tracked_only: true is set.
head_commit_message
HEAD’s commit message, as a single string with newlines preserved between subject and body. The subject is the first line; everything after the first blank line is the body.