@howells/husky 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/bin/howells-husky.mjs +24 -0
- package/hooks/pre-push +56 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,6 +35,25 @@ Runs `pnpm lint-staged` — formats staged files with the configured Howells for
|
|
|
35
35
|
|
|
36
36
|
Runs `pnpm typecheck` and `pnpm lint`. Both must pass before code reaches the remote.
|
|
37
37
|
|
|
38
|
+
Both run against the **working directory**, so their result only describes what is being pushed when the working directory is what is being pushed. Git names the refs on stdin, so the hook can tell:
|
|
39
|
+
|
|
40
|
+
| What you are pushing | What happens |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| The commit you have checked out | Typecheck and lint run. A failure blocks the push. |
|
|
43
|
+
| A ref that is not `HEAD` | Skipped, and said out loud. The checks would describe a different tree. |
|
|
44
|
+
| A branch deletion | Ignored; nothing is being added to check. |
|
|
45
|
+
| Nothing on stdin | Checked anyway. An unverified push is what this hook exists to stop. |
|
|
46
|
+
|
|
47
|
+
**Why a non-`HEAD` push is skipped rather than failed.** It is neither a pass nor a failure - it is unverifiable, and reporting the wrong tree's result is worse than admitting the hook cannot see. The case this matters for is the rescue path: work that exists in one place, in a tree that does not typecheck, is exactly what most needs pushing. The old behaviour failed that push for a reason unrelated to what was being pushed, leaving `--no-verify` as the only route - which disables every gate at once.
|
|
48
|
+
|
|
49
|
+
### The hooks are immutable, and now they say so
|
|
50
|
+
|
|
51
|
+
`.husky/pre-commit` and `.husky/pre-push` are overwritten from this package on every install. That is deliberate: a repo cannot weaken its own gate to get something to pass.
|
|
52
|
+
|
|
53
|
+
What changed is that it is no longer silent. If an install replaces a hook whose contents differ from the packaged one, it says so and names the file. Before, a customised hook vanished on the next `pnpm install` with nothing printed, so whoever wrote it believed it was in effect until it demonstrably was not.
|
|
54
|
+
|
|
55
|
+
**To change a hook, change it here and publish.** There is no per-repo override, by design.
|
|
56
|
+
|
|
38
57
|
## Requirements
|
|
39
58
|
|
|
40
59
|
Your `package.json` must have:
|
package/bin/howells-husky.mjs
CHANGED
|
@@ -78,11 +78,35 @@ if (!existsSync(huskyDir)) {
|
|
|
78
78
|
const hooks = ["pre-commit", "pre-push"];
|
|
79
79
|
const hooksDir = path.join(packageRoot, "hooks");
|
|
80
80
|
|
|
81
|
+
// The overwrite is deliberate: the hooks are the package's, not the project's,
|
|
82
|
+
// so a weakened gate cannot survive an install. What was missing is that it
|
|
83
|
+
// happened in silence — a customised hook vanished on the next `pnpm install`
|
|
84
|
+
// with nothing said, so the author believed their change was in effect until
|
|
85
|
+
// it demonstrably was not. Replacing is still unconditional; it is now audible.
|
|
81
86
|
for (const hook of hooks) {
|
|
82
87
|
const source = path.join(hooksDir, hook);
|
|
83
88
|
const dest = path.join(huskyDir, hook);
|
|
89
|
+
|
|
90
|
+
let replacedLocalEdit = false;
|
|
91
|
+
if (existsSync(dest)) {
|
|
92
|
+
replacedLocalEdit =
|
|
93
|
+
readFileSync(dest, "utf-8") !== readFileSync(source, "utf-8");
|
|
94
|
+
}
|
|
95
|
+
|
|
84
96
|
copyFileSync(source, dest);
|
|
85
97
|
chmodSync(dest, 0o755);
|
|
98
|
+
|
|
99
|
+
if (replacedLocalEdit) {
|
|
100
|
+
console.warn(
|
|
101
|
+
`[@howells/husky] Replaced .husky/${hook} with the packaged version; your local edits to it are gone.`
|
|
102
|
+
);
|
|
103
|
+
console.warn(
|
|
104
|
+
" These hooks are intentionally immutable, so a repo cannot weaken its own gate."
|
|
105
|
+
);
|
|
106
|
+
console.warn(
|
|
107
|
+
" Change them in @howells/husky and publish, or the next install reverts you again."
|
|
108
|
+
);
|
|
109
|
+
}
|
|
86
110
|
}
|
|
87
111
|
|
|
88
112
|
// Step 3: Validate lint-staged config
|
package/hooks/pre-push
CHANGED
|
@@ -1,2 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
#
|
|
3
|
+
# Pre-push gate: typecheck and lint before anything reaches a remote.
|
|
4
|
+
#
|
|
5
|
+
# Both checks run against the WORKING DIRECTORY, so their result only describes
|
|
6
|
+
# what is being pushed when the working directory *is* what is being pushed.
|
|
7
|
+
#
|
|
8
|
+
# Git says what is actually being pushed on stdin, one line per ref:
|
|
9
|
+
#
|
|
10
|
+
# <local ref> <local sha> <remote ref> <remote sha>
|
|
11
|
+
#
|
|
12
|
+
# When a pushed sha is not HEAD - archiving a salvage ref, pushing a branch that
|
|
13
|
+
# is not checked out - the checks would be measuring a different tree. That is
|
|
14
|
+
# neither a pass nor a failure. It is unverifiable, and it is reported as such
|
|
15
|
+
# rather than folded into either, because a gate that reports the wrong tree's
|
|
16
|
+
# result is worse than one that admits it cannot see.
|
|
17
|
+
#
|
|
18
|
+
# This matters most on the rescue path. Work that exists in one place, in a tree
|
|
19
|
+
# that does not typecheck, is exactly what most needs pushing - and the old
|
|
20
|
+
# behaviour failed that push for a reason unrelated to the thing being pushed,
|
|
21
|
+
# leaving `--no-verify` as the only route and disabling every gate at once.
|
|
22
|
+
|
|
23
|
+
ZERO=0000000000000000000000000000000000000000
|
|
24
|
+
|
|
25
|
+
head_sha=$(git rev-parse HEAD 2>/dev/null)
|
|
26
|
+
unverifiable=""
|
|
27
|
+
saw_ref=0
|
|
28
|
+
|
|
29
|
+
while read -r local_ref local_sha _remote_ref _remote_sha; do
|
|
30
|
+
[ -z "$local_sha" ] && continue
|
|
31
|
+
saw_ref=1
|
|
32
|
+
|
|
33
|
+
# A zero local sha is a branch deletion. Nothing is being added to check.
|
|
34
|
+
[ "$local_sha" = "$ZERO" ] && continue
|
|
35
|
+
|
|
36
|
+
# The common case: pushing the commit that is checked out. The working
|
|
37
|
+
# directory is the right tree and the checks below describe it.
|
|
38
|
+
[ "$local_sha" = "$head_sha" ] && continue
|
|
39
|
+
|
|
40
|
+
unverifiable="$unverifiable $local_ref"
|
|
41
|
+
done
|
|
42
|
+
|
|
43
|
+
if [ -n "$unverifiable" ]; then
|
|
44
|
+
echo "[@howells/husky] Not verified:$unverifiable"
|
|
45
|
+
echo " These refs are not HEAD, so typecheck and lint would describe a"
|
|
46
|
+
echo " different tree than the one being pushed. Skipped rather than"
|
|
47
|
+
echo " reported as passing. Verify on the branch itself, or in CI."
|
|
48
|
+
exit 0
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
# No refs on stdin means git did not tell us what it is pushing. Check anyway:
|
|
52
|
+
# an unverified push is the thing this hook exists to prevent.
|
|
53
|
+
if [ "$saw_ref" = "0" ]; then
|
|
54
|
+
echo "[@howells/husky] No refs on stdin; checking the working directory."
|
|
55
|
+
fi
|
|
56
|
+
|
|
1
57
|
pnpm typecheck || exit 1
|
|
2
58
|
pnpm lint || exit 1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howells/husky",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Standardised git hooks for Howells projects. Immutable pre-commit and pre-push configuration.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint": "howells-check --config=oxlint.config.ts package.json bin hooks README.md oxlint.config.ts oxfmt.config.ts",
|
|
26
26
|
"lint:fix": "howells-fix --config=oxlint.config.ts package.json bin hooks README.md oxlint.config.ts oxfmt.config.ts",
|
|
27
27
|
"format": "howells-oxfmt --write package.json bin hooks README.md oxlint.config.ts oxfmt.config.ts",
|
|
28
|
-
"test": "node --test bin/detect.test.mjs"
|
|
28
|
+
"test": "node --test bin/detect.test.mjs bin/pre-push.test.mjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"husky": "^9.1.7",
|