forked from kollerma/git-submodule-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·524 lines (475 loc) · 13.8 KB
/
tests.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#!/bin/bash
####
## config
####
## set current directory as working directory
wd=`pwd`/test
if test -d $wd
then
rm -rf $wd
fi
mkdir -p $wd
####
## setup
####
## stop on error
set -e
## switch to working dir
cd "$wd"
## create master (bare) clones for submodules
mkdir remote
git clone --bare http://github.com/kollerma/r-tutorial.git remote/r-tutorial.git
git clone --bare http://github.com/kollerma/aufgabe1.git remote/aufgabe1.git
git clone --bare http://github.com/kollerma/aufgabe2.git remote/aufgabe2.git
git clone --bare http://github.com/kollerma/aufgabe3.git remote/aufgabe3.git
## clone aufgabe2
git rclone remote/aufgabe2.git
## create super repositories
## serie x: 1-2
for i in 1 2; do
mkdir serie$i
cd serie$i
git init
touch series$i.tex
touch solution$i.tex
git add series$i.tex solution$i.tex
git submodule add $wd/remote/aufgabe$i.git aufgabe1
j=`expr $i + 1`
git submodule add $wd/remote/aufgabe$j.git aufgabe2
git commit -m 'first commit'
cd ..
git clone --bare serie$i remote/serie$i.git
cd serie$i
git remote add origin $wd/remote/serie$i.git
## to create tracking branches
git push -u --all
cd ..
done
## vorlesung
mkdir vorlesung
(cd vorlesung
git init
touch README
git add README
git submodule add $wd/remote/serie1.git serie1
git submodule add $wd/remote/serie2.git serie2
git submodule add $wd/remote/r-tutorial.git r-tutorial
git commit -m 'first commit'
) || exit 1
git clone --bare vorlesung remote/vorlesung.git
(cd vorlesung
git remote add origin $wd/remote/vorlesung.git
git tag state-0
git push --tag
) || exit 1
## clone vorlesung.git to vorlesung and vorlesung2
rm -rf vorlesung
git rclone $wd/remote/vorlesung.git vorlesung
git rclone $wd/remote/vorlesung.git vorlesung2
git rclone $wd/remote/vorlesung.git vorlesung3
####
## start tests
####
## get some work done in vorlesung2
(cd vorlesung2
(cd r-tutorial
echo "some random content" >> tutorial.Rnw
) || exit 1
(cd serie1/aufgabe1
echo "try to do it today" >> ex.Rnw
) || exit 1
## edit aufgabe2 but do commit
(cd serie1/aufgabe2
echo "try again" >> ex.Rnw
git add ex.Rnw
git commit -m 'This is no problem'
) || exit 1
## rcommit without -a should warn of unstaged changes now
git rcommit -m "I did something"
## ok, then add files that are already tracked
git rcommit -am "I did something"
## Now push this
git rpush
## Add a tag as well
git tag state-1
git push --tag
) || exit 1
## pull this in vorlesung
(cd vorlesung
git rpull
## This should report that there are updates available
## for serie2/aufgabe1 which points to the same rep. as
## serie1/aufgabe2.
) || exit 1
## clone vorlesung to vorlesung4
git rclone $wd/remote/vorlesung.git vorlesung4
## there is a detached head. do nothing...
####
## how to fix diverged branches
####
## now work in vorlesung3 without pulling first
## to force some conflicts
(cd vorlesung3
## rfetch --dry-run should report updates but not fetch them
git rfetch --dry-run
## force a conflict
(cd r-tutorial
echo "some more content" >> tutorial.Rnw
) || exit 1
(cd serie2/aufgabe1
echo "we work against each other" >> ex.Rnw
) || exit 1
## try to pull now, should fail
git rpull && exit 1 || echo "rpull failed, as required."
## try to push, should fail, since there are new commits
git rpush && exit 1 || echo "rpush failed, as required"
## commit
git rcommit -am "some message"
## now there's a conflict, try to push again
git rpush && exit 1 || echo "rpush failed, as required."
## so try a pull as the message says
## and this should also report the differences
git rpull && exit 1 || echo "rpull failed, as required."
## the way to go is to use rfetch
git rfetch
## rpull and rpush should still fail
git rpull && exit 1 || echo "rpull failed, as required."
git rpush && exit 1 || echo "rpush failed, as required."
## do git rdiff to find differences
git rdiff
## merge all differences
(cd r-tutorial
git pull && exit 1 || echo "corrected version" > tutorial.Rnw
) || exit 1
## This can be fast forwarded
(cd serie1/aufgabe1
git pull
) || exit 1
## This can be fast forwarded
(cd serie1/aufgabe2
git pull
) || exit 1
(cd serie2/aufgabe1
git pull && exit 1 || cat ex.Rnw | sed -e '7 d' -e '5 d' -e '3 d' > ex.Rnw
) || exit 1
## Now git rdiff should not show any changes
git rdiff
## ok, commit then
git rcommit -am 'merged remote'
## and push
git rpush
## add an untracked file
touch serie1/aufgabe2/blah.Rnw
## try to push, should not fail, since there only untracked files
## but there should be a warning.
git rpush || { echo "rpush failed, this shouldn't happen!!"; exit 1; }
## remove the file again
rm serie1/aufgabe2/blah.Rnw
) || exit 1
## Now pull this in vorlesung
(cd vorlesung
git rpull
## show differences
git rdiff
## update serie1/aufgabe2
(cd serie1/aufgabe2
git pull
) || exit 1
## commit and push this
git rcommit -am 'updated serie1/aufgabe2'
git rpush
) || exit 1
####
## try tag switching and removing submodules
###
## Now pull this in vorlesung2
(cd vorlesung2
git rpull
## show differences
git rdiff
## add tag and push it
git tag state-2
git push --tag
## list tags
git tag
## checkout
git rcheckout state-1
git rcheckout state-0
## try to do stuff
(cd r-tutorial
echo "testing..." >> tutorial.Rnw
) || exit 1
git rcommit -am 'testing stuff' && exit 1 || echo "rcommit failed as it should have"
git rcheckout state-1 && exit 1 || echo "rcheckout failed as it should have"
## revert
(cd r-tutorial
git reset --hard HEAD
) || exit 1
git rcheckout state-2
## remove some submodules and switch tags
(cd serie2
## try to remove dirty submodule
echo "test" > aufgabe2/hallo
git rm-submodule aufgabe2 && exit 1 || echo "rm-submodule failed as it should have"
## try non tracking branch
(cd aufgabe2
git checkout -b testbranch
git add hallo
git commit -m 'catch this!'
git checkout master
) || exit 1
git rm-submodule aufgabe2 && exit 1 || echo "rm-submodule caught non-tracking-branch"
## so merge it to master and push
(cd aufgabe2
git merge testbranch
git push
) || exit 1
## now it should work
git rm-submodule aufgabe2 || { echo "rm-submodule failed!"; exit 1; }
) || exit 1
## have to commit this in super repository by hand
git rcommit -am 'removed submodule serie2/aufgabe2'
## revert to state-2
git rcheckout state-2
[ -f serie2/aufgabe2/ex.Rnw ] || { echo "Error: serie2/aufgabe2 not restored"; exit 1; }
## revert to newest state
git rcheckout master
[ ! -f serie2/aufgabe2/ex.Rnw ] || { echo "Error: serie2/aufgabe2 not removed"; exit 1; }
## now push this
git rpush
) || exit 1
####
## cause conflict -- stage2:
## when submodules with local new commits were removed in remote
####
(cd vorlesung3
## check for updates, but ignore them
git rfetch --dry-run
(cd serie2/aufgabe2
## there are already unpulled changes...
git pull
) || exit 1
## should open an editor
## git rcommit -a
git rcommit -am "playing with fire!!"
## now get updates
git rpull && exit 1 || echo "This fails as it should"
git rpush && exit 1 || echo "This pushes the second level, but then fails"
## get updates
git rfetch --dry-run
git rfetch
git rdiff
) || exit 1
## make backup first
cp -r vorlesung3 vorlesung3a
## continue...
(cd vorlesung3
## update serie2
(cd serie2
git converge-submodules
[ ! -f aufgabe2/ex.Rnw ] || { echo "Error: serie2/aufgabe2 not removed"; exit 1; }
) || exit 1
git rcommit -am 'updated serie1 and serie2'
git rpush
## add tag and push
git tag state-3
git push --tags
) || exit 1
## now try this again in vorlesung3a
## (slightly different scenario for converge-submodules)
cp -r vorlesung3a vorlesung3b
(cd vorlesung3a
(cd serie2
git converge-submodules
[ ! -f aufgabe2/ex.Rnw ] || { echo "Error: serie2/aufgabe2 not removed"; exit 1; }
) || exit 1
## now commit
git rcommit -am 'updated serie1 and serie2'
) || exit 1
####
## cause conflict -- stage3: when submodules have been locally added
####
(cd vorlesung2
## removed serie2/aufgabe2 earlier
## now add another aufgabe2 and try to push
## check for updates, but ignore this
git rfetch --dry-run
(cd serie2
git submodule add $wd/remote/aufgabe1.git aufgabe2
git commit -m 'added aufgabe1.git as aufgabe2'
) || exit 1
git rcommit -am 'did some work in serie2'
git rpush && exit 1 || echo "Ok, there was an error in serie2"
## ok, check for updates
git rfetch
## so try the usual solution:
(cd serie2
git converge-submodules
## ok, force it
## this essentially forces the submodule add we just made
git converge-submodules -f
) || exit 1
git rcommit -am 'resolved conflict in serie2'
## don't push, want to go even further...
) || exit 1
####
## cause conflict -- stage4: when submodules will be removed in remote
## but others already added in the same place
####
(cd vorlesung
## removed serie2/aufgabe2 earlier
## now add another aufgabe2 and try to push
## check for updates, but ignore this
git rfetch --dry-run
(cd serie2
git rm-submodule aufgabe2
git submodule add $wd/remote/aufgabe1.git aufgabe2
git commit -m 'added aufgabe1.git as aufgabe2'
) || exit 1
git rcommit -am 'did some work in serie2'
git rpush && exit 1 || echo "Ok, there was an error in serie2"
## ok, check for updates
git rfetch
## so try the usual solution:
(cd serie2
git converge-submodules
## this will remove the submodule we just added
## but give the info we need to add it again.
## do so
git submodule add $wd/remote/aufgabe1.git aufgabe2
) || exit 1
git rcommit -am 'resolved conflict in serie2'
git rpush
) || exit 1
####
## cause conflict -- stage 5: when submodules have been added twice
## in different versions
####
(cd vorlesung3
## add aufgabe1.git as aufgabe2 again, aufgabe3.git as aufgabe3
## check for updates, but ignore them
git rfetch --dry-run
(cd serie2
git submodule add $wd/remote/aufgabe1.git aufgabe2
git submodule add $wd/remote/aufgabe3.git aufgabe3
git commit -m 'added aufgabe1.git as aufgabe2, aufgabe3.git as aufgabe3'
) || exit 1
git rcommit -am 'added some submodules in serie2'
) || exit 1
cp -r vorlesung3 vorlesung3c
(cd vorlesung3
## fetch updates
git rfetch
(cd serie2
git converge-submodules
) || exit 1
git rcommit -am 'converged submodules'
git rpush
) || exit 1
####
## test submodule version conflict resolution
####
(cd vorlesung
git rpull
## switch branch in serie2/aufgabe1
(cd serie2/aufgabe1
git branch alternative origin/alternative
git checkout alternative
) || exit 1
git rcommit -am 'switched branch in serie2/aufgabe1'
) || exit 1
(cd vorlesung3
## revert to an old commit in serie2/aufgabe1
(cd serie2/aufgabe1
git reset --hard HEAD~1
) || exit 1
git rcommit -am 'reset version in serie2/aufgabe1'
git rpush
) || exit 1
(cd vorlesung
## fetch updates
git rfetch
(cd serie2
git converge-submodules
## fails
) || exit 1
git rcommit -am 'merged serie2'
git rpush
) || exit 1
(cd vorlesung3
## pull
git rpull
) || exit 1
####
## test mv-submodule
####
(cd vorlesung
## mv serie2 to serie3
git mv-submodule serie1 serie2 && exit 1 || echo "Ok series2 exists already"
git mv-submodule serie2 serie3
[ ! -d serie2 ] || { echo "Error: serie2 not removed"; exit 1; }
[ -d serie3 ] || { echo "Error: serie3 not created"; exit 1; }
## move it back
git mv-submodule serie3 serie2
[ ! -d serie3 ] || { echo "Error: serie3 not removed"; exit 1; }
[ -d serie2 ] || { echo "Error: serie2 not created"; exit 1; }
) || exit 1
####
## test removal and adding of a submodule of the same name
####
## create a set of new submodules to be used
## in the subsequent tests
(cd remote
## clone aufgabe1 into aufgabe4
git clone --bare aufgabe1.git aufgabe4.git
) || exit 1
## add some commits to aufgabe1
git clone remote/aufgabe1.git aufgabe1
(cd aufgabe1
echo more-content >> ex.Rnw
git commit -am "first time adding more content to aufgabe1"
echo even-more-content >> ex.Rnw
git commit -am "second time adding more content to aufgabe1"
git push
) || exit 1
## add some commits to aufgabe2
git clone remote/aufgabe4.git aufgabe4
(cd aufgabe4
echo more-content2 >> ex.Rnw
git commit -am "first time adding more content to aufgabe4"
echo even-more-content2 >> ex.Rnw
git commit -am "second time adding more content to aufgabe4"
git push
) || exit 1
## create new repos vorlesung5 and vorlesung6
git rclone remote/vorlesung.git vorlesung5
git rclone remote/vorlesung.git vorlesung6
## update to newest version aufgabe1 in vorlesung5
(cd vorlesung5
git rpull
(cd serie1/aufgabe1
git checkout master
) || exit 1
git rcommit -am "updated series1/aufgabe1"
## the next push should be ok
## (even if HEAD in serie2/aufgabe2 is not attached)
git rpush
) || exit 1
## update to newest version aufgabe1 in vorlesung6
(cd vorlesung6
git rpull
(cd serie1
git rm-submodule aufgabe1
git submodule add $wd/remote/aufgabe4.git aufgabe1
) || exit 1
git rcommit -am "added aufgabe4.git as aufgabe1"
git rpush
) || exit 1
## go to vorlesung5 and pull again
(cd vorlesung5
git rpull
## the head of serie1/aufgabe1 should be attached now
(cd serie1/aufgabe1
git branch -v -a
) || exit 1
) || exit 1