From 837f4694df48df27ae92966329b6a26ef9e902fc Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Fri, 10 Oct 2025 11:22:33 +0200 Subject: [PATCH] hook: Add check for `git2` in `radicle` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend facilities for `rg` based hook generation to also cover includes and excludes, then add a hook that helps catch usage of `git2` in the `radicle` crate, *with the exception of* `…/raw.rs`. At the same time, these hooks are also enabled to run pre-push, as they are very quick, just for convenience of Jujutsu users, because Jujutsu currently does not support Git's commit hooks. --- flake.nix | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 306d71dc..becd8b9a 100644 --- a/flake.nix +++ b/flake.nix @@ -176,25 +176,46 @@ // { pre-commit-check = let grep = rec { - words = ["radicle.xyz" "radicle.zulipchat.com"]; - after = map id words; + generators = [ + { + word = "radicle.xyz"; + files = "\\.rs$"; + excludes = []; + } + { + word = "radicle.zulipchat.com"; + files = "\\.rs$"; + excludes = []; + } + { + word = "git2::"; + files = "^crates/radicle/.*\\.rs$"; + excludes = ["crates/radicle/src/git/raw.rs"]; + } + ]; + after = map id generators; prefix = "grep-"; - id = word: prefix + word; - hooks = builtins.listToAttrs (map (word: { + id = {word, ...}: prefix + word; + hooks = builtins.listToAttrs (map (generator: { # "," is problematic, as this is used to split # lists of hook names, when skipping, see: # https://pre-commit.com/#temporarily-disabling-hooks - name = assert !lib.hasInfix "," word; id word; - value = hook word; + name = assert !lib.hasInfix "," generator.word; id generator; + value = hook generator; }) - words); - hook = word: { + generators); + hook = { + word, + files, + excludes, + }: { + inherit files excludes; enable = true; entry = builtins.toString (pkgs.writeShellScript "grep-${word}" "! ${lib.getExe pkgs.ripgrep} --context=3 --fixed-strings '${word}' $@"); - name = "Avoid '${word}' in Rust code"; - files = "\\.rs$"; + name = "Avoid '${word}' in '${files}'"; + stages = ["pre-commit" "pre-push"]; pass_filenames = true; }; };