Skip to content

Commit 3fa3a17

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

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/pre-commit.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,20 @@ 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+
[[ "$uninstall_help" =~ "$hook" ]] && pre-commit uninstall -t $hook
336339
done
337340
# Add hooks for configured stages (only) ...
338341
if [ ! -z "${concatStringsSep " " cfg.default_stages}" ]; then
339342
for stage in ${concatStringsSep " " cfg.default_stages}; do
343+
[[ "$stage" == "manual" ]] && continue
344+
# different version of pre-commit support different hooks
345+
if [[ ! "$install_help" =~ "$stage" ]];then
346+
echo 1>&2 "WARNING: nix-pre-commit-hooks: '$stage' is not supported by this pre-commit version."
347+
continue
340348
case $stage in
341349
commit | merge-commit | push)
342350
stage="pre-"$stage

0 commit comments

Comments
 (0)