Created
November 29, 2016 21:34
-
-
Save tianskylan/92c94c73e0434c61a6e2d70cc7972ddd to your computer and use it in GitHub Desktop.
Prefix branch name to commit messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Automatically adds branch name and branch description to every commit message. | |
# I made this a commit-msg hook to get it working with GitUp client. Otherwise, prepare-commit-msg hook should work as well. | |
# | |
# Usage: | |
# 1. Save this file in PROJECT_NAME/.git/hooks, with name `commit-msg` | |
# 2. chmod 755 commit-msg | |
# 3. Profit. | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
DESCRIPTION=$(git config branch."$NAME".description) | |
TEXT=$(cat "$1" | sed '/^#.*/d') | |
if [ -n "$TEXT" ] | |
then | |
echo "[$NAME] $TEXT" > "$1" | |
if [ -n "$DESCRIPTION" ] | |
then | |
echo "" >> "$1" | |
echo $DESCRIPTION >> "$1" | |
fi | |
else | |
echo "Aborting commit due to empty commit message." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment