Skip to content

Instantly share code, notes, and snippets.

@xu3352
Last active August 12, 2017 09:12
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 xu3352/82c843e88101fd889dcd6a3e2f1c245e to your computer and use it in GitHub Desktop.
Save xu3352/82c843e88101fd889dcd6a3e2f1c245e to your computer and use it in GitHub Desktop.
SVN:pre-commit
#!/bin/sh
#author:xu3352@gmail.com
#desc:check commit message length
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/local/bin/svnlook
TIME=`date "+%Y-%m-%d %H:%M:%S"`
# env setting
envSetting="env LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8"
# commit message content
MSG=`$envSetting $SVNLOOK log -t "$TXN" "$REPOS"`
# chars length
# MSG_LEN=`echo $MSG | wc -m`
MSG_LEN=`python -c "import sys; print len(sys.argv[1].decode(\"UTF-8\"))" "$MSG"`
echo "$TIME - pre-commit - REPOS:$REPOS TXN:$TXN MSG_LENGTH:$MSG_LEN - MSG:$MSG" >> /tmp/svn-pre-commit.log
# message content must greater than 20 chars
if [ "$MSG_LEN" -lt 20 ];
then
echo -e "\"$MSG\" 不能少于 20 个字!" 1>&2
exit 1
fi
# message content must matching target chars
JIRA_NUM=`echo "$MSG" | grep "\(WX\|SD\|YD\|INTERFACE\)-[0-9]\+" | wc -m`
if [ "$JIRA_NUM" -lt 2 ];
then
echo -e "\"$MSG\" 没有对应项目的 JIRA 编号!" 1>&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment