Skip to content

Instantly share code, notes, and snippets.

@a88zach
Forked from branonbarrett/prepare-commit-message.sh
Last active November 19, 2021 16:20
Show Gist options
  • Save a88zach/cfd4b52bee36a9df6ad71ea9a2b6d002 to your computer and use it in GitHub Desktop.
Save a88zach/cfd4b52bee36a9df6ad71ea9a2b6d002 to your computer and use it in GitHub Desktop.
#!/bin/bash
# modified from https://gist.github.com/bartoszmajsak/1396344
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master main develop test release)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_TYPE=$(printf "${BRANCH_NAME%/*}")
BRANCH_CONTEXT=$(printf "${BRANCH_NAME##*/}")
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
if [ -n "$BRANCH_TYPE" ] && [ -n "$BRANCH_CONTEXT" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]]; then
sed -i.bak -e "1s/^/$BRANCH_TYPE($BRANCH_CONTEXT) /" $1
fi
@a88zach
Copy link
Author

a88zach commented Oct 17, 2018

To Install:

$ cd <your project dir>
$ curl https://gist.githubusercontent.com/a88zach/cfd4b52bee36a9df6ad71ea9a2b6d002/raw/4445ea130ed3c3968c6029222c268dbd08798a6e/prepare-commit-message.sh > .git/hooks/prepare-commit-msg && chmod u+x .git/hooks/prepare-commit-msg

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