Skip to content

Instantly share code, notes, and snippets.

@branonbarrett
Last active October 17, 2018 18:25
Show Gist options
  • Save branonbarrett/0b01b8ff236f71cf80d431fafcd1b1c4 to your computer and use it in GitHub Desktop.
Save branonbarrett/0b01b8ff236f71cf80d431fafcd1b1c4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# modified from https://gist.github.com/bartoszmajsak/1396344
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test release)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME=$(printf "${BRANCH_NAME##*/}" | grep -Eo 'QPPBSR-[0-9]+')
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
BRANCH_IN_COMMIT=$(grep -c "$BRANCH_NAME" $1)
if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
sed -i.bak -e "1s/^/$BRANCH_NAME /" $1
fi
@branonbarrett
Copy link
Author

branonbarrett commented Oct 2, 2018

For quick install:

$ cd <your project dir>
$ curl https://gist.githubusercontent.com/branonbarrett/0b01b8ff236f71cf80d431fafcd1b1c4/raw/a02e566617ce43520250f902a727b1535ef4f4cb/prepare-commit-message.sh > .git/hooks/prepare-commit-msg && chmod u+x .git/hooks/prepare-commit-msg
  • get Gist
  • copy into .git/hooks/prepare-commit-msg file
  • make it executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment