|
362 | 362 | display a warning message when a renamed option is used. |
363 | 363 | ''; |
364 | 364 | }; |
| 365 | + |
| 366 | + configFile = lib.mkOption { |
| 367 | + type = types.str; |
| 368 | + default = ".pre-commit-config.yaml"; |
| 369 | + description = ''The name of the config file.''; |
| 370 | + }; |
365 | 371 | }; |
366 | 372 |
|
367 | 373 | config = |
|
397 | 403 | # filesystem churn. This improves performance with watch tools like lorri |
398 | 404 | # and prevents installation loops by lorri. |
399 | 405 |
|
400 | | - if ! readlink "''${GIT_WC}/.pre-commit-config.yaml" >/dev/null \ |
401 | | - || [[ $(readlink "''${GIT_WC}/.pre-commit-config.yaml") != ${configFile} ]]; then |
| 406 | + if ! readlink "''${GIT_WC}/${cfg.configFile}" >/dev/null \ |
| 407 | + || [[ $(readlink "''${GIT_WC}/${cfg.configFile}") != ${configFile} ]]; then |
402 | 408 | echo 1>&2 "git-hooks.nix: updating $PWD repo" |
403 | | - [ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml |
| 409 | + [ -L ${cfg.configFile} ] && unlink ${cfg.configFile} |
404 | 410 |
|
405 | | - if [ -e "''${GIT_WC}/.pre-commit-config.yaml" ]; then |
406 | | - echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing .pre-commit-config.yaml" |
407 | | - echo 1>&2 " 1. Translate .pre-commit-config.yaml contents to the new syntax in your Nix file" |
| 411 | + if [ -e "''${GIT_WC}/${cfg.configFile}" ]; then |
| 412 | + echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing ${cfg.configFile}" |
| 413 | + echo 1>&2 " 1. Translate ${cfg.configFile} contents to the new syntax in your Nix file" |
408 | 414 | echo 1>&2 " see https://github.com/cachix/git-hooks.nix#getting-started" |
409 | | - echo 1>&2 " 2. remove .pre-commit-config.yaml" |
410 | | - echo 1>&2 " 3. add .pre-commit-config.yaml to .gitignore" |
| 415 | + echo 1>&2 " 2. remove ${cfg.configFile}" |
| 416 | + echo 1>&2 " 3. add ${cfg.configFile} to .gitignore" |
411 | 417 | else |
412 | 418 | if ${boolToString cfg.addGcRoot}; then |
413 | | - nix-store --add-root "''${GIT_WC}/.pre-commit-config.yaml" --indirect --realise ${configFile} |
| 419 | + nix-store --add-root "''${GIT_WC}/${cfg.configFile}" --indirect --realise ${configFile} |
414 | 420 | else |
415 | | - ln -fs ${configFile} "''${GIT_WC}/.pre-commit-config.yaml" |
| 421 | + ln -fs ${configFile} "''${GIT_WC}/${cfg.configFile}" |
416 | 422 | fi |
417 | 423 | # Remove any previously installed hooks (since pre-commit itself has no convergent design) |
418 | 424 | hooks="${concatStringsSep " " (remove "manual" supportedHooksLib.supportedHooks )}" |
|
429 | 435 | # if you amend these switches please also review $hooks above |
430 | 436 | commit | merge-commit | push) |
431 | 437 | stage="pre-"$stage |
432 | | - pre-commit install -t $stage |
| 438 | + pre-commit install -c ${cfg.configFile} -t $stage |
433 | 439 | ;; |
434 | 440 | ${concatStringsSep "|" supportedHooksLib.supportedHooks}) |
435 | | - pre-commit install -t $stage |
| 441 | + pre-commit install -c ${cfg.configFile} -t $stage |
436 | 442 | ;; |
437 | 443 | *) |
438 | 444 | echo 1>&2 "ERROR: git-hooks.nix: either $stage is not a valid stage or git-hooks.nix doesn't yet support it." |
|
442 | 448 | done |
443 | 449 | # ... or default 'pre-commit' hook |
444 | 450 | else |
445 | | - pre-commit install |
| 451 | + pre-commit install -c ${cfg.configFile} |
446 | 452 | fi |
447 | 453 |
|
448 | 454 | # Fetch the absolute path to the git common directory. This will normally point to $GIT_WC/.git. |
|
0 commit comments