Skip to content

Instantly share code, notes, and snippets.

@mallowigi
Created February 1, 2021 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 mallowigi/f5462f2db81078cec3e7e81e7b4181c4 to your computer and use it in GitHub Desktop.
Save mallowigi/f5462f2db81078cec3e7e81e7b4181c4 to your computer and use it in GitHub Desktop.
Commit Message Hook
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master release-version)
fi
ALT_NAME=$(git branch | grep '*' | sed 's/* //')i
BRANCH_NAME=$(git symbolic-ref --short HEAD 2>/dev/null)
if [ -z $BRANCH_NAME ]; then BRANCH_NAME=ALT_NAME; fi
#DESCRIPTION=$(git config branch."$NAME".description)
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
echo "this is $(cat ${1})"
if ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $(cat "$1") == "[$BRANCH_NAME]"* ]] && ! [ -z "$BRANCH_NAME" ]; then
echo "[$BRANCH_NAME]: $(cat "${1}")" > "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment