|
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 hookModule; |
21 | 24 |
|
|
170 | 173 | The predefined hooks are: |
171 | 174 |
|
172 | 175 | ${ |
173 | | - lib.concatStringsSep |
| 176 | + concatStringsSep |
174 | 177 | "\n" |
175 | 178 | (lib.mapAttrsToList |
176 | 179 | (hookName: hookConf: |
|
248 | 251 |
|
249 | 252 | default_stages = |
250 | 253 | mkOption { |
251 | | - type = types.listOf types.str; |
| 254 | + type = supportedHooksLib.supportedHooksType; |
252 | 255 | description = lib.mdDoc |
253 | 256 | '' |
254 | 257 | A configuration wide option for the stages property. |
255 | 258 | Installs hooks to the defined stages. |
256 | 259 | See [https://pre-commit.com/#confining-hooks-to-run-at-certain-stages](https://pre-commit.com/#confining-hooks-to-run-at-certain-stages). |
257 | 260 | ''; |
258 | | - default = [ "commit" ]; |
| 261 | + default = [ "pre-commit" ]; |
259 | 262 | }; |
260 | 263 |
|
261 | 264 | rawConfig = |
|
327 | 330 |
|
328 | 331 | # These update procedures compare before they write, to avoid |
329 | 332 | # filesystem churn. This improves performance with watch tools like lorri |
330 | | - # and prevents installation loops by via lorri. |
| 333 | + # and prevents installation loops by lorri. |
331 | 334 |
|
332 | 335 | if ! readlink "''${GIT_WC}/.pre-commit-config.yaml" >/dev/null \ |
333 | 336 | || [[ $(readlink "''${GIT_WC}/.pre-commit-config.yaml") != ${configFile} ]]; then |
334 | 337 | echo 1>&2 "pre-commit-hooks.nix: updating $PWD repo" |
335 | | -
|
336 | 338 | [ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml |
337 | 339 |
|
338 | 340 | if [ -e "''${GIT_WC}/.pre-commit-config.yaml" ]; then |
|
344 | 346 | else |
345 | 347 | ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml" |
346 | 348 | # Remove any previously installed hooks (since pre-commit itself has no convergent design) |
347 | | - hooks="pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-checkout post-commit" |
| 349 | + hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}" |
348 | 350 | for hook in $hooks; do |
349 | 351 | pre-commit uninstall -t $hook |
350 | 352 | done |
351 | 353 | ${git}/bin/git config --local core.hooksPath "" |
352 | 354 | # Add hooks for configured stages (only) ... |
353 | 355 | if [ ! -z "${concatStringsSep " " install_stages}" ]; then |
354 | 356 | for stage in ${concatStringsSep " " install_stages}; do |
355 | | - if [[ "$stage" == "manual" ]]; then |
356 | | - continue |
357 | | - fi |
358 | 357 | case $stage in |
| 358 | + manual) |
| 359 | + ;; |
359 | 360 | # if you amend these switches please also review $hooks above |
360 | 361 | commit | merge-commit | push) |
361 | 362 | stage="pre-"$stage |
362 | 363 | pre-commit install -t $stage |
363 | 364 | ;; |
364 | | - prepare-commit-msg | commit-msg | post-checkout | post-commit) |
| 365 | + ${concatStringsSep "|" supportedHooksLib.supportedHooks}) |
365 | 366 | pre-commit install -t $stage |
366 | 367 | ;; |
367 | 368 | *) |
|
0 commit comments