|
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 "[email protected]"
|
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
|
|
355 | 357 | elif ! ${cfg.gitPackage}/bin/git rev-parse --git-dir &> /dev/null; then
|
356 | 358 | echo 1>&2 "WARNING: git-hooks.nix: .git not found; skipping installation."
|
357 | 359 | else
|
358 |
| - GIT_WC=`${cfg.gitPackage}/bin/git rev-parse --show-toplevel` |
| 360 | + GIT_WC=$(${cfg.gitPackage}/bin/git rev-parse --show-toplevel) |
359 | 361 |
|
360 | 362 | # These update procedures compare before they write, to avoid
|
361 | 363 | # filesystem churn. This improves performance with watch tools like lorri
|
|
379 | 381 | ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml"
|
380 | 382 | fi
|
381 | 383 | # Remove any previously installed hooks (since pre-commit itself has no convergent design)
|
382 |
| - hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}" |
383 |
| - for hook in $hooks; do |
384 |
| - pre-commit uninstall -t $hook |
385 |
| - done |
| 384 | + pre-commit uninstall${concatMapStrings (hook: " --hook-type ${hook}") (remove "manual" supportedHooksLib.supportedHooks)} |
386 | 385 | ${cfg.gitPackage}/bin/git config --local core.hooksPath ""
|
387 |
| - # Add hooks for configured stages (only) ... |
388 |
| - if [ ! -z "${concatStringsSep " " install_stages}" ]; then |
389 |
| - for stage in ${concatStringsSep " " install_stages}; do |
390 |
| - case $stage in |
391 |
| - manual) |
392 |
| - ;; |
393 |
| - # if you amend these switches please also review $hooks above |
394 |
| - commit | merge-commit | push) |
395 |
| - stage="pre-"$stage |
396 |
| - pre-commit install -t $stage |
397 |
| - ;; |
398 |
| - ${concatStringsSep "|" supportedHooksLib.supportedHooks}) |
399 |
| - pre-commit install -t $stage |
400 |
| - ;; |
401 |
| - *) |
402 |
| - echo 1>&2 "ERROR: git-hooks.nix: either $stage is not a valid stage or git-hooks.nix doesn't yet support it." |
403 |
| - exit 1 |
404 |
| - ;; |
405 |
| - esac |
406 |
| - done |
407 |
| - # ... or default 'pre-commit' hook |
408 |
| - else |
409 |
| - pre-commit install |
410 |
| - fi |
| 386 | + # Add hooks for configured stages |
| 387 | + pre-commit install${concatMapStrings (stage: " --hook-type ${if builtins.elem stage [ "commit" "merge-commit" "push" ] then "pre-${stage}" else stage}") (remove "manual" install_stages)} |
411 | 388 |
|
412 | 389 | # Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git.
|
413 | 390 | common_dir=''$(${cfg.gitPackage}/bin/git rev-parse --path-format=absolute --git-common-dir)
|
414 | 391 |
|
415 | 392 | # Convert the absolute path to a path relative to the toplevel working directory.
|
416 |
| - common_dir=''${common_dir#''$GIT_WC/} |
| 393 | + common_dir=''${common_dir#"''$GIT_WC"/} |
417 | 394 |
|
418 | 395 | ${cfg.gitPackage}/bin/git config --local core.hooksPath "''$common_dir/hooks"
|
419 | 396 | fi
|
|
0 commit comments