mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 07:04:17 +00:00
git: add config helper for hooks
This commit is contained in:
parent
2e41a1bab3
commit
340ec22f6f
4 changed files with 53 additions and 0 deletions
|
@ -201,6 +201,21 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
hooks = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
pre-commit = ./pre-commit-script;
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Configuration helper for Git hooks.
|
||||
See <link xlink:href="https://git-scm.com/docs/githooks" />
|
||||
for reference.
|
||||
'';
|
||||
};
|
||||
|
||||
iniContent = mkOption {
|
||||
type = gitIniType;
|
||||
internal = true;
|
||||
|
@ -449,6 +464,15 @@ in {
|
|||
};
|
||||
})
|
||||
|
||||
(mkIf (cfg.hooks != { }) {
|
||||
programs.git.iniContent = {
|
||||
core.hooksPath = let
|
||||
entries =
|
||||
mapAttrsToList (name: path: { inherit name path; }) cfg.hooks;
|
||||
in toString (pkgs.linkFarm "git-hooks" entries);
|
||||
};
|
||||
})
|
||||
|
||||
(mkIf (cfg.aliases != { }) { programs.git.iniContent.alias = cfg.aliases; })
|
||||
|
||||
(mkIf (lib.isAttrs cfg.extraConfig) {
|
||||
|
|
|
@ -5,4 +5,5 @@
|
|||
git-with-str-extra-config = ./git-with-str-extra-config.nix;
|
||||
git-with-signing-key-id = ./git-with-signing-key-id.nix;
|
||||
git-without-signing-key-id = ./git-without-signing-key-id.nix;
|
||||
git-with-hooks = ./git-with-hooks.nix;
|
||||
}
|
||||
|
|
2
tests/modules/programs/git/git-pre-commit-hook.sh
Normal file
2
tests/modules/programs/git/git-pre-commit-hook.sh
Normal file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
echo "pre-commit hook..."
|
26
tests/modules/programs/git/git-with-hooks.nix
Normal file
26
tests/modules/programs/git/git-with-hooks.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
programs.git = {
|
||||
enable = true;
|
||||
hooks = { pre-commit = ./git-pre-commit-hook.sh; };
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
function getGitConfig() {
|
||||
${pkgs.gitMinimal}/bin/git config \
|
||||
--file $TESTED/home-files/.config/git/config \
|
||||
--get $1
|
||||
}
|
||||
|
||||
assertFileExists home-files/.config/git/config
|
||||
hookPath=$(getGitConfig core.hooksPath)
|
||||
assertLinkExists $hookPath/pre-commit
|
||||
|
||||
actual="$(readlink "$hookPath/pre-commit")"
|
||||
expected="${./git-pre-commit-hook.sh}"
|
||||
if [[ $actual != $expected ]]; then
|
||||
fail "Symlink $hookPath/pre-commit should point to $expected via the Nix store, but it actually points to $actual."
|
||||
fi
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue