|
2 | 2 | let |
3 | 3 | inherit (lib) |
4 | 4 | boolToString |
| 5 | + concatMapStrings |
5 | 6 | concatStringsSep |
6 | | - compare |
7 | 7 | filterAttrs |
8 | 8 | literalExample |
9 | 9 | mapAttrsToList |
10 | 10 | mkOption |
| 11 | + optionalString |
11 | 12 | types |
12 | 13 | remove |
13 | 14 | ; |
|
66 | 67 | git config --global user.email "you@example.com" |
67 | 68 | git config --global user.name "Your Name" |
68 | 69 | git commit -m "init" -q |
69 | | - if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]] |
70 | | - then |
71 | | - echo "Running: $ pre-commit run --hook-stage manual --all-files" |
72 | | - ${cfg.package}/bin/pre-commit run --hook-stage manual --all-files |
73 | | - else |
74 | | - echo "Running: $ pre-commit run --all-files" |
75 | | - ${cfg.package}/bin/pre-commit run --all-files |
76 | | - fi |
| 70 | + ${ |
| 71 | + let |
| 72 | + cmd = "pre-commit run${optionalString (install_stages == [ "manual" ]) " --hook-stage manual"} --all-files"; |
| 73 | + in |
| 74 | + '' |
| 75 | + echo "Running: $ ${cmd}" |
| 76 | + ${cfg.package}/bin/${cmd} |
| 77 | + '' |
| 78 | + } |
77 | 79 | exitcode=$? |
78 | 80 | git --no-pager diff --color |
79 | 81 | mkdir $out |
|
341 | 343 | elif ! ${git}/bin/git rev-parse --git-dir &> /dev/null; then |
342 | 344 | echo 1>&2 "WARNING: git-hooks.nix: .git not found; skipping installation." |
343 | 345 | else |
344 | | - GIT_WC=`${git}/bin/git rev-parse --show-toplevel` |
| 346 | + GIT_WC=$(${git}/bin/git rev-parse --show-toplevel) |
345 | 347 |
|
346 | 348 | # These update procedures compare before they write, to avoid |
347 | 349 | # filesystem churn. This improves performance with watch tools like lorri |
|
365 | 367 | ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml" |
366 | 368 | fi |
367 | 369 | # Remove any previously installed hooks (since pre-commit itself has no convergent design) |
368 | | - hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}" |
369 | | - for hook in $hooks; do |
370 | | - pre-commit uninstall -t $hook |
371 | | - done |
| 370 | + pre-commit uninstall${concatMapStrings (hook: " --hook-type ${hook}") (remove "manual" supportedHooksLib.supportedHooks)} |
372 | 371 | ${git}/bin/git config --local core.hooksPath "" |
373 | | - # Add hooks for configured stages (only) ... |
374 | | - if [ ! -z "${concatStringsSep " " install_stages}" ]; then |
375 | | - for stage in ${concatStringsSep " " install_stages}; do |
376 | | - case $stage in |
377 | | - manual) |
378 | | - ;; |
379 | | - # if you amend these switches please also review $hooks above |
380 | | - commit | merge-commit | push) |
381 | | - stage="pre-"$stage |
382 | | - pre-commit install -t $stage |
383 | | - ;; |
384 | | - ${concatStringsSep "|" supportedHooksLib.supportedHooks}) |
385 | | - pre-commit install -t $stage |
386 | | - ;; |
387 | | - *) |
388 | | - echo 1>&2 "ERROR: git-hooks.nix: either $stage is not a valid stage or git-hooks.nix doesn't yet support it." |
389 | | - exit 1 |
390 | | - ;; |
391 | | - esac |
392 | | - done |
393 | | - # ... or default 'pre-commit' hook |
394 | | - else |
395 | | - pre-commit install |
396 | | - fi |
| 372 | + # Add hooks for configured stages |
| 373 | + pre-commit install${concatMapStrings (stage: " --hook-type ${if builtins.elem stage [ "commit" "merge-commit" "push" ] then "pre-${stage}" else stage}") (remove "manual" install_stages)} |
397 | 374 |
|
398 | 375 | # Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git. |
399 | 376 | common_dir=''$(${git}/bin/git rev-parse --path-format=absolute --git-common-dir) |
400 | 377 |
|
401 | 378 | # Convert the absolute path to a path relative to the toplevel working directory. |
402 | | - common_dir=''${common_dir#''$GIT_WC/} |
| 379 | + common_dir=''${common_dir#"''$GIT_WC"/} |
403 | 380 |
|
404 | 381 | ${git}/bin/git config --local core.hooksPath "''$common_dir/hooks" |
405 | 382 | fi |
|
0 commit comments