Documentation
¶
Overview ¶
Package hooks works with lefthook: reading what a run of it printed, reading its configuration, and writing a configuration for a repository whose hooks predate it.
Index ¶
- Constants
- Variables
- func DumpCommand(dir string) proc.Command
- func HasConfig(repo fs.FS) bool
- func InstallCommand(dir string) proc.Command
- func RunCommand(dir, hook string) proc.Command
- func Write(dir string, generated Generated) error
- type Configured
- type FailureScan
- type File
- type Generated
- type GitHook
- type GitOnly
- type Job
- type JobState
- type Location
Constants ¶
const MaxPlaces = 1000
MaxPlaces is the most places a FailureScan keeps. A run folds every line of its output into the scan as the line arrives, so an output naming ever more places would otherwise grow the scan, and the work of keeping each place once, without limit. Past it the scan keeps the first places, which are usually the causes of the rest.
Variables ¶
var ErrUnreadableConfiguration = errors.New("lefthook's configuration could not be read")
ErrUnreadableConfiguration reports a dump of lefthook's configuration that is not one.
Functions ¶
func DumpCommand ¶ added in v0.10.0
DumpCommand prints lefthook's configuration as JSON, merged as a run of it reads it: the repository's file, its local override, and the remotes it names, from lefthook's own cache.
lefthook logs on the standard output it dumps to, so a LEFTHOOK_VERBOSE this process inherited would put its debug lines ahead of the JSON. The command turns it off; a duplicated variable takes its last value.
func HasConfig ¶
HasConfig reports whether a repository already configures lefthook. A local override alone does not count: it amends a configuration rather than being one.
func InstallCommand ¶ added in v0.10.0
InstallCommand installs lefthook's hooks in a repository: its root, not wherever the process happens to be.
func RunCommand ¶
RunCommand runs one hook through lefthook, as git would, without committing.
func Write ¶
Write creates the configuration and its scripts in a repository. It never replaces anything: not a lefthook configuration under any name lefthook reads, and not an existing script.
Everything is created through the repository opened as a root, which no path can leave: the repository's own tree decides what .lefthook is, and a clone can make it a link to anywhere at all.
Types ¶
type Configured ¶ added in v0.10.0
type Configured struct {
// Runnable is the hooks a run by hand can stand in for: git's own in the
// order git documents them, then the configuration's own names, sorted.
Runnable []string
// GitOnly is the hooks only git can run, in git's order.
GitOnly []GitOnly
}
Configured is the hooks lefthook's merged configuration defines, split by whether a run by hand can stand in for git's.
func ReadConfigured ¶ added in v0.10.0
func ReadConfigured( ctx context.Context, dir string, run func(context.Context, proc.Command) ([]byte, error), ) (Configured, error)
ReadConfigured reads the hooks lefthook's configuration in dir defines, asking lefthook through run for the configuration merged as a run of it reads it: whichever file lefthook finds, its local override even alone, or the file LEFTHOOK_CONFIG names. lefthook alone knows every place it looks, so it is always asked. It refuses to dump where it finds no configuration, and that refusal, from a directory holding no file lefthook reads, is no hook at all rather than a failure.
type FailureScan ¶ added in v0.4.0
type FailureScan struct {
// contains filtered or unexported fields
}
FailureScan reads where a hook's tools pointed one output line at a time, as NextJob reads its jobs, so a run can keep the places as its output streams in: by the time a long run ends, its first lines are gone. Start one with NewFailureScan.
func NewFailureScan ¶ added in v0.4.0
func NewFailureScan(goos string) FailureScan
NewFailureScan starts reading a hook's output. goos is the running platform, which decides whether a Windows drive letter is read as part of a path.
func (FailureScan) Next ¶ added in v0.4.0
func (s FailureScan) Next(raw string) FailureScan
Next folds one more output line in. It does not modify the scan it is given.
The ESLint file is carried only while its rows follow it: a header opens a block when the next line is one of its rows, and any line that is neither a row nor a new header ends the block — so a blank line, or a later tool's output, is never read against a stale filename.
func (FailureScan) Places ¶ added in v0.4.0
func (s FailureScan) Places() []Location
Places is every place found so far, once each, in the order they appeared. A held line that nothing followed is read as any other line is.
type Generated ¶
Generated is a lefthook configuration and the scripts it runs.
func Structured ¶
Structured writes a configuration that runs each hook of plain commands as lefthook jobs, and keeps any other hook as a script. Only a hook whose every line is a command lefthook can run on its own is converted: one that reads its arguments, branches, or sets variables is kept whole rather than guessed at.
type GitHook ¶
GitHook is a hook script found in the hooks directory.
func ExistingHooks ¶
ExistingHooks finds the hooks git would run from a hooks directory, in git's order: files named for a hook, runnable as one, that are not lefthook's own shim. Whether a file is runnable is decided by goos, since Windows has no executable bit to check.
type GitOnly ¶ added in v0.10.0
GitOnly is a hook only git can run, and why: what git hands it that a run by hand would not.
type Job ¶
type Job struct {
Name string
State JobState
// Duration is lefthook's own words for how long it took, once reported.
Duration string
}
Job is one job in a hook run.
func NextJob ¶ added in v0.0.6
NextJob folds one more output line into the jobs seen so far, returning the updated jobs and whether the summary has begun: a job is running from its header until the summary reports it. It does not modify the jobs it is given, so a caller streaming output can keep the running set on its own value and never re-read the whole output — a chatty hook would otherwise cost a full re-parse on every line, and again on every redraw.