Skip to content

Instantly share code, notes, and snippets.

@kujiy
Created October 9, 2019 03:26
Show Gist options
  • Save kujiy/00c42381a29cf67f065ed079b86ebe66 to your computer and use it in GitHub Desktop.
Save kujiy/00c42381a29cf67f065ed079b86ebe66 to your computer and use it in GitHub Desktop.
Add the branch name to commit message
#!/bin/sh
#ブランチ名を取得
Branch="$(git rev-parse --abbrev-ref HEAD)"
#コミットメッセージの最初にブランチ名を追加
#echo "Hook is working..."
#echo "コミットメッセージにbranch名を強制付与しています..."
MSG=$(cat .git/COMMIT_EDITMSG)
PAT="^(squash|fixup)"
if echo $MSG | grep -E "$PAT" > /dev/null
then
# echo "squashから始まるコミットメッセージには強制付与をしません。"
echo
else
mv $1 $1.tmpbycommit-msg
echo "[$Branch] $(cat $1.tmpbycommit-msg)" > $1
fi
@kujiy
Copy link
Author

kujiy commented Oct 9, 2019

# a repo
cat .git/hooks/commit-msg
# global
cat ~/.git-template/hooks/commit-msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment