Skip to content

Commit f0ee09d

Browse files
committed
Add an option to overwrite any existing config
1 parent 1293270 commit f0ee09d

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

modules/pre-commit.nix

+23-7
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,18 @@ in
290290
'';
291291
};
292292

293+
overwriteConfig =
294+
mkOption {
295+
type = types.bool;
296+
default = false;
297+
description =
298+
''
299+
Whether to overwrite any existing config at `configPath`.
300+
301+
When enabled, any existing config will be overwritten without prompting.
302+
'';
303+
};
304+
293305
src =
294306
lib.mkOption {
295307
description = ''
@@ -397,7 +409,6 @@ in
397409

398410
config =
399411
{
400-
401412
rawConfig =
402413
{
403414
repos =
@@ -430,12 +441,17 @@ in
430441
echo 1>&2 "git-hooks.nix: updating $PWD repo"
431442
[ -L ${cfg.configPath} ] && unlink ${cfg.configPath}
432443
433-
if [ -e "''${GIT_WC}/${cfg.configPath}" ]; then
434-
echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of pre-existing ${cfg.configPath}"
435-
echo 1>&2 " 1. Translate ${cfg.configPath} contents to the new syntax in your Nix file"
436-
echo 1>&2 " see https://github.com/cachix/git-hooks.nix#getting-started"
437-
echo 1>&2 " 2. remove ${cfg.configPath}"
438-
echo 1>&2 " 3. add ${cfg.configPath} to .gitignore"
444+
if [ -e "''${GIT_WC}/${cfg.configPath}" && ! ${boolToString cfg.overwriteConfig} ]; then
445+
echo 1>&2 "git-hooks.nix: WARNING: Refusing to install because of an existing config at ${cfg.configPath}"
446+
echo 1>&2 ""
447+
echo 1>&2 " To migrate the existing config to a Nix configuration:"
448+
echo 1>&2 " 1. Translate the contents of ${cfg.configPath} into a Nix configuration."
449+
echo 1>&2 " See https://github.com/cachix/git-hooks.nix#getting-started"
450+
echo 1>&2 " 2. Remove ${cfg.configPath}"
451+
echo 1>&2 " 3. Add ${cfg.configPath} to .gitignore"
452+
echo 1>&2 ""
453+
echo 1>&2 " To always overwrite the existing config, enable `overwriteConfig` in Nix."
454+
439455
else
440456
if ${boolToString cfg.addGcRoot}; then
441457
nix-store --add-root "''${GIT_WC}/${cfg.configPath}" --indirect --realise ${cfg.configFile}

0 commit comments

Comments
 (0)