Clone
git clone [email protected]:faf373e5c05a8cb4bc49c048504dbea6.git git-hook-prepare-commit-msg
Clone
git clone [email protected]:faf373e5c05a8cb4bc49c048504dbea6.git git-hook-prepare-commit-msg
#!/bin/bash | |
# prepends branch name and description to commit message | |
# https://gist.github.com/tomviner/faf373e5c05a8cb4bc49c048504dbea6/ | |
# | |
# put this in repo/.git/hooks/ and chmod +x the file | |
# see the following stackoverflow question about how | |
# to do this for every new/cloned repo: | |
# http://stackoverflow.com/a/8842663/207894 | |
# fetch branch name after last instace of '/' | |
FULL_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
BRANCH=${FULL_BRANCH##*/} | |
# don't process if branch in excluded list | |
if [ -z "$GIT_BRANCHES_TO_SKIP" ]; then | |
# default skip list is master and rebase branches | |
# list can be set outside if this script | |
GIT_BRANCHES_TO_SKIP=(master HEAD staging); | |
fi | |
EXCLUDED=$(printf "%s\n" "${GIT_BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH$") | |
# skip if commit message is non-empty (e.g. with --amend or --message) | |
# or if excluded branch, | |
# or if branch was already added | |
if [[ -z $(head -n1 $1) && $EXCLUDED -eq 0 && $(echo $1 | grep -c "$BRANCH") -eq 0 ]] ; then | |
sed -i.bak "1s/^/$BRANCH /" $1 | |
fi |
still using that daily 😹