Last active 1751197245

Increments a GIT tag tot he next version and pushes the tag upstream

git

john's Avatar john revised this gist 1751197244. Go to revision

No changes

john's Avatar john revised this gist 1751197217. Go to revision

1 file changed, 34 insertions

tag.increment.sh(file created)

@@ -0,0 +1,34 @@
1 + #!/bin/bash
2 +
3 + ### Increments the part of the string
4 + ## $1: version itself
5 + ## $2: number of part: 0 – major, 1 – minor, 2 – patch
6 +
7 + increment_version() {
8 + local delimiter=.
9 + local array=($(echo "$1" | tr $delimiter '\n'))
10 + array[$2]=$((array[$2]+1))
11 + if [ $2 -lt 2 ]; then array[2]=0; fi
12 + if [ $2 -lt 1 ]; then array[1]=0; fi
13 + NEW_TAG=$(local IFS=$delimiter ; echo "${array[*]}")
14 + }
15 +
16 +
17 + LATEST_TAG=$(git describe --tags --abbrev=0)
18 +
19 + increment_version "$LATEST_TAG" $1
20 +
21 +
22 + read -r -p "Apply tag $NEW_TAG to branch? [Y/n]" response
23 + response=${response,,} # tolower
24 + if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
25 + git tag -a $NEW_TAG -m "$NEW_TAG"
26 + else
27 + exit 1
28 + fi
29 +
30 + read -r -p "Push tag $NEW_TAG to origin? [Y/n]" response
31 + response=${response,,} # tolower
32 + if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
33 + git push origin $NEW_TAG --follow-tags
34 + fi
Newer Older