Skip to content

Commit 795e813

Browse files
author
David Arnold
committed
fix: add intialization according to hook type
1 parent dc6efb8 commit 795e813

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

modules/pre-commit.nix

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,31 @@ in
329329
echo 1>&2 " 3. add .pre-commit-config.yaml to .gitignore"
330330
else
331331
ln -s ${configFile} .pre-commit-config.yaml
332-
pre-commit install
332+
# Remove any previously installed hooks (since pre-commit iteslf has no idempotent design)
333+
hooks="pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-checkout post-commit"
334+
for hook in $hooks; do
335+
pre-commit uninstall -t $hook
336+
done
337+
# Add hooks for configured stages (only) ...
338+
if [ ! -z "${concatStringsSep " " cfg.default_stages}" ]; then
339+
for stage in ${concatStringsSep " " cfg.default_stages}; do
340+
case $stage in
341+
commit | merge-commit | push)
342+
stage="pre-"$stage
343+
pre-commit install -t $stage
344+
;;
345+
prepare-commit-msg | commit-msg | post-checkout | post-commit)
346+
stage="pre-"$stage
347+
pre-commit install -t $stage
348+
;;
349+
*)
350+
;;
351+
esac
352+
done
353+
# ... or default 'pre-commit' hook
354+
else
355+
pre-commit install
356+
fi
333357
fi
334358
fi
335359
fi

0 commit comments

Comments
 (0)