当前位置: 首页 > news >正文

maven 项目添加 git-hook 脚本,约束提交内容格式

git 提交代码,推送代码,可以通过在 .git/hooks 目录中的 bash 脚本来做一定的验证工作。

本例使用插件 maven-antrun-plugin 自动输出脚本至 .git/hooks 目录中,在 pom.xml 中的使用示例如下:

        <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId><executions><execution><phase>generate-sources</phase><goals><goal>run</goal></goals><configuration><tasks><!-- 生成commit-msg文件 --><echo file="${basedir}/.git/hooks/commit-msg"message="#!/usr/bin/env bash${line.separator}${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="# Color codes${line.separator}red='\033[0;31m'${line.separator}yellow='\033[0;33m'${line.separator}blue='\033[0;34m'${line.separator}NC='\033[0m' # No colors"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="${line.separator}${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="# Regex &amp; Usage${line.separator}commit_regex=&quot;^(\[[A-Za-z]+\-[0-9]+\]|merge|Merge)\s&quot;${line.separator}error_message=&quot;Aborting commit. Commit message must start with ${yellow} 开发任务编号&quot;${line.separator}usage=&quot;开发任务编号 Commit Message. \n${blue}示例: [TASK-101] 完成A功能开发&quot;"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="${line.separator}${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="if ! grep -qE &quot;$commit_regex&quot; &quot;$1&quot;; then${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="  printf &quot;${red}$error_message\n&quot;${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="  printf &quot;${yellow}Commit Regex: ${NC}${commit_regex}\n&quot;${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="  printf &quot;${red}Usage: ${NC}${usage}\n&quot;${line.separator}"/><echo file="${basedir}/.git/hooks/commit-msg" append="true"message="  exit 1${line.separator}fi"/><!-- 生成pre-push文件 --><echo file="${basedir}/.git/hooks/pre-push"message="#!/usr/bin/env bash${line.separator}${line.separator}"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="# Color codes${line.separator}red='\033[0;31m'${line.separator}yellow='\033[0;33m'"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="${line.separator}${line.separator}"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="command=&quot;./mvnw.cmd clean test&quot;${line.separator}${command}"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="${line.separator}${line.separator}"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="if ! [ $? -eq 0 ]; then${line.separator}"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="  printf &quot;${red}Make sure successfully execute command: ${yellow}$command${red}.&quot;${line.separator}"/><echo file="${basedir}/.git/hooks/pre-push" append="true"message="  exit 1${line.separator}fi"/><!-- 设置权限 --><chmod dir="${basedir}/.git/hooks" perm="755" includes="**/*"/></tasks></configuration></execution></executions></plugin>

插件会自动输出 commit-msgpre-push 两个脚本文件


(END)

http://www.lryc.cn/news/220694.html

相关文章:

  • 18、Flink的SQL 支持的操作和语法
  • 泛微OA_lang2sql 任意文件上传漏洞复现
  • Rust编程基础核心之所有权(上)
  • 优化改进YOLOv5算法之添加DCNv3模块,有效提升目标检测效果
  • VSCode 连接不上 debian 的问题
  • 【ElasticSearch系列-06】Es集群架构的搭建以及集群的核心概念
  • 软考高级系统架构设计师系列案例考点专题六:面向服务架构设计
  • 【入门Flink】- 07Flink DataStream API【万字篇】
  • AI:55-基于深度学习的人流量检测
  • node版本管理工具nvm
  • stable-diffusion-webui安装Wav2Lip
  • Nacos-2.2.2源码修改集成高斯数据库GaussDB,postresql
  • Linux 内核中根据文件inode号获取其对应的struct inode
  • Pycharm-community-2021版安装和配置
  • 飞书开发学习笔记(一)-应用创建和测试
  • 【Mybatis小白从0到90%精讲】12:Mybatis删除 delete, 推荐使用主键删除!
  • RocketMQ批量发送消息❓
  • 一键同步chromedriver版本
  • Zephyr-7B-β :类GPT的高速推理LLM
  • 【笔试题】位运算
  • RT-Thread 10. 使用keil4编译GD32F450
  • Vue 跨域的两种解决方式
  • 【windows Docker 安装mysql:只需3条命令】
  • 【软件逆向】如何逆向Unity3D+il2cpp开发的安卓app【IDA Pro+il2CppDumper+DnSpy+AndroidKiller】
  • vue3ref和reactive
  • [架构之路-244]:目标系统 - 设计方法 - 软件工程 - 软件开发方法与软件开发模型
  • Matter 系列 #10|Matter 的证书吊销机制
  • mybatis动态表名
  • 高校为什么需要大数据挖掘平台?
  • @Value的使用