前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git commit 检查脚本

git commit 检查脚本

作者头像
美团骑手
发布2023-01-05 08:32:00
4300
发布2023-01-05 08:32:00
举报
文章被收录于专栏:技术进阶技术进阶
代码语言:javascript
复制
#!/bin/sh

MSG=`awk '{printf("%s",$0)}' $1`

if [ ${#MSG} -lt 10 ]  
  then
    echo "-------------------------------------------------------------------"
    echo "当前提交的 commit message 为: $MSG"
    echo "commit message 只有${#MSG}字符"
    echo "message的长度不能小于10, 本次提交失败,请完善commit message,再提交"
    echo "-------------------------------------------------------------------"
    exit 1
fi

if [[ $MSG =~ ^feat:[[:blank:]].* ]] || 
   [[ $MSG =~ ^feat(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^fix:[[:blank:]].* ]] ||
   [[ $MSG =~ ^fix(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^style:[[:blank:]].* ]] ||
   [[ $MSG =~ ^style(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^refactor:[[:blank:]].* ]] ||
   [[ $MSG =~ ^refactor(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^docs:[[:blank:]].* ]] ||
   [[ $MSG =~ ^docs(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^test:[[:blank:]].* ]] ||
   [[ $MSG =~ ^test(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^chore:[[:blank:]].* ]] ||
   [[ $MSG =~ ^chore(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]feat:[[:blank:]].* ]] || 
   [[ $MSG =~ ^revert:[[:blank:]]feat(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]fix:[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]fix(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]style:[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]style(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]refactor:[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]refactor(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]docs:[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]docs(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]test:[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]test(.*):[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]chore:[[:blank:]].* ]] ||
   [[ $MSG =~ ^revert:[[:blank:]]chore(.*):[[:blank:]].* ]]
  then
    exit 0
  else
    echo "-------------------------------------------------------------------"
    echo "当前提交的 commit message 为: $MSG"
    echo "本次提交失败,请参考 commit message 提交规范"
    echo "-------------------------------------------------------------------"
    exit 1
fi
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-01-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档