Skip to content

Instantly share code, notes, and snippets.

@jearl4
Created May 27, 2019 05:31
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 jearl4/4792043650728cb57d92c5091b7bbc58 to your computer and use it in GitHub Desktop.
Save jearl4/4792043650728cb57d92c5091b7bbc58 to your computer and use it in GitHub Desktop.
script to add your branch name to a git commit message
#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