Created
August 22, 2019 08:46
-
-
Save tormjens/4297ab62d79d4ecf4cf0a4fe96e72f8c to your computer and use it in GitHub Desktop.
Git: Commit, tag and push
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
# commit unstaged changes | |
if [[ -n $(git status -s -uall) ]]; then | |
echo "Commiting unstaged changes.", | |
git add -A | |
git commit -m "wip" | |
fi | |
#get current hash and see if it already has a tag | |
GIT_COMMIT=`git rev-parse HEAD` | |
NEEDS_TAG=`git describe --contains $GIT_COMMIT` | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment