Skip to content

Instantly share code, notes, and snippets.

@maxtortime
Forked from qkraudghgh/shell
Last active July 30, 2020 08:16
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 maxtortime/a03e3289db5d600899eda5dfa5e3b6cf to your computer and use it in GitHub Desktop.
Save maxtortime/a03e3289db5d600899eda5dfa5e3b6cf to your computer and use it in GitHub Desktop.
feature/sample 이름을 가진 브랜치일때 커밋 메시지 앞에 [sample] 을 붙여주는 훅
#!/bin/sh
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop release hotfix)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ $? -eq 0 ]; then
BRANCH_NAME="${BRANCH_NAME##*/}"
JIRA_ID=`echo $BRANCH_NAME | grep -oE '[A-Z]+-[0-9]+'`
JIRA_ID="[$JIRA_ID]"
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
# JIRA_ID가 존재하고 master develop release hotfix 브랜치가 아닐 때만 동작함
if [ -n $JIRA_ID ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] ; then
sed -i.bak -e "1s/^/$JIRA_ID /" $1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment