feat(git): custom merge message hook
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -36,6 +36,9 @@ git/*
|
|||||||
git/config.d/*
|
git/config.d/*
|
||||||
!git/config.d/aflabs.conf
|
!git/config.d/aflabs.conf
|
||||||
!git/config.d/flare.conf
|
!git/config.d/flare.conf
|
||||||
|
!git/hooks
|
||||||
|
git/hooks/*
|
||||||
|
!git/hooks/merge-msg
|
||||||
|
|
||||||
# ghostty
|
# ghostty
|
||||||
!ghostty
|
!ghostty
|
||||||
|
|||||||
@@ -73,3 +73,7 @@
|
|||||||
|
|
||||||
[includeIf "gitdir:~/git/gitlab.com/flare-foundation/"]
|
[includeIf "gitdir:~/git/gitlab.com/flare-foundation/"]
|
||||||
path = ~/.config/git/config.d/flare.conf
|
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
22
git/hooks/merge-msg
Executable 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"
|
||||||
Reference in New Issue
Block a user