feat(git): custom merge message hook

This commit is contained in:
2026-10-16 18:42:49 +02:00
parent 3e7c76aed7
commit 2c60e23ac2
3 changed files with 29 additions and 0 deletions

3
.gitignore vendored
View File

@@ -36,6 +36,9 @@ git/*
git/config.d/*
!git/config.d/aflabs.conf
!git/config.d/flare.conf
!git/hooks
git/hooks/*
!git/hooks/merge-msg
# ghostty
!ghostty

View File

@@ -73,3 +73,7 @@
[includeIf "gitdir:~/git/gitlab.com/flare-foundation/"]
path = ~/.config/git/config.d/flare.conf
[hook "merge-msg"]
command = ~/.config/git/hooks/merge-msg
event = prepare-commit-msg

22
git/hooks/merge-msg Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# rewrite default merge subject to `merge: <branch with dashes as spaces>`
msg_file="$1"
source="$2"
[[ "$source" == "merge" ]] || exit 0
subject=$(head -n1 "$msg_file")
if [[ "$subject" =~ ^Merge\ remote-tracking\ branch\ \'[^/]+/([^\']+)\' ]]; then
branch="${BASH_REMATCH[1]}"
elif [[ "$subject" =~ ^Merge\ branch\ \'([^\']+)\' ]]; then
branch="${BASH_REMATCH[1]}"
else
exit 0
fi
{
printf 'merge: %s\n' "${branch//-/ }"
tail -n +2 "$msg_file"
} > "$msg_file.tmp" && mv "$msg_file.tmp" "$msg_file"