Skip to main content

Module common

Module common 

Source
Expand description

Shared plumbing for the linter-orchestration hooks.

Nine of them do the same four things: collect staged files of some kind, bail out if there are none, resolve a tool, run it. In shell that was ~65 lines apiece, mostly duplicated; here it is a handful of helpers and each hook keeps only what is actually specific to it.

Enums§

Ran
What became of a command run under the deadline.
Restaged
What a re-stage actually did. THREE answers, because the old bool conflated two of them and the conflation shipped unformatted code.

Functions§

bounded_success
status_within, collapsed to “did it exit 0” — the shape the one-shot tool spawns want. A timeout says so, names what, and reads as failure.
check_timeout
The wall-clock budget for one check’s spawned command, in seconds.
fail
first_existing
The first of names that exists at the repo root — how these hooks decide a repo has opted into a tool.
fixing_enabled
Whether the user asked for checks to repair what they find.
fixing_requested
What the CONFIG says, ignoring whether the current run may act on it.
hl
Orange, for the fragments these hooks highlight.
not_the_index
Whether the file set every check sees is something other than the index.
ok
override_file_set
Make every subsequent staged_files answer from files instead of the index. Only the first call counts.
program
Resolve a tool name to a full path for spawning.
repo_root
Repo root, or “.” when git cannot say.
repo_root_checked
Repo root, or an error naming the problem.
resolve_tool
Resolve a tool, preferring the repo’s PINNED copy so the hook matches CI.
restage
Re-stage exactly the paths a fixer rewrote, and say what happened.
run
Run argv from root, inheriting stdio. True when it exits 0.
run_quiet
As run, but with the tool’s own output discarded.
say
A line with no sign of its own — what a check’s direct println! becomes, so it lands in the check’s block instead of interleaving. See live::say.
say_timed_out
Say a command was killed at the deadline, and how to change the deadline.
staged_files
An empty exts returns them all.
status_streamed
status_within, with the child’s stdout and stderr CAPTURED into the calling check’s slot instead of inherited — the other half of one-check- one-block: a linter’s twelve lines used to land on the shared terminal between two other checks’ lines. Falls back to plain status_within when no slot is installed on this thread (amont.progress false, or a spawn outside a stage), which is byte-for-byte the old behaviour.
status_within
cmd.status(), bounded by check_timeout.
status_within_secs
status_within with an explicit budget — the testable seam.
strip_git_env
Strip git’s own environment before handing a Command to another tool.
warn
which
First match for tool on PATH.