Skip to content

Commit

Permalink
Add commit-msg hook to git templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoriguchi committed Nov 9, 2023
1 parent 317c447 commit ce7bb9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ pkgs, config, lib, colors, ... }: {
imports = [ ./template.nix ];

home = {
packages = [ pkgs.nano ];

Expand Down
23 changes: 23 additions & 0 deletions modules/home-manager/git/template.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ pkgs, lib, config, ... }: {
programs.git.extraConfig.init.templatedir = "${config.home.homeDirectory}/.git_template";

home.file.".git_template/hooks/commit-msg".source = pkgs.writeShellScript "commit-msg" ''
PATH=${lib.makeBinPath [ pkgs.coreutils ]}
readonly COMMIT_MSG_FILE="$1"
function check_commit_msg_length {
readonly MAX_MSG_LENGTH=72
local title=$(head -n 1 "$COMMIT_MSG_FILE")
if [ ''${#title} -gt $MAX_MSG_LENGTH ]; then
# TODO figure out how to use hex colors variable
echo -e "\x1b[1;38;5;203mCommit title is ''${#title} characters long, must be equal or shorter than $MAX_MSG_LENGTH characters!\e[0m";
exit 1
fi
}
check_commit_msg_length
'';
}

0 comments on commit ce7bb9b

Please sign in to comment.