Skip to content

Commit 3b02665

Browse files
author
David Arnold
committed
imp: work around the possibility of different pre-commit versions
1 parent ac0ce1e commit 3b02665

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

modules/pre-commit.nix

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let
5959
The entry point - the executable to run. entry can also contain arguments that will not be overridden such as entry: autopep8 -i.
6060
'';
6161
};
62-
language =
62+
language =
6363
mkOption {
6464
type = types.str;
6565
description =
@@ -331,12 +331,25 @@ in
331331
ln -s ${configFile} .pre-commit-config.yaml
332332
# Remove any previously installed hooks (since pre-commit itself has no convergent design)
333333
hooks="pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-checkout post-commit"
334+
uninstall_help=$(pre-commit uninstall --help)
335+
install_help=$(pre-commit install --help)
334336
for hook in $hooks; do
335-
pre-commit uninstall -t $hook
337+
# different version of pre-commit support different hooks
338+
if [[ "$uninstall_help" =~ "$hook" ]]; then
339+
pre-commit uninstall -t $hook
340+
fi
336341
done
337342
# Add hooks for configured stages (only) ...
338343
if [ ! -z "${concatStringsSep " " cfg.default_stages}" ]; then
339344
for stage in ${concatStringsSep " " cfg.default_stages}; do
345+
if [[ "$stage" == "manual" ]]; then
346+
continue
347+
fi
348+
# different version of pre-commit support different hooks
349+
if [[ ! "$install_help" =~ "$stage" ]];then
350+
echo 1>&2 "WARNING: nix-pre-commit-hooks: '$stage' is not supported by this pre-commit version."
351+
continue
352+
fi
340353
case $stage in
341354
commit | merge-commit | push)
342355
stage="pre-"$stage

0 commit comments

Comments
 (0)