|
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 | ;
|
|
62 | 63 | nativeBuildInputs = enabledExtraPackages
|
63 | 64 | ++ lib.optional (config.settings.rust.check.cargoDeps != null) cargoSetupHook;
|
64 | 65 | cargoDeps = config.settings.rust.check.cargoDeps;
|
65 |
| - buildPhase = '' |
66 |
| - set +e |
67 |
| - HOME=$PWD |
68 |
| - ln -fs ${configFile} .pre-commit-config.yaml |
69 |
| - git init -q |
70 |
| - git add . |
71 |
| - git config --global user.email "[email protected]" |
72 |
| - git config --global user.name "Your Name" |
73 |
| - git commit -m "init" -q |
74 |
| - if [[ ${toString (compare install_stages [ "manual" ])} -eq 0 ]] |
75 |
| - then |
76 |
| - echo "Running: $ pre-commit run --hook-stage manual --all-files" |
77 |
| - ${cfg.package}/bin/pre-commit run --hook-stage manual --all-files |
78 |
| - else |
79 |
| - echo "Running: $ pre-commit run --all-files" |
80 |
| - ${cfg.package}/bin/pre-commit run --all-files |
81 |
| - fi |
82 |
| - exitcode=$? |
83 |
| - git --no-pager diff --color |
84 |
| - mkdir $out |
85 |
| - [ $? -eq 0 ] && exit $exitcode |
86 |
| - ''; |
| 66 | + buildPhase = |
| 67 | + let |
| 68 | + cmd = "pre-commit run${optionalString (install_stages == [ "manual" ]) " --hook-stage manual"} --all-files"; |
| 69 | + in |
| 70 | + '' |
| 71 | + set +e |
| 72 | + HOME=$PWD |
| 73 | + ln -fs ${configFile} .pre-commit-config.yaml |
| 74 | + git init -q |
| 75 | + git add . |
| 76 | + git config --global user.email "[email protected]" |
| 77 | + git config --global user.name "Your Name" |
| 78 | + git commit -m "init" -q |
| 79 | + echo "Running: $ ${cmd}" |
| 80 | + ${cfg.package}/bin/${cmd} |
| 81 | + exitcode=$? |
| 82 | + git --no-pager diff --color |
| 83 | + mkdir $out |
| 84 | + [ $? -eq 0 ] && exit $exitcode |
| 85 | + ''; |
87 | 86 | };
|
88 | 87 |
|
89 | 88 | failedAssertions = builtins.map (x: x.message) (builtins.filter (x: !x.assertion) config.assertions);
|
|
361 | 360 | elif ! ${cfg.gitPackage}/bin/git rev-parse --git-dir &> /dev/null; then
|
362 | 361 | echo 1>&2 "WARNING: git-hooks.nix: .git not found; skipping installation."
|
363 | 362 | else
|
364 |
| - GIT_WC=`${cfg.gitPackage}/bin/git rev-parse --show-toplevel` |
| 363 | + GIT_WC=$(${cfg.gitPackage}/bin/git rev-parse --show-toplevel) |
365 | 364 |
|
366 | 365 | # These update procedures compare before they write, to avoid
|
367 | 366 | # filesystem churn. This improves performance with watch tools like lorri
|
|
385 | 384 | ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml"
|
386 | 385 | fi
|
387 | 386 | # Remove any previously installed hooks (since pre-commit itself has no convergent design)
|
388 |
| - hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}" |
389 |
| - for hook in $hooks; do |
390 |
| - pre-commit uninstall -t $hook |
391 |
| - done |
| 387 | + pre-commit uninstall${concatMapStrings (hook: " --hook-type ${hook}") (remove "manual" supportedHooksLib.supportedHooks)} |
392 | 388 | ${cfg.gitPackage}/bin/git config --local core.hooksPath ""
|
393 |
| - # Add hooks for configured stages (only) ... |
394 |
| - if [ ! -z "${concatStringsSep " " install_stages}" ]; then |
395 |
| - for stage in ${concatStringsSep " " install_stages}; do |
396 |
| - case $stage in |
397 |
| - manual) |
398 |
| - ;; |
399 |
| - # if you amend these switches please also review $hooks above |
400 |
| - commit | merge-commit | push) |
401 |
| - stage="pre-"$stage |
402 |
| - pre-commit install -t $stage |
403 |
| - ;; |
404 |
| - ${concatStringsSep "|" supportedHooksLib.supportedHooks}) |
405 |
| - pre-commit install -t $stage |
406 |
| - ;; |
407 |
| - *) |
408 |
| - echo 1>&2 "ERROR: git-hooks.nix: either $stage is not a valid stage or git-hooks.nix doesn't yet support it." |
409 |
| - exit 1 |
410 |
| - ;; |
411 |
| - esac |
412 |
| - done |
413 |
| - # ... or default 'pre-commit' hook |
414 |
| - else |
415 |
| - pre-commit install |
416 |
| - fi |
| 389 | + # Add hooks for configured stages |
| 390 | + pre-commit install${concatMapStrings (stage: " --hook-type ${if builtins.elem stage [ "commit" "merge-commit" "push" ] then "pre-${stage}" else stage}") (remove "manual" install_stages)} |
417 | 391 |
|
418 | 392 | # Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git.
|
419 | 393 | common_dir=''$(${cfg.gitPackage}/bin/git rev-parse --path-format=absolute --git-common-dir)
|
420 | 394 |
|
421 | 395 | # Convert the absolute path to a path relative to the toplevel working directory.
|
422 |
| - common_dir=''${common_dir#''$GIT_WC/} |
| 396 | + common_dir=''${common_dir#"''$GIT_WC"/} |
423 | 397 |
|
424 | 398 | ${cfg.gitPackage}/bin/git config --local core.hooksPath "''$common_dir/hooks"
|
425 | 399 | fi
|
|
0 commit comments