Skip to content

Commit 9b35472

Browse files
bougymanclaude
andauthored
feat: add mix githooks.install to activate the repo's git hooks (#51)
## Summary Closes #50. `githooks/commit-msg` exists and correctly calls `ci/validate_conventional_commit.sh`, but `core.hooksPath` was never actually configured on any local clone - the hook never fired, which is how `fix!(docs)`/`docs!(licence)` (wrong `!` position) got committed without ever being caught before push. Adds `mix githooks.install` (`git config core.hooksPath githooks`) and mentions it in the Readme's Development section so it's actually discoverable. Related: `main` now also requires the `Test` and `Validate Commit Subjects` checks to pass before merge, with no admin override - so even if the local hook is skipped, CI backstops it. ## Test plan - [x] `mix test` - 182 passed - [x] `mix format --check-formatted` - clean - [x] Ran `mix githooks.install` for real, then fed a malformed subject (`fix!(docs): ...`) through the now-active `githooks/commit-msg` hook directly - correctly rejected - [x] `asciidoctor -o /dev/null Readme.adoc` renders clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 567b508 commit 9b35472

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

Readme.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ $ lproj list --mine
265265

266266
== Development
267267

268+
First, activate the repo's git hooks (enforces conventional-commit subjects
269+
before you even push):
270+
271+
[source,sh]
272+
----
273+
$ cd app
274+
$ mise exec -- mix githooks.install
275+
----
276+
268277
The project uses ExUnit and `mix format`. Run tests with:
269278

270279
[source,sh]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule Mix.Tasks.Githooks.Install do
2+
@moduledoc "Activates this repo's githooks/ (conventional-commit enforcement on commit-msg)."
3+
@shortdoc "Activates the repo's git hooks"
4+
5+
use Mix.Task
6+
7+
@impl Mix.Task
8+
def run(_args) do
9+
with {root, 0} <- System.cmd("git", ["rev-parse", "--show-toplevel"], stderr_to_stdout: true),
10+
root = String.trim(root),
11+
{_output, 0} <-
12+
System.cmd("git", ["config", "core.hooksPath", "githooks"],
13+
cd: root,
14+
stderr_to_stdout: true
15+
) do
16+
Mix.shell().info("githooks activated (core.hooksPath = githooks)")
17+
else
18+
{output, _status} -> Mix.raise("Failed to activate githooks: #{String.trim(output)}")
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)