feat(snix/shell.nix): automatically set up the commit-msg hook

Lix does this and it has eliminated anyone ever having to think about
it; it just works.

Change-Id: I24a35d2d0b31f1245172d332bac40fe0b39dc2b9
Reviewed-on: https://cl.snix.dev/c/snix/+/30604
Tested-by: besadii
Reviewed-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
Jade Lovelace 2025-07-14 19:40:14 -07:00
parent be68d89901
commit 7bc461b162
2 changed files with 29 additions and 0 deletions

View file

@ -53,5 +53,24 @@ pkgs.mkShell {
shellHook = ''
export SNIX_BUILD_SANDBOX_SHELL=${if pkgs.stdenv.isLinux then pkgs.busybox-sandbox-shell + "/bin/busybox" else "/bin/sh"}
export SNIX_BENCH_NIX_PATH=nixpkgs=${pkgs.path}
snixShellHook() {
# Somewhat brute force check. Lix uses .this-is-lix in repo root.
if [[ ! -d ./snix || ! -e ./.git ]]; then
echo "Dev shell not started from within the Snix repo, skipping repo setup" >&2
return
fi
local gitcommondir
# Install the Gerrit commit-msg hook.
# (git common dir is the main .git, including for worktrees)
if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then
echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2
mkdir -p "$gitcommondir/hooks"
curl -s -Lo "$gitcommondir/hooks/commit-msg" https://cl.snix.dev/tools/hooks/commit-msg
chmod u+x "$gitcommondir/hooks/commit-msg"
fi
}
snixShellHook
'';
}

View file

@ -56,10 +56,18 @@ git remote set-url origin "https://$USER@cl.snix.dev/a/snix"
replicates fast enough, then update to --push only -->
### Install the commit-msg hook
Setting up the `commit-msg` Git hook is done for you automagically the first time you enter the shell.
If it didn't work for you for some reason, see the manual steps below.
Gerrit uses a `commit-msg` hook to add a `Change-Id: …` field to each commit
message if not present already. This allows Gerrit to identify new revisions /
updates of old commits, and track them as new revisions of the same "CL" [^2].
<details>
<summary>Manually installing the hook</summary>
To install the commit-msg hook, run the following from the repo root:
```bash
@ -68,6 +76,8 @@ curl -Lo .git/hooks/commit-msg https://cl.snix.dev/tools/hooks/commit-msg
chmod +x .git/hooks/commit-msg
```
</details>
{{< callout context="tip" title="Did you know?" icon="outline/rocket" >}}
Gerrit refuses receiving commits without these `Change-Id: …` fields.