Skip to content

Instantly share code, notes, and snippets.

@mehdichaouch
Last active July 26, 2016 09:15
Show Gist options
  • Save mehdichaouch/b8ed35a96ea3f3b6581e to your computer and use it in GitHub Desktop.
Save mehdichaouch/b8ed35a96ea3f3b6581e to your computer and use it in GitHub Desktop.
Script Git hook which prefix BRANCH name in every COMMIT if this one is like MAG-1234 or SUP-1234. Add also the branch description if define a the end of the commit.
#!/bin/sh
BRANCH_NAME=$(git symbolic-ref --short HEAD)
# Set description with : git branch --edit-description $(git symbolic-ref --short HEAD)
BRANCH_DESCRIPTION=$(git config branch."$BRANCH_NAME".description)
STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/\(\(MAG\|SUP\)-[0-9]*\).*/\1/p')
if [ -n "$STORY_NUMBER" ]; then
sed -i.back "1s/^/$STORY_NUMBER : \n/" "$1"
# Add the branch description if there is one
if [ -n "$BRANCH_DESCRIPTION" ]; then
echo $BRANCH_DESCRIPTION >> "$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment