Last active
February 24, 2020 08:33
-
-
Save goforbroke1006/9cd148e8a3123505bd2c5e6695e28232 to your computer and use it in GitHub Desktop.
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/sh | |
#Get the highest tag number | |
VERSION=$(git describe --abbrev=0 --tags) | |
VERSION=${VERSION:-'0.0.1'} | |
#Get number parts | |
MAJOR="${VERSION%%.*}"; VERSION="${VERSION#*.}" | |
MINOR="${VERSION%%.*}"; VERSION="${VERSION#*.}" | |
PATCH="${VERSION%%.*}"; VERSION="${VERSION#*.}" | |
#Increase version | |
PATCH=$((PATCH+1)) | |
#Get current hash and see if it already has a tag | |
GIT_COMMIT=$(git rev-parse HEAD) | |
NEEDS_TAG=$(git describe --contains "$GIT_COMMIT") | |
#Create new tag | |
NEW_TAG="$MAJOR.$MINOR.$PATCH" | |
echo "Updating to $NEW_TAG" | |
#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" | |
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
$ curl -O https://gist.githubusercontent.com/goforbroke1006/9cd148e8a3123505bd2c5e6695e28232/raw/d77ebe9416ea16c7553546d4ce2058bd66ebd215/git-retag-patch
$ sudo mv ./git-retag-patch /usr/local/bin/
$ sudo chmod +x /usr/local/bin/git-retag-patch