Skip to content

Commit d1d1572

Browse files
chooglengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e94bd6 commit d1d1572

File tree

1 file changed

+45
-50
lines changed

1 file changed

+45
-50
lines changed

t/t5526-fetch-submodules.sh

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ write_expected_super () {
4040
# a file that contains the expected err if that new commit were fetched.
4141
# These output files get concatenated in the right order by
4242
# verify_fetch_result().
43-
add_upstream_commit() {
43+
add_submodule_commits () {
4444
(
4545
cd submodule &&
4646
echo new >> subfile &&
@@ -61,6 +61,30 @@ add_upstream_commit() {
6161
)
6262
}
6363

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+
6488
# Verifies that the expected repositories were fetched. This is done by
6589
# concatenating the files expect.err.[super|sub|deep] in the correct
6690
# order and comparing it to the actual stderr.
@@ -117,7 +141,7 @@ test_expect_success setup '
117141
'
118142

119143
test_expect_success "fetch --recurse-submodules recurses into submodules" '
120-
add_upstream_commit &&
144+
add_submodule_commits &&
121145
(
122146
cd downstream &&
123147
git fetch --recurse-submodules >../actual.out 2>../actual.err
@@ -127,7 +151,7 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" '
127151
'
128152

129153
test_expect_success "submodule.recurse option triggers recursive fetch" '
130-
add_upstream_commit &&
154+
add_submodule_commits &&
131155
(
132156
cd downstream &&
133157
git -c submodule.recurse fetch >../actual.out 2>../actual.err
@@ -137,7 +161,7 @@ test_expect_success "submodule.recurse option triggers recursive fetch" '
137161
'
138162

139163
test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
140-
add_upstream_commit &&
164+
add_submodule_commits &&
141165
(
142166
cd downstream &&
143167
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
148172
'
149173

150174
test_expect_success "fetch alone only fetches superproject" '
151-
add_upstream_commit &&
175+
add_submodule_commits &&
152176
(
153177
cd downstream &&
154178
git fetch >../actual.out 2>../actual.err
@@ -177,7 +201,7 @@ test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses i
177201
'
178202

179203
test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
180-
add_upstream_commit &&
204+
add_submodule_commits &&
181205
(
182206
cd downstream &&
183207
git fetch --no-recurse-submodules >../actual.out 2>../actual.err
@@ -226,7 +250,7 @@ test_expect_success "--quiet propagates to parallel submodules" '
226250
'
227251

228252
test_expect_success "--dry-run propagates to submodules" '
229-
add_upstream_commit &&
253+
add_submodule_commits &&
230254
(
231255
cd downstream &&
232256
git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
@@ -245,7 +269,7 @@ test_expect_success "Without --dry-run propagates to submodules" '
245269
'
246270

247271
test_expect_success "recurseSubmodules=true propagates into submodules" '
248-
add_upstream_commit &&
272+
add_submodule_commits &&
249273
(
250274
cd downstream &&
251275
git config fetch.recurseSubmodules true &&
@@ -256,7 +280,7 @@ test_expect_success "recurseSubmodules=true propagates into submodules" '
256280
'
257281

258282
test_expect_success "--recurse-submodules overrides config in submodule" '
259-
add_upstream_commit &&
283+
add_submodule_commits &&
260284
(
261285
cd downstream &&
262286
(
@@ -270,7 +294,7 @@ test_expect_success "--recurse-submodules overrides config in submodule" '
270294
'
271295

272296
test_expect_success "--no-recurse-submodules overrides config setting" '
273-
add_upstream_commit &&
297+
add_submodule_commits &&
274298
(
275299
cd downstream &&
276300
git config fetch.recurseSubmodules true &&
@@ -309,7 +333,7 @@ test_expect_success "Recursion stops when no new submodule commits are fetched"
309333
'
310334

311335
test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
312-
add_upstream_commit &&
336+
add_submodule_commits &&
313337
echo a > file &&
314338
git add file &&
315339
git commit -m "new file" &&
@@ -334,7 +358,7 @@ test_expect_success "Recursion picks up config in submodule" '
334358
git config fetch.recurseSubmodules true
335359
)
336360
) &&
337-
add_upstream_commit &&
361+
add_submodule_commits &&
338362
git add submodule &&
339363
git commit -m "new submodule" &&
340364
new_head=$(git rev-parse --short HEAD) &&
@@ -352,23 +376,8 @@ test_expect_success "Recursion picks up config in submodule" '
352376
'
353377

354378
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 &&
372381
(
373382
cd downstream &&
374383
git fetch >../actual.out 2>../actual.err
@@ -378,19 +387,7 @@ test_expect_success "Recursion picks up all submodules when necessary" '
378387
'
379388

380389
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 &&
394391
(
395392
cd downstream &&
396393
git config fetch.recurseSubmodules true &&
@@ -402,10 +399,8 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne
402399
'
403400

404401
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 &&
409404
(
410405
cd downstream &&
411406
git config fetch.recurseSubmodules false &&
@@ -425,7 +420,7 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess
425420
'
426421

427422
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 &&
429424
echo a >> file &&
430425
git add file &&
431426
git commit -m "new file" &&
@@ -446,7 +441,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
446441
cd downstream &&
447442
git fetch --recurse-submodules
448443
) &&
449-
add_upstream_commit &&
444+
add_submodule_commits &&
450445
git config --global fetch.recurseSubmodules false &&
451446
git add submodule &&
452447
git commit -m "new submodule" &&
@@ -472,7 +467,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override
472467
cd downstream &&
473468
git fetch --recurse-submodules
474469
) &&
475-
add_upstream_commit &&
470+
add_submodule_commits &&
476471
git config fetch.recurseSubmodules false &&
477472
git add submodule &&
478473
git commit -m "new submodule" &&
@@ -522,7 +517,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git
522517
cd downstream &&
523518
git fetch --recurse-submodules
524519
) &&
525-
add_upstream_commit &&
520+
add_submodule_commits &&
526521
git add submodule &&
527522
git rm .gitmodules &&
528523
git commit -m "new submodule without .gitmodules" &&

0 commit comments

Comments
 (0)