首页 > 代码库 > 工作随笔——pre-commit钩子限制日志长度和提交的文件类型
工作随笔——pre-commit钩子限制日志长度和提交的文件类型
近期检查SVN时发现备份好的文件体积异常庞大。才跑2个月备份出来的大小就有4G多。仔细查询发现很多很多IDE自动生成的二进制文件。。。我类个去。好吧,开发不自觉就只有强制限制了。
google的时候发现这篇文章:http://blog.csdn.net/clever101/article/details/8560833
自己动手丰衣足食。脚本如下:
#!/bin/bashexport LANG="zh_CN.UTF-8" #确保中文日志显示正常,便于统计日志REPOS="$1"TXN="$2"#限制日志长度LENGTH=10SVNLOOK="/usr/local/csvn/bin/svnlook"BLACKLIST="target build classes bin/target .* *.iml *.ipr *.iws *.class " function error_exit(){ echo -e "1.Not allowed empty log " >&2 echo -e "2.Logs must be greater than ${LENGTH} characters or chinese" >&2 exit 1}function blacklist_exit(){ if [ ! -z "${INBLACKLIST}" ] ;then echo -e "some files in the blacklist , please cheack again !" >&2 echo -e "blacklist:\n ${BLACKLIST}" >&2 exit 1 fi}# 获取字符数量(包括换行符)TEMP_LENGTH=`${SVNLOOK} log -t "${TXN}" "${REPOS}"|sed ‘s/\s*$//g‘|sed ‘s/^\s*//g‘| wc --chars`# 统计换行符TEMP_LINE=`${SVNLOOK} log -t "${TXN}" "${REPOS}"| wc --lines`# 真实字符数量LOGMSG_LENGTH=`expr ${TEMP_LENGTH} - ${TEMP_LINE}`# 文件黑名单过滤 # 过滤文件夹INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/target/"`" #文件夹前后必须有/,否则匹配会有误伤blacklist_exitINBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/build/"`"blacklist_exitINBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/classes/"`"blacklist_exitINBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/bin/target/"`"blacklist_exit# 过滤所有已点开头的文件和文件夹INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/\."`"blacklist_exit# 过滤文件尾缀INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.iml$"`"blacklist_exitINBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.ipr$"`"blacklist_exitINBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.iws$"`"blacklist_exitINBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.class$"`"blacklist_exit# 判断日志长度是否满足要求if [ "${LOGMSG_LENGTH}" -lt ${LENGTH} ];then error_exitfiexit 0
不知道为啥,不能在返回的日志中加入中文,否则小乌龟报编码无法解析。去官方询问也没人回答,蛋疼。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。