Skip to content

Instantly share code, notes, and snippets.

@alfredodeza
Last active March 17, 2017 11:20
Show Gist options
  • Save alfredodeza/5666368 to your computer and use it in GitHub Desktop.
Save alfredodeza/5666368 to your computer and use it in GitHub Desktop.
Pre-commit hook to prepend the branch name on every commit message
#!/bin/sh
# this file should be marked as executable and placed on .git/hooks/
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
# FogBugz
if [[ $BRANCH_NAME =~ ^case ]]; then
CASE_NUMBER=$(echo $BRANCH_NAME 2>/dev/null | tr -d "case" | tr -d "-" | tr -d "_")
echo "[case $CASE_NUMBER] $(cat $1)" > $1
# Trac
elif [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ] && [ "$BRANCH_NAME" != "(nobranch)" ]; 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