git增量校验代码

npm install pre-commit --save-dev
npm instal husky --save-dev


 "husky": {
    "hooks": {
      "pre-commit": "npm run prettier && ./check-keyword.sh"
    }
  },

check-keyword.sh

#!/bin/bash

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`

echo  "${green}start checking keyword${reset}"

checkList='TODO debugger console <Table rgb #' #配置检测条件
passfileList='.sh .json'  #配置后缀
isError=0

for FILE in `git diff --ignore-space-at-eol --name-only --staged`; do
      isPass=0
     #排除文件
     for passFile in $passfileList;do
      if [[ $FILE == *"$passFile"* ]] ; then
        echo $FILE '不检测此类型文件'
        isPass=1;
        continue
    fi
    done
  `git diff  --staged $FILE >a.txt`
   `grep -v '-' a.txt>b.txt`
    if [ $isPass -eq 0 ]; then
     #调试
    for checkItem in $checkList;do
      grep  $checkItem b.txt 2>&1 >/dev/null 
      if [ $? -eq 0 ]; then
        echo $FILE '包含'$checkItem'请删除后再提交'
        isError=1
      fi
    done
     fi
     
done
if [ $isError -eq 0 ]; then
exit 
fi

if [ $isError -eq 1 ]; then
exit 1
fi



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值