Skip to content

Instantly share code, notes, and snippets.

@ingyeoking13
Created August 19, 2021 08:42
Show Gist options
  • Save ingyeoking13/d2d200d1622e769e7c30d522fb37ac8e to your computer and use it in GitHub Desktop.
Save ingyeoking13/d2d200d1622e769e7c30d522fb37ac8e to your computer and use it in GitHub Desktop.
git hook을 이용한 커밋 메시지 수정
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
COMMIT_MSG=$(cat $COMMIT_MSG_FILE)
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *')
ADDED_FILES=$(git diff --cached --name-only)
TOKENED=(${ADDED_FILES///n/ })
FILEPATH=${TOKENED[0]}
FILE_TOKENED=(${FILEPATH//// })
arrLength=${#FILE_TOKENED[@]} #file name
filename=${FILE_TOKENED[${arrLength}-1]}
filename=(${filename//./ })
filename=${filename[0]}
# echo file path $FILEPATH
# echo file tokened $FILE_TOKENED
# echo arr Length $arrLength
# echo file name $filename
regexp="^ps[[:space:]]+(\-([[:alnum:]]+)[[:space:]]+)?(.+)$"
if [[ $COMMIT_MSG =~ $regexp ]]
then
platform=${BASH_REMATCH[2]}
msg=${BASH_REMATCH[3]}
fi
# echo file $FILEPATH
# echo platform $platform
# echo msg $msg
[[ -z $platform ]] && platform='bj'
result="feat(${BRANCH_NAME}): [${platform}, ${filename}] ${msg}"
echo "${result}" > $COMMIT_MSG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment