Skip to content

Instantly share code, notes, and snippets.

@TheHippo
Last active July 13, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheHippo/8ad10014b39f6210bae8c8decacb2620 to your computer and use it in GitHub Desktop.
Save TheHippo/8ad10014b39f6210bae8c8decacb2620 to your computer and use it in GitHub Desktop.
If your git branch starts with a number add `ref #ISSUE-NUMBER` to commit msg
#!/bin/bash
NAME=$(git branch | grep '*' | sed 's/* //')
ISSUE_NUMBER=$(git branch | grep '*' | sed 's/* //' | tr -dc '0-9')
if [ "$2" == "message" ]; then
echo "Message given, we do not modify the git commit message"
exit 0
fi
if [ "$2" == "merge" ] || [ "$2" == "squash" ]; then
echo "$2 commit, we do not edit the message"
exit 0
fi
if [ -z "$ISSUE_NUMBER" ]; then
echo -n -e "\n# Current branch: $NAME" | cat - "$1" > .git-commit-msg-temp
else
echo -n -e "\n\nrefs #$ISSUE_NUMBER\n#Current branch: $NAME" | cat - "$1" > .git-commit-msg-temp
fi
cat .git-commit-msg-temp > "$1"
rm .git-commit-msg-temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment