@@ -40,7 +40,7 @@ write_expected_super () {
40
40
# a file that contains the expected err if that new commit were fetched.
41
41
# These output files get concatenated in the right order by
42
42
# verify_fetch_result().
43
- add_upstream_commit () {
43
+ add_submodule_commits () {
44
44
(
45
45
cd submodule &&
46
46
echo new >> subfile &&
@@ -61,6 +61,30 @@ add_upstream_commit() {
61
61
)
62
62
}
63
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
+
64
88
# Verifies that the expected repositories were fetched. This is done by
65
89
# concatenating the files expect.err.[super|sub|deep] in the correct
66
90
# order and comparing it to the actual stderr.
@@ -117,7 +141,7 @@ test_expect_success setup '
117
141
'
118
142
119
143
test_expect_success " fetch --recurse-submodules recurses into submodules" '
120
- add_upstream_commit &&
144
+ add_submodule_commits &&
121
145
(
122
146
cd downstream &&
123
147
git fetch --recurse-submodules >../actual.out 2>../actual.err
@@ -127,7 +151,7 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" '
127
151
'
128
152
129
153
test_expect_success " submodule.recurse option triggers recursive fetch" '
130
- add_upstream_commit &&
154
+ add_submodule_commits &&
131
155
(
132
156
cd downstream &&
133
157
git -c submodule.recurse fetch >../actual.out 2>../actual.err
@@ -137,7 +161,7 @@ test_expect_success "submodule.recurse option triggers recursive fetch" '
137
161
'
138
162
139
163
test_expect_success " fetch --recurse-submodules -j2 has the same output behaviour" '
140
- add_upstream_commit &&
164
+ add_submodule_commits &&
141
165
(
142
166
cd downstream &&
143
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
148
172
'
149
173
150
174
test_expect_success " fetch alone only fetches superproject" '
151
- add_upstream_commit &&
175
+ add_submodule_commits &&
152
176
(
153
177
cd downstream &&
154
178
git fetch >../actual.out 2>../actual.err
@@ -177,7 +201,7 @@ test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses i
177
201
'
178
202
179
203
test_expect_success " --no-recurse-submodules overrides .gitmodules config" '
180
- add_upstream_commit &&
204
+ add_submodule_commits &&
181
205
(
182
206
cd downstream &&
183
207
git fetch --no-recurse-submodules >../actual.out 2>../actual.err
@@ -226,7 +250,7 @@ test_expect_success "--quiet propagates to parallel submodules" '
226
250
'
227
251
228
252
test_expect_success " --dry-run propagates to submodules" '
229
- add_upstream_commit &&
253
+ add_submodule_commits &&
230
254
(
231
255
cd downstream &&
232
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" '
245
269
'
246
270
247
271
test_expect_success " recurseSubmodules=true propagates into submodules" '
248
- add_upstream_commit &&
272
+ add_submodule_commits &&
249
273
(
250
274
cd downstream &&
251
275
git config fetch.recurseSubmodules true &&
@@ -256,7 +280,7 @@ test_expect_success "recurseSubmodules=true propagates into submodules" '
256
280
'
257
281
258
282
test_expect_success " --recurse-submodules overrides config in submodule" '
259
- add_upstream_commit &&
283
+ add_submodule_commits &&
260
284
(
261
285
cd downstream &&
262
286
(
@@ -270,7 +294,7 @@ test_expect_success "--recurse-submodules overrides config in submodule" '
270
294
'
271
295
272
296
test_expect_success " --no-recurse-submodules overrides config setting" '
273
- add_upstream_commit &&
297
+ add_submodule_commits &&
274
298
(
275
299
cd downstream &&
276
300
git config fetch.recurseSubmodules true &&
@@ -309,7 +333,7 @@ test_expect_success "Recursion stops when no new submodule commits are fetched"
309
333
'
310
334
311
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 &&
313
337
echo a > file &&
314
338
git add file &&
315
339
git commit -m "new file" &&
@@ -334,7 +358,7 @@ test_expect_success "Recursion picks up config in submodule" '
334
358
git config fetch.recurseSubmodules true
335
359
)
336
360
) &&
337
- add_upstream_commit &&
361
+ add_submodule_commits &&
338
362
git add submodule &&
339
363
git commit -m "new submodule" &&
340
364
new_head=$(git rev-parse --short HEAD) &&
@@ -352,23 +376,8 @@ test_expect_success "Recursion picks up config in submodule" '
352
376
'
353
377
354
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 &&
372
381
(
373
382
cd downstream &&
374
383
git fetch >../actual.out 2>../actual.err
@@ -378,19 +387,7 @@ test_expect_success "Recursion picks up all submodules when necessary" '
378
387
'
379
388
380
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 &&
394
391
(
395
392
cd downstream &&
396
393
git config fetch.recurseSubmodules true &&
@@ -402,10 +399,8 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne
402
399
'
403
400
404
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 &&
409
404
(
410
405
cd downstream &&
411
406
git config fetch.recurseSubmodules false &&
@@ -425,7 +420,7 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess
425
420
'
426
421
427
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 &&
429
424
echo a >> file &&
430
425
git add file &&
431
426
git commit -m "new file" &&
@@ -446,7 +441,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
446
441
cd downstream &&
447
442
git fetch --recurse-submodules
448
443
) &&
449
- add_upstream_commit &&
444
+ add_submodule_commits &&
450
445
git config --global fetch.recurseSubmodules false &&
451
446
git add submodule &&
452
447
git commit -m "new submodule" &&
@@ -472,7 +467,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override
472
467
cd downstream &&
473
468
git fetch --recurse-submodules
474
469
) &&
475
- add_upstream_commit &&
470
+ add_submodule_commits &&
476
471
git config fetch.recurseSubmodules false &&
477
472
git add submodule &&
478
473
git commit -m "new submodule" &&
@@ -522,7 +517,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git
522
517
cd downstream &&
523
518
git fetch --recurse-submodules
524
519
) &&
525
- add_upstream_commit &&
520
+ add_submodule_commits &&
526
521
git add submodule &&
527
522
git rm .gitmodules &&
528
523
git commit -m "new submodule without .gitmodules" &&
0 commit comments