Skip to content

Commit 1149d5f

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

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

modules/pre-commit.nix

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,27 @@ 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
338+
if [ -z "${lib.concatMapStringSep " " cfg.default_stages}" ]; then
339+
for stage in ${lib.concatMapStringSep " " cfg.default_stages}; do
340+
case $stage in
341+
commit | merge-commit | push)
342+
stage="pre-"$stage
343+
;;
344+
*)
345+
;;
346+
esac
347+
pre-commit install -t $stage
348+
done
349+
# or simply 'pre-commit' hook
350+
else
351+
pre-commit install
352+
fi
333353
fi
334354
fi
335355
fi

0 commit comments

Comments
 (0)