Commit 216a906
committed
fix(hooks): scope trunk protection to the project's own repository
block-push-to-main.sh blocked any push whose destination ref resolved to the
trunk, without first asking which repository the push targets. Trunk protection
exists to route changes to THIS project through a PR, but the guard fired on
pushes to unrelated repositories too, where there is no PR flow to route
through and nothing to protect.
The case that surfaced it: publishing a design doc to a GitLab project wiki. A
wiki lives in a separate `<project>.wiki.git` repository whose default — and
only — branch is `main`. Every wiki update tripped the guard, so wiki pages
could not be pushed at all. The same false positive hits a sibling checkout or
a vendored dependency that happens to sit on its trunk.
Resolve the target repository with the existing resolve_git_command_cwd helper
(it already understands `git -C <path> push` and `cd <path> && git push`), then
compare git-common-dir the way block-commit-outside-worktree.sh already does
and exit 0 when the push lands in a different repository. No new helper: this
reuses what lib.sh exports and mirrors the identity check the sibling guard was
already performing, so the two hooks now agree on what "this repo" means.
Comparing git-common-dir rather than git-dir keeps a linked worktree of this
project counted as this project, so the scoping cannot be used as an escape
hatch. Resolution uncertainty falls back to the inherited cwd, leaving an
unparsable command checked rather than waved through.
Extends tests/unit/test-block-push-regex.sh with 4 cases (2 reproducing the
false positive, 2 pinning the escape-hatch boundary):
TC-BP-12 push another repo's main via `git -C` -> allow
TC-BP-13 push a `<project>.wiki.git` main via `cd &&` -> allow
TC-BP-14 push this repo's main via `git -C <self>` -> still block
TC-BP-15 push this repo's main from a linked worktree -> still block
15/15 pass; the two new allow-cases fail on the unmodified hook (13 pass / 2
fail), and TC-BP-14/15 already passed before the change, confirming the scoping
narrows nothing it should still catch. Bare `git push` was verified separately
across all three shapes — same repo on a feature branch (allow), same repo on
trunk (block), and a different repo sitting on trunk (allow) — since
parse_push_target_refspec reads the current branch and only runs on the
same-repo path. test-block-commit-outside-worktree.sh,
test-install-git-pre-push.sh and test-chp-commit-file.sh still pass (they share
lib.sh); shellcheck -x is clean.1 parent 3610c2b commit 216a906
2 files changed
Lines changed: 106 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
25 | 54 | | |
26 | 55 | | |
27 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
64 | 88 | | |
65 | 89 | | |
66 | 90 | | |
| |||
165 | 189 | | |
166 | 190 | | |
167 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
168 | 245 | | |
169 | 246 | | |
170 | 247 | | |
| |||
0 commit comments