git推送前HOOK pre-push判断版本号增加再推送

我写了一个C++程序,然后每次编译后,记不得当时的版本是哪个源代码,对于core dump复现调试很麻烦。

为此我想了一个办法,首先在include/git_version.hpp 创建一个版本的文件

/*
 * @Description:
 * @Author: jiangsheng
 * @Date: 2024-01-11 10:59:53
 * @LastEditors: jiangsheng
 * @LastEditTime: 2024-01-11 20:07:28
 */
#ifndef __JS_GIT_VERSION__H
#define __JS_GIT_VERSION__H
#include <iostream>
namespace JS_GIT_VERSION
{
const char *VERSION_STRING = "v1.5.1";
void cout_version()
{
    std::cout << "VERSION_STRING  " << VERSION_STRING << std::endl;
}
}; // namespace JS_GIT_VERSION
#endif

然后在单例模式下,上来就调用cout_version()函数,这样一启动就有输出,我就知道现在是哪个版本号。

然后我在master分支和develop分支之间 每次master发布版本号 都写上比当前tag大的版本号,

例如最新tag是V1.5.1,那么我下次就写V1.5.2 或者 V1.6什么的。

然后我在develop分支下 需要判断一下 最后push时候的HPP里头记录的TAG,是否不等于git tag里头的TAG,这样就可以保证自己不会忘记更新HPP文件里的TAG就直接push了。

然后master分支pull request develop的代码,这样在发布新版本时候 只要指定的版本和刚刚代码HPP里头的版本一致就可以了

下面是pre-push的代码

#!/bin/bash
while read local_ref local_sha remote_ref remote_sha
do
    if [ "$remote_ref" == "refs/heads/develop" ]; then
        # Get the latest version number from the git_version.hpp file
        current_version=$(grep -oP 'const char \*VERSION_STRING = "\K[^"]+' include/git_version.hpp)
        echo "hpp version : $current_version"
        # Get the latest tag on the develop branch
        latest_tag=$(git tag -l --sort=-v:refname | head -n 1)
        
        if [ $? -ne 0 ]; then
            echo "Error getting latest tag: $latest_tag"
            # Continue with the push even if tag retrieval fails
            continue
        fi

        echo "git tag: $latest_tag"

        if [ -n "$latest_tag" ] && [ "$latest_tag" == "$current_version" ]; then
            echo "版本号未更新,停止上传"
            exit 1
        else
            echo "保存的版本号与上传版本号不同,允许上传"
        fi
    fi
done

相关推荐

  1. gitHOOK pre-push判断版本号增加

    2024-01-12 09:06:04       37 阅读
  2. git基础教程(10) git push将本地修改到远端

    2024-01-12 09:06:04       16 阅读
  3. Git本地文件到仓库

    2024-01-12 09:06:04       44 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-12 09:06:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-12 09:06:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-12 09:06:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-12 09:06:04       20 阅读

热门阅读

  1. EasyExcel+多线程实现大数据量

    2024-01-12 09:06:04       38 阅读
  2. MergeTwoSortedLists 【合并有序链表】

    2024-01-12 09:06:04       43 阅读
  3. 【精选】 dockerFile 使用简介 (超详细)

    2024-01-12 09:06:04       59 阅读
  4. ADO.Net前端页面调用后台方法使用

    2024-01-12 09:06:04       35 阅读
  5. #Uniapp:upx 和 rpx使用区分 & 设计稿计算规则

    2024-01-12 09:06:04       45 阅读
  6. Spark指令参数,RDD--学习笔记

    2024-01-12 09:06:04       37 阅读
  7. 【ARM 嵌入式 编译系列 3.5 -- gcc 链接参数介绍】

    2024-01-12 09:06:04       36 阅读