-
Notifications
You must be signed in to change notification settings - Fork 9
/
gg-functions
executable file
·207 lines (190 loc) · 5.83 KB
/
gg-functions
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
# cautions:
# do not have % in the name of the branches (% are treated as indicator for trail branches)
# "master, develop, release, feature"... are indicators for different type, so do not have a "*master*" name for a develop type, so for other types..
genDebugLog(){
git --version > gg-debug.txt
git status >> gg-debug.txt
git branch >> gg-debug.txt
}
get_currentBranch(){
currentBranch=$(git rev-parse --abbrev-ref HEAD) # in case of detached HEAD state
if [[ $currentBranch == "HEAD" ]]; then
pointer=1
currentBranch=$(git rev-parse HEAD)
currentBranch=${currentBranch:0:7}
fi
}
get_isTrialBranch(){
isTrialBranch=$(echo $currentBranch|grep %) # only trial branch have %
}
get_currentBranchType(){
get_currentBranch
if [[ -n "$pointer" ]]; then
currentBranchType="pointer" # detached HEAD state
return
fi
get_isTrialBranch
if [[ -z "$isTrialBranch" ]]; then # not the trialBranch
if [[ -n $(echo $currentBranch | grep -- "-FromBranch-") ]]; then
temp=$(echo ${currentBranch%%-FromBranch-*} | grep issues) ;[[ -n "$temp" ]] && currentBranchType="issues" && return
temp=$(echo ${currentBranch%%-FromBranch-*} | grep feature);[[ -n "$temp" ]] && currentBranchType="feature"&& return
fi
temp=$(echo $currentBranch | grep \/)
if [[ -n "$temp" ]]; then # have a "/" struct
currentBranchTypeAll=$(echo $currentBranch|sed 's#\([^/]*\)\/.*#\1#')
temp=$(echo $currentBranchTypeAll | grep issues) ;[[ -n "$temp" ]] && currentBranchType="issues" && return
temp=$(echo $currentBranchTypeAll | grep feature);[[ -n "$temp" ]] && currentBranchType="feature"&& return
else # do not have a "/" struct
currentBranchTypeAll=$currentBranch
temp=$(echo $currentBranchTypeAll | grep release);[[ -n "$temp" ]] && currentBranchType="release"&& return
temp=$(echo $currentBranchTypeAll | grep hotfix) ;[[ -n "$temp" ]] && currentBranchType="hotfix" && return
temp=$(echo $currentBranchTypeAll | grep master) ;[[ -n "$temp" ]] && currentBranchType="master" && return
temp=$(echo $currentBranchTypeAll | grep develop);[[ -n "$temp" ]] && currentBranchType="develop"&& return
fi
else # it is a trialBranch
currentBranchType="trial"&& return
fi
echo $currentBranch
printf "can not get current BranchType name!!!!\n"
exit 1
}
get_father() {
get_currentBranchType
if [[ $currentBranchType == "issues" || $currentBranchType == "feature" ]]; then
father=$(echo $currentBranch | grep -- '-FromBranch-')
if [[ -z $father ]]; then
get_develop
father=$develop
else
father=$(echo ${currentBranch#*-FromBranch-})
fi
elif [[ $currentBranchType == "trial" ]]; then
father=$(echo $currentBranch|sed 's#\(.*\)%.*#\1#')
else
father=
fi
}
get_develop() {
get_currentBranchType
devCode=$(echo $currentBranchTypeAll|awk -F '|' '{print $1}')
haveDevCode=$(echo $currentBranchTypeAll|grep \|)
if [[ -z "$haveDevCode" ]];then
devCode=
fi
if [[ -n "$devCode" ]]; then
develop="$devCode|develop"
else
develop="develop"
fi
}
get_master() {
get_currentBranchType
devCode=$(echo $currentBranchTypeAll|awk -F '|' '{print $1}')
haveDevCode=$(echo $currentBranchTypeAll|grep \|)
if [[ -z "$haveDevCode" ]];then
devCode=
fi
if [[ -n "$devCode" ]]; then
master="$devCode|master"
else
master="master"
fi
}
get_feature() {
get_develop
if [[ -z $devCode ]]; then
feature="feature"
else
feature="$devCode|feature"
fi
}
get_issues() {
get_develop
if [[ -z $devCode ]]; then
issues="issues"
else
issues="$devCode|issues"
fi
}
get_version() {
get_currentBranchType
if [[ $currentBranchType != "release" ]] && [[ $currentBranchType != "hotfix" ]]; then
printf "must be in the release or hotfix branches to get the version!\n"
exit 1
fi
version=$(echo $currentBranch|awk -F '-' '{print $2}')
devCode=$(echo $currentBranch|awk -F '|' '{print $1}')
haveDevCode=$(echo $currentBranch|awk -F '|' '{print $2}')
if [[ -n "$version" ]];then
if [[ -n "$haveDevCode" ]];then
version="$devCode-$version"
fi
fi
}
get_release() {
get_develop
if [[ -z $devCode ]]; then
release="release"
else
release="$devCode|release"
fi
}
get_hotfix() {
get_master
if [[ -z $devCode ]]; then
hotfix="hotfix"
else
hotfix="$devCode|hotfix"
fi
}
get_currentBranchParent(){
currentBranchParent=`echo $currentBranch|sed 's#\(.*\)%.*#\1#'`
}
get_isParentAlive(){
isParentAlive=$(git rev-parse --symbolic --branches | grep -x "$currentBranchParent")
}
get_currentSHA() {
#currentSHA=`git show|grep ^commit|awk '{print $2}'`
currentSHA=$(git rev-parse HEAD)
}
get_currentTagName() {
#get_currentSHA
#git tag -l > .gg-data-temp1.txt
#git tag -l|awk '{system("git show "$1"|grep ^commit")}'|awk '{print $2}' > .gg-data-temp2.txt
#paste .gg-data-temp1.txt .gg-data-temp2.txt > .gg-data-temp3.txt
#currentTagName=`cat .gg-data-temp3.txt|grep $currentSHA|head -n 1|awk '{print $1}'`
#rm .gg-data-temp*
currentTagName=$(git describe --exact-match --tags)
if [[ -n $(echo $currentTagName | grep "fital:") ]]; then
---currentTagName="None"
fi
}
get_currentTagVersion() {
if [[ -z $currentTagName ]]; then
get_currentTagName
fi
currentTagVersion=$(echo $currentTagName|sed 's#inUse-\(.*\)#\1#')
}
get_now() {
now=`date "+%Y-%m-%d-%H-%M-%S"`
}
testClear() {
if [[ -n "$(git status --untracked-files=no --porcelain)" ]]; then
git status
printf "\n\nwe suggest you make a commit or stash before you do the next thing(Ctrl+c to abort the scripts)\nor you just want to go on doing this?(Press Enter twice for sure)"
read temp
read temp
fi
}
gggttt(){
printf "\t"
}
testUntracked(){
haveUntracked=$(git status --porcelain | grep "^?? ")
if [[ -n "$haveUntracked" ]]; then
git status
printf "\nyou have Untracked files!!\nThe next step will REMOVE all the files here, please make the Untracked files safe!\n\tOr you can use 'git stash' to make a stash and then 'git stash pop'\n"
exit 1
fi
}