Skip to content

Instantly share code, notes, and snippets.

@schnipseljagd
Created November 9, 2011 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schnipseljagd/1351823 to your computer and use it in GitHub Desktop.
Save schnipseljagd/1351823 to your computer and use it in GitHub Desktop.
prepare commit message wih refs generation
#!/bin/bash
#
# prepends the current branch to the commit subject
# replace it if a commit got e. g. cherry-picked
#
BRANCH=$(git name-rev --name-only HEAD)
# strip possible old branch (if cherry-picked)
COMMIT_MSG=$(sed -r -e 's/\([a-z0-9-]+\) //ig' $1)
#add reference dummy if in branch dev and not in commit message
REFS=''
if [[ "$BRANCH" == "dev" && !("$COMMIT_MSG" =~ "refs #") ]]; then
REFS='refs #'
fi
echo -e "($BRANCH) $REFS$COMMIT_MSG" > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment