From 7bc461b162c5446e4eefffcbb0edf80de5ed28f8 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 14 Jul 2025 19:40:14 -0700 Subject: [PATCH] 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 --- snix/shell.nix | 19 +++++++++++++++++++ web/content/docs/guides/contributing.md | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/snix/shell.nix b/snix/shell.nix index fa18d012e..3586d0d93 100644 --- a/snix/shell.nix +++ b/snix/shell.nix @@ -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 ''; } diff --git a/web/content/docs/guides/contributing.md b/web/content/docs/guides/contributing.md index 51dd6b88a..8c7825541 100644 --- a/web/content/docs/guides/contributing.md +++ b/web/content/docs/guides/contributing.md @@ -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]. +
+ +Manually installing the hook + 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 ``` +
+ {{< callout context="tip" title="Did you know?" icon="outline/rocket" >}} Gerrit refuses receiving commits without these `Change-Id: …` fields.