t5526: create superproject commits with test helper
A few tests in t5526 use this pattern as part of their setup: 1. Create new commits in the upstream submodules (using add_upstream_commit()). 2. In the upstream superprojects, add the new submodule commits from the previous step. A future commit will add more tests with this pattern, so reduce the verbosity of present and future tests by introducing a test helper that creates superproject commits. Since we now have two helpers that add upstream commits, rename add_upstream_commit() to add_submodule_commits(). Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Mar 7, 2022 at 16:14 UTC
d1d1572e75edfa901fd6ab836402f57ba2da27b4
1 file changed
+45
-50
t/t5526-fetch-submodules.sh
+45
-50
@@ -40,7 +40,7 @@ write_expected_super () {
40
# a file that contains the expected err if that new commit were fetched.
41
# These output files get concatenated in the right order by
42
# verify_fetch_result().
43
-add_upstream_commit() {
43
+add_submodule_commits () {
44
(
45
cd submodule &&
46
echo new >> subfile &&
@@ -61,6 +61,30 @@ add_upstream_commit() {
61
)
62
}
63
64
+# For each superproject in the test setup, update its submodule, add the
65
+# submodule and create a new commit with the submodule change.
66
+#
67
+# This requires add_submodule_commits() to be called first, otherwise
68
+# the submodules will not have changed and cannot be "git add"-ed.
69
+add_superproject_commits () {
70
+ (
71
+ cd submodule &&
72
+ (
73
+ cd subdir/deepsubmodule &&
74
+ git fetch &&
75
+ git checkout -q FETCH_HEAD
76
+ ) &&
77
+ git add subdir/deepsubmodule &&
78
+ git commit -m "new deep submodule"
79
+ ) &&
80
+ git add submodule &&
81
+ git commit -m "new submodule" &&
82
+ super_head=$(git rev-parse --short HEAD) &&
83
+ sub_head=$(git -C submodule rev-parse --short HEAD) &&
84
+ write_expected_super $super_head &&
85
+ write_expected_sub $sub_head
86
+}
87
+
88
# Verifies that the expected repositories were fetched. This is done by
89
# concatenating the files expect.err.[super|sub|deep] in the correct
90
# order and comparing it to the actual stderr.
@@ -117,7 +141,7 @@ test_expect_success setup '
141
'
142
143
test_expect_success "fetch --recurse-submodules recurses into submodules" '
120
- add_upstream_commit &&
144
+ add_submodule_commits &&
145
(
146
cd downstream &&
147
git fetch --recurse-submodules >../actual.out 2>../actual.err
@@ -127,7 +151,7 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" '
151
'
152
153
test_expect_success "submodule.recurse option triggers recursive fetch" '
130
- add_upstream_commit &&
154
+ add_submodule_commits &&
155
(
156
cd downstream &&
157
git -c submodule.recurse fetch >../actual.out 2>../actual.err
@@ -137,7 +161,7 @@ test_expect_success "submodule.recurse option triggers recursive fetch" '
161
'
162
163
test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
140
- add_upstream_commit &&
164
+ add_submodule_commits &&
165
(
166
cd downstream &&
167
GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err
@@ -148,7 +172,7 @@ test_expect_success "fetch --recurse-submodules -j2 has the same output behaviou
172
'
173
174
test_expect_success "fetch alone only fetches superproject" '
151
- add_upstream_commit &&
175
+ add_submodule_commits &&
176
(
177
cd downstream &&
178
git fetch >../actual.out 2>../actual.err
@@ -177,7 +201,7 @@ test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses i
201
'
202
203
test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
180
- add_upstream_commit &&
204
+ add_submodule_commits &&
205
(
206
cd downstream &&
207
git fetch --no-recurse-submodules >../actual.out 2>../actual.err
@@ -226,7 +250,7 @@ test_expect_success "--quiet propagates to parallel submodules" '
250
'
251
252
test_expect_success "--dry-run propagates to submodules" '
229
- add_upstream_commit &&
253
+ add_submodule_commits &&
254
(
255
cd downstream &&
256
git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
@@ -245,7 +269,7 @@ test_expect_success "Without --dry-run propagates to submodules" '
269
'
270
271
test_expect_success "recurseSubmodules=true propagates into submodules" '
248
- add_upstream_commit &&
272
+ add_submodule_commits &&
273
(
274
cd downstream &&
275
git config fetch.recurseSubmodules true &&
@@ -256,7 +280,7 @@ test_expect_success "recurseSubmodules=true propagates into submodules" '
280
'
281
282
test_expect_success "--recurse-submodules overrides config in submodule" '
259
- add_upstream_commit &&
283
+ add_submodule_commits &&
284
(
285
cd downstream &&
286
(
@@ -270,7 +294,7 @@ test_expect_success "--recurse-submodules overrides config in submodule" '
294
'
295
296
test_expect_success "--no-recurse-submodules overrides config setting" '
273
- add_upstream_commit &&
297
+ add_submodule_commits &&
298
(
299
cd downstream &&
300
git config fetch.recurseSubmodules true &&
@@ -309,7 +333,7 @@ test_expect_success "Recursion stops when no new submodule commits are fetched"
333
'
334
335
test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
312
- add_upstream_commit &&
336
+ add_submodule_commits &&
337
echo a > file &&
338
git add file &&
339
git commit -m "new file" &&
@@ -334,7 +358,7 @@ test_expect_success "Recursion picks up config in submodule" '
358
git config fetch.recurseSubmodules true
359
)
360
) &&
337
- add_upstream_commit &&
361
+ add_submodule_commits &&
362
git add submodule &&
363
git commit -m "new submodule" &&
364
new_head=$(git rev-parse --short HEAD) &&
@@ -352,23 +376,8 @@ test_expect_success "Recursion picks up config in submodule" '
376
'
377
378
test_expect_success "Recursion picks up all submodules when necessary" '
355
- add_upstream_commit &&
356
- (
357
- cd submodule &&
358
- (
359
- cd subdir/deepsubmodule &&
360
- git fetch &&
361
- git checkout -q FETCH_HEAD
362
- ) &&
363
- git add subdir/deepsubmodule &&
364
- git commit -m "new deepsubmodule" &&
365
- new_head=$(git rev-parse --short HEAD) &&
366
- write_expected_sub $new_head
367
- ) &&
368
- git add submodule &&
369
- git commit -m "new submodule" &&
370
- new_head=$(git rev-parse --short HEAD) &&
371
- write_expected_super $new_head &&
379
+ add_submodule_commits &&
380
+ add_superproject_commits &&
381
(
382
cd downstream &&
383
git fetch >../actual.out 2>../actual.err
@@ -378,19 +387,7 @@ test_expect_success "Recursion picks up all submodules when necessary" '
387
'
388
389
test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
381
- add_upstream_commit &&
382
- (
383
- cd submodule &&
384
- (
385
- cd subdir/deepsubmodule &&
386
- git fetch &&
387
- git checkout -q FETCH_HEAD
388
- ) &&
389
- git add subdir/deepsubmodule &&
390
- git commit -m "new deepsubmodule" &&
391
- new_head=$(git rev-parse --short HEAD) &&
392
- write_expected_sub $new_head
393
- ) &&
390
+ add_submodule_commits &&
391
(
392
cd downstream &&
393
git config fetch.recurseSubmodules true &&
@@ -402,10 +399,8 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne
399
'
400
401
test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
405
- git add submodule &&
406
- git commit -m "new submodule" &&
407
- new_head=$(git rev-parse --short HEAD) &&
408
- write_expected_super $new_head &&
402
+ add_submodule_commits &&
403
+ add_superproject_commits &&
404
(
405
cd downstream &&
406
git config fetch.recurseSubmodules false &&
@@ -425,7 +420,7 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess
420
'
421
422
test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
428
- add_upstream_commit &&
423
+ add_submodule_commits &&
424
echo a >> file &&
425
git add file &&
426
git commit -m "new file" &&
@@ -446,7 +441,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
441
cd downstream &&
442
git fetch --recurse-submodules
443
) &&
449
- add_upstream_commit &&
444
+ add_submodule_commits &&
445
git config --global fetch.recurseSubmodules false &&
446
git add submodule &&
447
git commit -m "new submodule" &&
@@ -472,7 +467,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override
467
cd downstream &&
468
git fetch --recurse-submodules
469
) &&
475
- add_upstream_commit &&
470
+ add_submodule_commits &&
471
git config fetch.recurseSubmodules false &&
472
git add submodule &&
473
git commit -m "new submodule" &&
@@ -522,7 +517,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git
517
cd downstream &&
518
git fetch --recurse-submodules
519
) &&
525
- add_upstream_commit &&
520
+ add_submodule_commits &&
521
git add submodule &&
522
git rm .gitmodules &&
523
git commit -m "new submodule without .gitmodules" &&