forked from FarisHijazi/Rarbg-Enhancer-UserScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gittag-increment.sh
29 lines (23 loc) · 857 Bytes
/
gittag-increment.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
#Get the highest tag number
VERSION=$(git describe --abbrev=0 --tags 2>/dev/null)
VERSION=${VERSION:-'0.0.0'}
#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" -m "autogenerated"
else
echo "Already a tag on this commit"
fi