Created
May 27, 2019 05:31
-
-
Save jearl4/4792043650728cb57d92c5091b7bbc58 to your computer and use it in GitHub Desktop.
script to add your branch name to a git commit message
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
#If BRANCHES_TO_SKIP is null | |
if [ -z "$BRANCHES_TO_SKIP" ]; then | |
BRANCHES_TO_SKIP = (master) | |
fi | |
#Get branch name | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
#Set excluded branches and search on the excluded branches for | |
#branch name | |
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME") | |
BRANCH_IN_COMMIT=$(grep -c "$BRANCH_NAME" $1) | |
#If branch is non-zero and isn't excluded and branch is not listed | |
#more than once in commit open stream editor, create backup of | |
#branch name and on 1 line write branch name | |
if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1]] && ! [[ $BRANCH_IN_COMMIT -ge 1]]; then | |
sed -i.bak -e "ls@^@$BRANCH_NAME \n\nChange: @" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment