hooks

package
v0.17.7 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Hook wiring that is not formwork's. Both sides of #146 need to agree about what counts as a real hook file — Verify reports the hooks core.hooksPath is shadowing, and Install refuses to create it — and two implementations that drift is precisely how a repository loses a hook silently. One set of rules, put here so the second side cites it rather than growing its own copy: what a real hook file is, where git's default hooks directory is, and whether the two paths in question are the same directory.

preexistingHooks is that second side's question, and Install now asks it: Install → preflight → runningHooksRefusal. PreexistingHooksForTest in export_test.go is still the seam that reaches the detector directly, for the reason given at its own site.

The ambient git configuration environment, for both commands in this package (#167 D9). Verify's R7 guard used to live in verify.go and install had no equivalent at all; this file is the shared replacement, and the asymmetry it removes was backwards — the READ command refused while the command that rewrites `.git/config` did not.

Package hooks installs and verifies git hook shims that invoke formwork lanes (spec §8). `formwork hooks install` points git's core.hooksPath at a generated shim directory; `formwork hooks verify` replaces the shell system's "hooks-wired" gate. A lane is wired as a git hook when its name is a git client-hook name (pre-commit, pre-push, pre-merge-commit).

Install and its pre-flight. hooks.go keeps the vocabulary — what a hook is, and what one lane's shim says — and answers no question about the filesystem. This file is the side that touches it: it creates a directory, writes files, and changes git's configuration.

That is the boundary. Everything here can fail for reasons that have nothing to do with the config it was handed — a read-only tree, a directory where a file is expected, a git that will not take a setting — so this is where the error returns live, and hooks.go stays a place where the only way to be wrong is to describe a hook incorrectly.

Install's pre-flight: the states where formwork must refuse to wire hooks at all, rather than take over wiring that is already there (#146 D1/D2/D7).

IT IS A SEPARATE FUNCTION FOR A REASON THAT IS NOT TIDINESS. "A refusal changes nothing" is true HERE and false one function away: install still writes the healthy lanes' shims when another git-hook lane selects no rules, and returns that diagnosis alongside the list of what it wired, because refusing the whole install over a stale lane left developers with no gate at all (install.go argues that ordering at its site). Two `if`s inside Install would have made "changes nothing" read as a property of the command. A function returning a bare error, called before the first write, cannot be mistaken for the loop that returns (wired, err).

Verify and the checks behind it. hooks.go keeps the vocabulary and install.go keeps Install; this file answers one question, and the whole of #146 is that it used to answer a different one.

THE QUESTION IS "WILL GIT RUN FORMWORK'S GATE HERE", NOT "IS THE CONFIG STRING THE ONE INSTALL WRITES". Verify used to read core.hooksPath, compare it to a constant, and read shims under formwork's own root. Git decides by different rules: it resolves core.hooksPath from the repository top level across every config scope, applies its own default, resolves it again per worktree, and then runs whatever executable file it finds by name. Twelve states came apart between those two answers — ten where verify printed "hooks wired" over a gate that could not run, two where it reported a healthy repository unwired.

So the verdict here is FILE-LEVEL, at the directory git names: the shim exists, is a regular file, is executable, and byte-equals what install would write. There is deliberately no path comparison in the decision, which is why an absolute core.hooksPath and one spelled with a trailing slash stop being special cases rather than becoming two more of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expected

func Expected(cfg *config.Config) []string

Expected returns, sorted, the lane names in cfg that map to git hooks.

func Install

func Install(root string, cfg *config.Config, overrideGlobal bool) ([]string, error)

Install writes a shim per git-hook lane into root/.formwork/hooks and points core.hooksPath at it. The shims are machine-independent (see shim) and meant to be committed. Idempotent.

overrideGlobal is `formwork hooks install --override-global`: the operator saying this repository is different from whatever the machine has set. It answers ONE of the pre-flight's refusals, the one about a wiring wider than this repository, and it never makes formwork write outside the repository — what it unlocks is a repo-local core.hooksPath. Wiring the project itself declared is not something it clears; preflight.go argues which is which.

func Verify

func Verify(root string, cfg *config.Config) ([]string, error)

Verify reports every reason git will not run formwork's gate in the repository containing root. An empty result means the wiring is intact.

The error return is not a wiring problem. A git failure means verify could not find out what git will do; reporting "not wired" for a question nobody answered would turn a tool fault into a layout diagnosis, and the exit-code contract puts it at 2 rather than 1 (R6).

R6 HAS TWO STATED EXCEPTIONS, both below and both for a git failure that is not a tool fault: shadowedHookProblems' defaultHooksDir call, which is a diagnostic arm reached only after the verdict has already run, and the HooksPath call for a worktree git has itself reported prunable, where the failure IS the finding. Each is argued at its site. Everywhere else a git failure is an error, and neither exception may be widened to a git call whose answer the verdict depends on.

THE SECOND EXCEPTION IS FOR A FAILURE GIT ITSELF PRODUCED, and it excludes vcs.ErrGitEnv on that ground — an error formwork's environment policy raised before running git at all is not something git diagnosed, and it is argued at the site.

Every other error lands IN the result. Nothing below moves past a failed stat, read or listing without appending a problem first — the loops do `continue`, but only after reporting — because each of those was a state where the check could not be performed at all and the old code read that as nothing to report. The two `fs.ErrNotExist` arms below are not that class: each is a state where there is genuinely nothing to check, and each is argued at its site.

Types

This section is empty.

Jump to

Keyboard shortcuts

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