我正在使用一个 pre-push
钩子(Hook)来复制一些文件并使用 grunt bump
在压缩包之前提高版本号。这一切都发生在 master
分支上,假设是因为它是对 master
的 push ,所以值得增加补丁版本并压缩我的 Chrome 扩展以包含所有必要的文件。
我遇到的问题是版本修改得太晚,无法提交以将其包含在推送中,因此我的下一次提交总是比实际标记的版本晚 1 个补丁版本。
我这里有什么解决方案?这是一个单用户项目,所以我不太担心会违反 hook 的预期使用方式。是否可以选择提交和子推送,然后从此 Hook 返回非零值以防止推送发生?
#!/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?
最佳答案
而不是使用 client-side hook像 pre-push
甚至 pre-commit
一样,另一种选择是使用内容过滤器驱动程序,特别是“干净”的驱动程序,它在 git 提交
。
我建议在“Why is the index not updated after doing a git add in a pre-commit
hook?”中...但是这不会捕获最后一次提交(在 git describe
中),...因为正在构建所说的最后一次提交。
相反,如 this answer ,post-commit
Hook 可用于(如果它在正确的分支中运行)检测版本更改并添加/更新版本文件。
关于git - 在预推送中提交以更新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36232835/