-
Notifications
You must be signed in to change notification settings - Fork 464
/
git_update.sh
executable file
·198 lines (168 loc) · 5.02 KB
/
git_update.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
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
#!/bin/bash
CURRENT_BRANCH=""
fWelcome() {
clear
echo "======================================================="
echo " _ _ _ _ _ _____ _ _______ _ _______ "
echo "| || || | | | (_____) | | (_______) | (_______)"
echo "| || || | |__ | | _ \ \ _ | | _____ "
echo "| ||_|| | __)| | | | \ \| | | | | ___) "
echo "| |___| | | | |_| |_ _____) ) |_____| |_____| |_____ "
echo " \______|_| |_(_____|______/ \______)_______)_______)"
echo " - - - Signaling the start of next generation telephony"
echo "======================================================="
printf '%56s' "Current Branch: $CURRENT_BRANCH"
echo
}
fMaintance() {
echo "# git gc"
git gc
}
fStash() {
if [ ! -z "$(git diff-files)" ]; then
echo "# git stash"
git stash || fStashFail
trap "fCleanup $CURRENT_BRANCH TRUE" 0 1 2 5 15
else
trap "fCleanup $CURRENT_BRANCH FALSE" 0 1 2 5 15
fi
}
fStashFail() {
echo "!!! ERROR:LOCAL MODIFICATIONS COULD NOT BE STORED !!!"
echo
echo "No changes have been made to your source code, but we"
echo "could not safely continue. Ensure the source code is"
echo "under GIT control or check the man page for git-stash."
echo
exit 1
}
fFetch() {
echo "# git fetch"
git fetch || fFetchFail
return $?
}
fFetchFail() {
echo
echo " !!! ERROR:COULD NOT RETRIEVE UPDATES !!!"
echo
echo "No updates have been made to your source code, but we"
echo "could not safely continue. Ensure you have a working"
echo "internet connection on this box and you can ping"
echo "source.2600hz.org"
echo
exit 1
}
fCheckout() {
[ "$1" == "`git status | grep 'On branch' | cut -d ' ' -f 4`" ] && return 0
echo "# git checkout $1"
git checkout $1 || fCheckoutFail
return $?
}
fCheckoutFail() {
echo
echo " !!! ERROR:COULD NOT CHECKOUT BRANCH !!!"
echo
echo "The attempt to switch branches has failed, this has"
echo "caused the update processes to stop. Please address"
echo "the error above and try again."
echo
exit 1
}
fMerge() {
echo "# git merge $1"
git merge $1 || fMergeFail
return $?
}
fMergeFail() {
echo
echo " !!! ERROR:COULD NOT MERGE UPDATES !!!"
echo
echo "No updates have been made to your source code, but we"
echo "could not safely continue. Please resolve the git error"
echo "above, use git status to get an idea what might be wrong"
echo
exit 1
}
fSubModule() {
echo "# git submodule sync/init/update"
(git submodule sync && git submodule init && git submodule update ) || fSubModuleFail
return $?
}
fSubModuleFail() {
echo
echo " !!! WARNING:COULD NOT UPDATE SUBMODULES !!!"
echo
echo "Whistle does not directly rely on external libraries to"
echo "operate, but some modules could use them. You should work to"
echo "determine what failed and how you can update it manually."
}
fStashPop() {
echo "# git stash pop"
retString="`git stash pop 2>&1`"
retVal=$?
echo "${retString}"
if [[ "${retString}" == "Nothing to apply" ]]; then
return 0
fi
if [ $retVal != 0 ]; then fStashPopFail; fi
return $retVal
}
fStashPopFail() {
echo
echo " !!! ERROR:COULD NOT RESTORE LOCAL CHANGES !!!"
echo
echo "Applying the state can fail with conflicts; in this case,"
echo "you need to resolve the conflicts by hand and call"
echo "'git stash drop' manually once you are sure you have"
echo "resolved the conflicts."
echo
echo "If there are conflicts with the stashed changes you"
echo "could try running: git checkout stash@{0} {dir_of_file}"
echo
exit 1
}
fGetCurrentBranch() {
CURRENT_BRANCH="`git status | grep 'On branch' | cut -d ' ' -f 4`"
[ -z "$CURRENT_BRANCH" ] && echo "Unable to determine the current git branch, please ensure you are on a local branch before running this command!" && exit 1
}
fMergeAllBranches() {
while read b; do
if r=$(git config --get branch.$b.remote); then
m=$(git config --get branch.$b.merge)
if [ "$b" != "production" -a "$b" != "development" ]; then
fCheckout $b && fMerge $r/${m##*/} #&& fSubModule
fi
fi;
done < <(git for-each-ref --format='%(refname:short)' refs/heads/*)
}
fMergeCurrentBranch() {
b="${CURRENT_BRANCH}"
if r=$(git config --get branch.$b.remote); then
m=$(git config --get branch.$b.merge)
fMerge $r/${m##*/} #&& fSubModule
fi
}
fCleanup() {
if [ "$2" == "TRUE" ]; then
fCheckout $1 && fStashPop
else
fCheckout $1
fi
}
cd `dirname $0`
while [ -n "$*" ]; do
case "x$1" in
x--all)
all_branches="true"
;;
esac
shift
done
fGetCurrentBranch
fWelcome
fMaintance
fStash
fFetch
([ -z "${all_branches}" ] && fMergeCurrentBranch) || fMergeAllBranches
echo "Whistle updated, enjoy!"
exit 0