-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupSub.sh
270 lines (256 loc) · 5.31 KB
/
groupSub.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
function print(){
echo ">>>current in $PWD"
}
#place your remote address here
Server=(
"wendi@192.168.1.101:/home/wendi/test/server1/.git"
"wendi@192.168.1.101:/home/wendi/test/server2/.git"
"wendi@192.168.1.101:/home/wendi/test/server3/"
)
out_path=$PWD
#place your repo_name here
repo_name="myproj"
cd $repo_name
repo_path=$PWD
if [[ $1 = 'init' ]]; then
mkdir "Server"
for server in ${Server[@]}; do
cd $out_path
#make bare repository
temp=$(echo $(basename ${server%/*}))
mkdir "dircp"
mkdir dircp/$temp
cd dircp/$temp
subdir_path=Server/$temp
git init --bare
#split subtree and push to remote
cd $repo_path
git subtree split --prefix=$subdir_path -b split
git push ../$temp split:master
git remote add origin $server
git push origin master
cd $repo_path
git rm -r $subdir_path
git commit -am "Remove split code."
git remote add $temp $server
git subtree add --prefix=$subdir_path --squash $temp master
done
#doing first commit
git add .
git commit -m "refreshing...and do commit"
git push origin master
cd ../
elif [[ $1 = 'push' ]]; then
git add --all
git commit -m "all push"
if [[ $2 = 'subrepo' ]]; then
# push and update subrepo
for server in ${Server[@]}; do
temp=$(echo $(basename ${server%/*}))
subdir_path=Server/$temp
git subtree push --prefix=$subdir_path --squash $temp master
done
else
# push ifself!
git push origin master
fi
cd ../
echo "push done!"
elif [[ $1 = 'pull' ]]; then
if [[ $2 = 'subrepo' ]];then
# pull from sub repos
for server in ${Server[@]}; do
temp=$(echo $(basename ${server%/*}))
subdir_path=Server/$temp
git subtree pull --prefix=$subdir_path --squash $temp master
done
else
#pull itself
git pull
fi
cd ../
echo "all pull done!"
elif [[ $1 = 'checkout' ]]; then
if [[ $2 == -* ]]; then
case $2 in
-b)
git checkout -b $3
;;
-f)
git checkout -f $3
;;
-m)
git checkout -m $3
;;
esac
else
git checkout $2
fi
cd ../
elif [[ $1 = 'status' ]]; then
if [[ $2 = '-s' ]]; then
git status -s
else
git status
fi
cd ../
elif [[ $1 = 'diff' ]]; then
if [[ "$3" != "" ]]; then
git diff $2 $3
else
case $2 in
--cached)
git diff --cached
;;
HEAD)
git diff HEAD
;;
esac
fi
cd ../
elif [[ $1 = 'reset' ]]; then
git log
# $3 represent commit id
if [[ $2 == 'HEAD' ]]; then
git reset HEAD
elif [[ $2 == 'soft' ]]; then
git reset --soft $3
elif [[ $2 == 'hard' ]]; then
git reset --hard $3
fi
cd ../
elif [[ $1 = 'clone' ]]; then
# $2 represent remote repository address
git clone $2
cd ../
elif [[ $1 = 'commit' ]]; then
# $2 is option and $3 is commit message
case $2 in
-a)
git commit -a
;;
--amend)
git commit --amend
;;
-m)
git commit -m $3
;;
esac
cd ../
elif [[ $1 = 'branch' ]]; then
if [[ !$2 == -* ]]; then
# create a new branch but do not switch to it.
git branch $2
echo "create branch " $2
elif [[ $2 == -* ]]; then
case $2 in
-r)
git branch -r
;;
-a)
git branch -a
;;
-d)
# branch name that you want to delete
git branch -d $3
;;
-D)
git branch -D $3
;;
-vv)
git branch -vv
;;
-m)
# old branch name rename to new branch name
git branch -m $3 $4
;;
esac
else
git branch
fi
cd ../
elif [[ $1 = 'merge' ]]; then
# $2 represemt branch 1 name that you want to merge
branch=$2
options=$3
if [ "$branch" != "" ];then
if [ "$options" != "" ]; then
case $options in
--abort)
git merge $branch --abort
;;
--commit|-nocommit)
if [[ $options == '--commit' ]];then
git merge $branch --commit
else
git merge $branch --no-commit
fi
;;
-e|--edit|--no-edit)
if [[ $options == '--edit'||'-e' ]];then
git merge $branch --edit
else
git merge $branch --no-edit
fi
;;
-squash|--no-squash)
if [[ $options == '--squash' ]];then
git merge $branch --squash
else
git merge $branch --no-squash
fi
;;
esac
else
echo "Please offer option"
fi
else
echo "Please enter the branch you want to merge!"
fi
cd ../
elif [[ $1 = 'stash' ]]; then
if [[ $2 != "" ]] ;then
case $2 in
pop|apply)
if [[ $2 == "pop" ]] ;then
git stash pop
else
# $3 represent stash here
git stash apply $3
fi
;;
list)
git stash list
;;
clear)
git stash clear
;;
save)
# $3 represent message
git stash save $3
;;
esac
else
git stash
fi
cd ../
elif [[ $1 = "show" ]]; then
git show
cd ../
elif [[ $1 = "--help" ]]; then
echo " init init repository using given series of repositories' address"
echo " push push repository to remote or push changes to remote sub repos"
echo " pull pull changes from remote or pull changes from remote sub repos"
echo " checkout basic implementation of git checkout"
echo " status basic implementation of git status"
echo " diff basic implementation of git diff"
echo " reset basic implementation of git reset"
echo " clone basic implementation of git clone"
echo " commit basic implementation of git commit"
echo " merge basic implementation of git merge"
echo " branch basic implementation of git branch"
echo " stash basic implementation of git stash"
echo " show basic implementation of git show"
cd ../
fi