Created
January 11, 2012 09:11
-
-
Save andrewle/1593841 to your computer and use it in GitHub Desktop.
Automatically append a ticket number reference to git 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/bash | |
NUMLINES=$(cat "$1" | | |
sed '{ | |
# Ignore the "References #blah" line | |
/^References \#[0-9]*/d | |
# Remove blank lines | |
/^$/d | |
# Remove lines containing only whitespace | |
/^[ \t]*$/d | |
# Remove comments that will be ignored by git | |
/^\#.*/d | |
}' | | |
wc -l) | |
if [ $NUMLINES -eq "0" ]; then | |
echo >&2 Aborting commit due to empty commit message. | |
exit 1 | |
fi |
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/bash | |
# Don't do anything if we're editing a commit as a result of a merge, | |
# rebase, amend, etc | |
[[ $2 != "" ]] && [[ $3 != "" ]] && exit 0 | |
TICKET_NUM=$(git branch | grep '^\*' | awk -F '[/-]' '{print $2}') | |
# The ticket number must be all digits | |
echo $TICKET_NUM | grep "^[[:digit:]]\+$" > /dev/null | |
[[ "$?" == "1" ]] && exit 0 | |
grep "References #[[:digit]]\+" | |
if [ "$?" == "1" ]; then | |
echo >> "$1" | |
echo "References #$TICKET_NUM" >> "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment