|
10 | 10 | mkIf |
11 | 11 | mkOption |
12 | 12 | types |
| 13 | + remove |
13 | 14 | ; |
14 | 15 |
|
15 | 16 | inherit (pkgs) runCommand writeText git; |
16 | 17 |
|
17 | 18 | cfg = config; |
18 | | - install_stages = lib.unique (cfg.default_stages ++ (builtins.concatLists (lib.mapAttrsToList (_: h: h.stages) enabledHooks))); |
| 19 | + install_stages = lib.unique (builtins.concatLists (lib.mapAttrsToList (_: h: h.stages) enabledHooks)); |
| 20 | + |
| 21 | + supportedHooksLib = import ./supported-hooks.nix { inherit lib; }; |
19 | 22 |
|
20 | 23 | hookType = types.submodule { |
21 | 24 | imports = [ |
|
175 | 178 | The predefined hooks are: |
176 | 179 |
|
177 | 180 | ${ |
178 | | - lib.concatStringsSep |
| 181 | + concatStringsSep |
179 | 182 | "\n" |
180 | 183 | (lib.mapAttrsToList |
181 | 184 | (hookName: hookConf: |
|
253 | 256 |
|
254 | 257 | default_stages = |
255 | 258 | mkOption { |
256 | | - type = types.listOf types.str; |
| 259 | + type = supportedHooksLib.supportedHooksType; |
257 | 260 | description = lib.mdDoc |
258 | 261 | '' |
259 | 262 | A configuration wide option for the stages property. |
260 | 263 | Installs hooks to the defined stages. |
261 | 264 | See [https://pre-commit.com/#confining-hooks-to-run-at-certain-stages](https://pre-commit.com/#confining-hooks-to-run-at-certain-stages). |
262 | 265 | ''; |
263 | | - default = [ "commit" ]; |
| 266 | + default = [ "pre-commit" ]; |
264 | 267 | }; |
265 | 268 |
|
266 | 269 | rawConfig = |
|
332 | 335 |
|
333 | 336 | # These update procedures compare before they write, to avoid |
334 | 337 | # filesystem churn. This improves performance with watch tools like lorri |
335 | | - # and prevents installation loops by via lorri. |
| 338 | + # and prevents installation loops by lorri. |
336 | 339 |
|
337 | 340 | if ! readlink "''${GIT_WC}/.pre-commit-config.yaml" >/dev/null \ |
338 | 341 | || [[ $(readlink "''${GIT_WC}/.pre-commit-config.yaml") != ${configFile} ]]; then |
339 | 342 | echo 1>&2 "pre-commit-hooks.nix: updating $PWD repo" |
340 | | -
|
341 | 343 | [ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml |
342 | 344 |
|
343 | 345 | if [ -e "''${GIT_WC}/.pre-commit-config.yaml" ]; then |
|
349 | 351 | else |
350 | 352 | ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml" |
351 | 353 | # Remove any previously installed hooks (since pre-commit itself has no convergent design) |
352 | | - hooks="pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-checkout post-commit" |
| 354 | + hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}" |
353 | 355 | for hook in $hooks; do |
354 | 356 | pre-commit uninstall -t $hook |
355 | 357 | done |
356 | 358 | ${git}/bin/git config --local core.hooksPath "" |
357 | 359 | # Add hooks for configured stages (only) ... |
358 | 360 | if [ ! -z "${concatStringsSep " " install_stages}" ]; then |
359 | 361 | for stage in ${concatStringsSep " " install_stages}; do |
360 | | - if [[ "$stage" == "manual" ]]; then |
361 | | - continue |
362 | | - fi |
363 | 362 | case $stage in |
| 363 | + manual) |
| 364 | + ;; |
364 | 365 | # if you amend these switches please also review $hooks above |
365 | 366 | commit | merge-commit | push) |
366 | 367 | stage="pre-"$stage |
367 | 368 | pre-commit install -t $stage |
368 | 369 | ;; |
369 | | - prepare-commit-msg | commit-msg | post-checkout | post-commit) |
| 370 | + ${concatStringsSep "|" supportedHooksLib.supportedHooks}) |
370 | 371 | pre-commit install -t $stage |
371 | 372 | ;; |
372 | 373 | *) |
|
0 commit comments