1
+ #! /bin/bash
2
+ #
3
+ # Tag repository with the next pre tag
4
+ #
5
+
6
+ currBranchLine=$( git status | head -1)
7
+ cbAsArray=($currBranchLine )
8
+ branch=${cbAsArray[2]}
9
+ baseVer=' unknown'
10
+ #
11
+ # Determine the branch, and the version to use for the next tag
12
+ # User must be on a rc or dev branch, otherwise exist
13
+ #
14
+ if [ " $branch " = " dev" ]; then
15
+ cycle=$( git describe --tags --match ' cycle-*' --abbrev=0)
16
+ baseVer=$( echo $cycle | sed ' s/cycle-//' )
17
+ else
18
+ if [[ " $branch " =~ rc- ]]; then
19
+ baseVer=$( echo $branch | sed ' s/rc-//' )
20
+ else
21
+ echo " Exiting: You must be on a rc or dev branch"
22
+ exit
23
+ fi
24
+ fi
25
+
26
+ #
27
+ # get a list of all the previous pre tags and the determine the next number to use
28
+ #
29
+ matchingPreTags=($( git tag | grep ' pre-.*' ${baseVer} ) )
30
+
31
+ if [ -z " ${matchingPreTags[0]} " ]; then
32
+ nextNum=1
33
+ else
34
+ for aTag in " ${matchingPreTags[@]} " ; do
35
+ asNum=$( echo $aTag $| sed ' s/pre-//' | sed ' s/-.*$//' )
36
+ number_array+=(" $asNum " )
37
+ done
38
+ sorted_array=($( printf " %s\n" " ${number_array[@]} " | sort -n -r) )
39
+ nextNum=$( expr ${sorted_array[0]} + 1)
40
+ fi
41
+
42
+ #
43
+ # build the new tag string and then "git tag" and "git push --tags"
44
+ #
45
+ newPreTag=pre-${nextNum} -${baseVer}
46
+ read -n1 -s -p " New ($branch branch) tag will be: $newPreTag , make tag? (y/n [y]): " makeTag
47
+ echo
48
+ makeTagLower=$( echo " $makeTag " | tr ' [:upper:]' ' [:lower:]' )
49
+ if [ " $makeTagLower " = " y" ] || [ " $makeTagLower " = " " ]; then
50
+ echo ' >>>>>' git tag $newPreTag
51
+ git tag $newPreTag
52
+ read -n1 -s -p " push tags (y/n [n]): " doPush
53
+ doPushLower=$( echo " $doPush " | tr ' [:upper:]' ' [:lower:]' )
54
+ echo
55
+ if [ " $doPushLower " = " y" ]; then
56
+ echo ' >>>>>' git push origin --tags
57
+ git push origin --tags
58
+ else
59
+ echo not pushing
60
+ fi
61
+ else
62
+ echo not taging
63
+ fi
0 commit comments