Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.