用于自动将新版本号添加到当前git分支的脚本

时间:2014-12-05 16:24:58

标签: git bash

我创建了这个脚本,用于自动提高Symfony2中外部包的版本号(只是一个需要标记的标准git repo,因此composer会提取这些新版本。)

我只是想检查它是否有任何问题(并分享它,如果它对其他人有好处和帮助)因为我记得与一位高级开发人员交谈,他会通过输出到.version文件来跟踪版本号我担心他这样做可能有很好的理由!

#!/bin/bash

#get highest tag number
VERSION=`git describe --abbrev=0 --tags`

#replace . with space so can split into an array
VERSION_BITS=(${VERSION//./ })

#get number parts and increase last one by 1
VNUM1=${VERSION_BITS[0]}
VNUM2=${VERSION_BITS[1]}
VNUM3=${VERSION_BITS[2]}
VNUM3=$((VNUM3+1))

#create new tag
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"

echo "Updating $VERSION to $NEW_TAG"

#get current hash and see if it already has a tag
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $GIT_COMMIT`

#only tag if no tag already (would be better if the git describe command above could have a silent option)
if [ -z "$NEEDS_TAG" ]; then
    echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
    git tag $NEW_TAG
    git push --tags
else
    echo "Already a tag on this commit"
fi

0 个答案:

没有答案