hook: Add check for `git2` in `radicle`

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.
This commit is contained in:
Lorenz Leutgeb 2025-10-10 11:22:33 +02:00
parent 880634acd4
commit 837f4694df
No known key found for this signature in database
1 changed files with 31 additions and 10 deletions

View File

@ -176,25 +176,46 @@
// { // {
pre-commit-check = let pre-commit-check = let
grep = rec { grep = rec {
words = ["radicle.xyz" "radicle.zulipchat.com"]; generators = [
after = map id words; {
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-"; prefix = "grep-";
id = word: prefix + word; id = {word, ...}: prefix + word;
hooks = builtins.listToAttrs (map (word: { hooks = builtins.listToAttrs (map (generator: {
# "," is problematic, as this is used to split # "," is problematic, as this is used to split
# lists of hook names, when skipping, see: # lists of hook names, when skipping, see:
# https://pre-commit.com/#temporarily-disabling-hooks # https://pre-commit.com/#temporarily-disabling-hooks
name = assert !lib.hasInfix "," word; id word; name = assert !lib.hasInfix "," generator.word; id generator;
value = hook word; value = hook generator;
}) })
words); generators);
hook = word: { hook = {
word,
files,
excludes,
}: {
inherit files excludes;
enable = true; enable = true;
entry = builtins.toString (pkgs.writeShellScript entry = builtins.toString (pkgs.writeShellScript
"grep-${word}" "grep-${word}"
"! ${lib.getExe pkgs.ripgrep} --context=3 --fixed-strings '${word}' $@"); "! ${lib.getExe pkgs.ripgrep} --context=3 --fixed-strings '${word}' $@");
name = "Avoid '${word}' in Rust code"; name = "Avoid '${word}' in '${files}'";
files = "\\.rs$"; stages = ["pre-commit" "pre-push"];
pass_filenames = true; pass_filenames = true;
}; };
}; };