-
Notifications
You must be signed in to change notification settings - Fork 6
/
repo.sh
executable file
·211 lines (197 loc) · 3.54 KB
/
repo.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
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
#!/bin/bash
showAllHelp(){
echo 'usage: git [-help] [-branch] [-status] [-push] [-pull] [-diff] [foreach <command>] [sync]'
echo '-----------------------------------------------------------------------------------------'
echo "git-based commands, easy to use"
printf " %-20s %-10s \n" '-branch:' 'show the current branch of all submodules.'
printf " %-20s %-10s \n" '-status:' 'show git status of all submodules.'
printf " %-20s %-10s \n" '-pull:' 'pull and rebase the latest code of all submodules.'
printf " %-20s %-10s \n" '-diff:' 'show local changes for all submodules.'
echo ""
echo "use custom command of all submodules"
printf " %-20s %-10s \n" 'foreach <command>:' 'execute the specified command of all submodules.'
echo ""
echo "source and publish command"
printf " %-20s %-10s \n" 'sync' 'sync all submodules to specified devbranch.'
echo "for more help, please see: https://github.com/Ryan-Shz/Repo"
}
if [ $# -eq 0 ];
then
showAllHelp
exit 1
fi
args=$1
execCmd=${@:2}
subArgs=$2
argsList=$@
currPath=""
refreshCurrPath(){
if [ "$(uname)"=="Darwin" ]
then
currPath=$(pwd)
else
currPath=$(dirname $(readlink -f $0))
fi
}
printBranch(){
cd submodules
refreshCurrPath
path=$currPath
files=$(ls $path)
for fileName in $files
do
if [ ! -d $fileName ]
then
continue
fi
cd $fileName
branch=$(git rev-parse --abbrev-ref HEAD)
echo $fileName': '$branch
cd ..
done
}
printAllStatus(){
cd submodules
refreshCurrPath
path=$currPath
files=$(ls $path)
for fileName in $files
do
if [ ! -d $fileName ]
then
continue
fi
cd $fileName
echo -e "\033[33mEntering $fileName\033[0m"
git status
cd ..
done
}
printAllDiff(){
cd submodules
refreshCurrPath
path=$currPath
files=$(ls $path)
for fileName in $files
do
if [ ! -d $fileName ]
then
continue
fi
cd $fileName
echo -e "\033[33mEntering $fileName\033[0m"
git diff
cd ..
done
}
mergeAll(){
cd submodules
refreshCurrPath
path=$currPath
files=$currPath
for fileName in $files
do
if [ ! -d $fileName ]
then
continue
fi
cd $fileName
echo -e "\033[33mEntering $fileName\033[0m"
git pull --rebase
cd ..
done
}
pullRebase(){
cd submodules
refreshCurrPath
path=$currPath
files=$(ls $path)
for fileName in $files
do
if [ ! -d $fileName ]
then
continue
fi
cd $fileName
echo -e "\033[33mEntering $fileName\033[0m"
git pull --rebase
cd ..
done
}
foreach(){
if [ ! -d "submodules" ]
then
return
fi
cd submodules
refreshCurrPath
path=$currPath
files=$(ls $path)
for fileName in $files
do
if [ ! -d $fileName ]
then
continue
fi
cd $fileName
echo -e "\033[33mEntering $fileName\033[0m"
$execCmd
cd ..
done
}
syncModules(){
chmod +x ./gradlew
if [ '-c' = $subArgs ]
then
./gradlew -Psync=true -PnoBuild=true -PdevBranch=false cmd
else
./gradlew -Psync=true -PnoBuild=true -PdevBranch=true cmd
fi
}
args_contains () {
seeking=$1
inArray=$argsList
for element in $inArray
do
if [ $element == $seeking ];
then
return 1
fi
done
return 0
}
string_contains(){
seeking=$1
inString=$2
result=$(echo $inString | grep "${seeking}")
if [[ "$result" != "" ]]
then
return 1
fi
return 0
}
case $args in
"-help") showAllHelp
;;
"-h") showAllHelp
;;
"-branch") printBranch
;;
"foreach") foreach
;;
"-pull") pullRebase
;;
"-status") printAllStatus
;;
"-diff") printAllDiff
;;
"-merge") mergeAll
;;
"sync") syncModules
;;
*)
echo "submodules: '$args' is not a submodules command. See ./submodules.sh -help."
exit 1
;;
esac