Skip to content

Instantly share code, notes, and snippets.

@daanpeer
Created February 13, 2017 15:41
Show Gist options
  • Save daanpeer/30c12bf16cf954a51f0f88e908646d34 to your computer and use it in GitHub Desktop.
Save daanpeer/30c12bf16cf954a51f0f88e908646d34 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Add git branch if relevant
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Extact tracker abbreviation and ticket number (e.g. DS-123)
parse_git_tracker_and_ticket() {
parse_git_branch | grep -e '[A-Z]\+-[0-9]\+' -o
}
MESSAGE="$(cat $1)"
TICKET=`parse_git_tracker_and_ticket`
if [ -n "$TICKET" ]
then
if [[ $MESSAGE != *$TICKET* ]]
then
echo "New commit message: [$TICKET] $MESSAGE"
echo "$TICKET $MESSAGE" > $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment