【问题标题】:Commit within a pre-push to update version在预推送更新版本中提交
【发布时间】:2016-07-13 23:17:46
【问题描述】:

我正在使用pre-push 钩子复制一些文件,并在压缩之前使用grunt bump 来提高我的包的版本号。这一切都发生在 master 分支上,假设是因为它是对 master 的推动,所以值得增加补丁版本并压缩我的 Chrome 扩展程序以包含所有必要的文件。

我遇到的问题是版本被修改得太晚,以至于无法提交钩子以将其包含在推送中,因此我的下一次提交总是比实际标记的版本落后 1 个补丁版本。

我在这里有什么解决方案?这是一个单用户项目,所以我不太担心会违背钩子的用途。是否可以选择提交和子推送,然后从此挂钩返回非零值以防止推送发生?

#!/bin/sh
PATH=$PATH:/usr/local/bin:/usr/local/sbin

BRANCH="$1"
EXTENSION_PATH=./extension
SCRIPT_PATH=$EXTENSION_PATH/script/


if [ "$branch" == "master" ]
then

    # remove the existing script folder; we'll just re-populate it
    echo "Removing existing scripts..."
    rm -rf $EXTENSION_PATH/script

    echo "Making target directory: $SCRIPT_PATH"
    mkdir $SCRIPT_PATH

    echo "Copying script files..."
    cp config.js $SCRIPT_PATH
    cp supportportal.js $SCRIPT_PATH
    cp -r ./scripts/ $SCRIPT_PATH/scripts/

    # bump the version
    grunt bump

    # commit changes and push here
    # >>>

    # if on a tag, append that to the filename
    VERSION=$(git describe --tags --always)

    # get name of the most top folder of git repo directory,
    # combine with revision tail
    OUTPUT=extension-$VERSION.zip

    # building archive
    zip -r -X $OUTPUT $EXTENSION_PATH 

    echo "Done!";
fi

exit 0 #exit 1 instead of 0 to cancel original push?

【问题讨论】:

    标签: git githooks


    【解决方案1】:

    除了使用client-side hook 之类的pre-push 甚至pre-commit 之外,另一种选择是使用内容过滤器驱动程序,特别是“干净”驱动程序,它会在git commit 上自动运行。

    我建议在“Why is the index not updated after doing a git add in a pre-commit hook?”中...但是这不会捕获最后一次提交(在git describe),...因为说最后一次提交正在构建中。

    相反,与this answer 一样,post-commit 挂钩可用于(如果它在正确的分支中运行)检测版本更改并添加/更新版本文件。

    【讨论】:

      猜你喜欢
      • 2020-01-06
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2018-12-17
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多