Skip to content

Instantly share code, notes, and snippets.

@jincod
Last active July 27, 2017 08:40
Show Gist options
  • Save jincod/149fa1f7a8880bcba720e0afbc821677 to your computer and use it in GitHub Desktop.
Save jincod/149fa1f7a8880bcba720e0afbc821677 to your computer and use it in GitHub Desktop.
git hook for added branch name to commit message
#!/bin/sh
PROJECT_NAME="PROJECT_NAME"
COMMIT_MSG=$1
IS_EXISTS=$(cat $COMMIT_MSG |grep -i "$PROJECT_NAME"|wc -l)
FULL_BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
BRANCH_NAME=${FULL_BRANCH_NAME##*/}
addBranchName() {
echo "$BRANCH_NAME" "$(cat $COMMIT_MSG)" > $COMMIT_MSG
}
if [[ $BRANCH_NAME == *$PROJECT_NAME* ]]; then
if [ $IS_EXISTS -eq 0 ] ; then
addBranchName
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment