diff --git a/.gitignore b/.gitignore index c61a793..05a0341 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/git/config b/git/config index 5d4e6d2..bb82f49 100644 --- a/git/config +++ b/git/config @@ -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 diff --git a/git/hooks/merge-msg b/git/hooks/merge-msg new file mode 100755 index 0000000..63889ce --- /dev/null +++ b/git/hooks/merge-msg @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# rewrite default merge subject to `merge: ` + +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"