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>
This commit is contained in:
Glen Choo 2022-03-07 16:14:26 -08:00 committed by Junio C Hamano
parent 6e94bd64f3
commit d1d1572e75

View File

@ -40,7 +40,7 @@ write_expected_super () {
# a file that contains the expected err if that new commit were fetched. # a file that contains the expected err if that new commit were fetched.
# These output files get concatenated in the right order by # These output files get concatenated in the right order by
# verify_fetch_result(). # verify_fetch_result().
add_upstream_commit() { add_submodule_commits () {
( (
cd submodule && cd submodule &&
echo new >> subfile && echo new >> subfile &&
@ -61,6 +61,30 @@ add_upstream_commit() {
) )
} }
# For each superproject in the test setup, update its submodule, add the
# submodule and create a new commit with the submodule change.
#
# This requires add_submodule_commits() to be called first, otherwise
# the submodules will not have changed and cannot be "git add"-ed.
add_superproject_commits () {
(
cd submodule &&
(
cd subdir/deepsubmodule &&
git fetch &&
git checkout -q FETCH_HEAD
) &&
git add subdir/deepsubmodule &&
git commit -m "new deep submodule"
) &&
git add submodule &&
git commit -m "new submodule" &&
super_head=$(git rev-parse --short HEAD) &&
sub_head=$(git -C submodule rev-parse --short HEAD) &&
write_expected_super $super_head &&
write_expected_sub $sub_head
}
# Verifies that the expected repositories were fetched. This is done by # Verifies that the expected repositories were fetched. This is done by
# concatenating the files expect.err.[super|sub|deep] in the correct # concatenating the files expect.err.[super|sub|deep] in the correct
# order and comparing it to the actual stderr. # order and comparing it to the actual stderr.
@ -117,7 +141,7 @@ test_expect_success setup '
' '
test_expect_success "fetch --recurse-submodules recurses into submodules" ' test_expect_success "fetch --recurse-submodules recurses into submodules" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git fetch --recurse-submodules >../actual.out 2>../actual.err git fetch --recurse-submodules >../actual.out 2>../actual.err
@ -127,7 +151,7 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" '
' '
test_expect_success "submodule.recurse option triggers recursive fetch" ' test_expect_success "submodule.recurse option triggers recursive fetch" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git -c submodule.recurse fetch >../actual.out 2>../actual.err git -c submodule.recurse fetch >../actual.out 2>../actual.err
@ -137,7 +161,7 @@ test_expect_success "submodule.recurse option triggers recursive fetch" '
' '
test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" ' test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err 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
' '
test_expect_success "fetch alone only fetches superproject" ' test_expect_success "fetch alone only fetches superproject" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git fetch >../actual.out 2>../actual.err git fetch >../actual.out 2>../actual.err
@ -177,7 +201,7 @@ test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses i
' '
test_expect_success "--no-recurse-submodules overrides .gitmodules config" ' test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git fetch --no-recurse-submodules >../actual.out 2>../actual.err git fetch --no-recurse-submodules >../actual.out 2>../actual.err
@ -226,7 +250,7 @@ test_expect_success "--quiet propagates to parallel submodules" '
' '
test_expect_success "--dry-run propagates to submodules" ' test_expect_success "--dry-run propagates to submodules" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
@ -245,7 +269,7 @@ test_expect_success "Without --dry-run propagates to submodules" '
' '
test_expect_success "recurseSubmodules=true propagates into submodules" ' test_expect_success "recurseSubmodules=true propagates into submodules" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git config fetch.recurseSubmodules true && git config fetch.recurseSubmodules true &&
@ -256,7 +280,7 @@ test_expect_success "recurseSubmodules=true propagates into submodules" '
' '
test_expect_success "--recurse-submodules overrides config in submodule" ' test_expect_success "--recurse-submodules overrides config in submodule" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
( (
@ -270,7 +294,7 @@ test_expect_success "--recurse-submodules overrides config in submodule" '
' '
test_expect_success "--no-recurse-submodules overrides config setting" ' test_expect_success "--no-recurse-submodules overrides config setting" '
add_upstream_commit && add_submodule_commits &&
( (
cd downstream && cd downstream &&
git config fetch.recurseSubmodules true && git config fetch.recurseSubmodules true &&
@ -309,7 +333,7 @@ test_expect_success "Recursion stops when no new submodule commits are fetched"
' '
test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" ' test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
add_upstream_commit && add_submodule_commits &&
echo a > file && echo a > file &&
git add file && git add file &&
git commit -m "new file" && git commit -m "new file" &&
@ -334,7 +358,7 @@ test_expect_success "Recursion picks up config in submodule" '
git config fetch.recurseSubmodules true git config fetch.recurseSubmodules true
) )
) && ) &&
add_upstream_commit && add_submodule_commits &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
new_head=$(git rev-parse --short HEAD) && new_head=$(git rev-parse --short HEAD) &&
@ -352,23 +376,8 @@ test_expect_success "Recursion picks up config in submodule" '
' '
test_expect_success "Recursion picks up all submodules when necessary" ' test_expect_success "Recursion picks up all submodules when necessary" '
add_upstream_commit && add_submodule_commits &&
( add_superproject_commits &&
cd submodule &&
(
cd subdir/deepsubmodule &&
git fetch &&
git checkout -q FETCH_HEAD
) &&
git add subdir/deepsubmodule &&
git commit -m "new deepsubmodule" &&
new_head=$(git rev-parse --short HEAD) &&
write_expected_sub $new_head
) &&
git add submodule &&
git commit -m "new submodule" &&
new_head=$(git rev-parse --short HEAD) &&
write_expected_super $new_head &&
( (
cd downstream && cd downstream &&
git fetch >../actual.out 2>../actual.err git fetch >../actual.out 2>../actual.err
@ -378,19 +387,7 @@ test_expect_success "Recursion picks up all submodules when necessary" '
' '
test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" ' test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
add_upstream_commit && add_submodule_commits &&
(
cd submodule &&
(
cd subdir/deepsubmodule &&
git fetch &&
git checkout -q FETCH_HEAD
) &&
git add subdir/deepsubmodule &&
git commit -m "new deepsubmodule" &&
new_head=$(git rev-parse --short HEAD) &&
write_expected_sub $new_head
) &&
( (
cd downstream && cd downstream &&
git config fetch.recurseSubmodules true && git config fetch.recurseSubmodules true &&
@ -402,10 +399,8 @@ test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no ne
' '
test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" ' test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
git add submodule && add_submodule_commits &&
git commit -m "new submodule" && add_superproject_commits &&
new_head=$(git rev-parse --short HEAD) &&
write_expected_super $new_head &&
( (
cd downstream && cd downstream &&
git config fetch.recurseSubmodules false && git config fetch.recurseSubmodules false &&
@ -425,7 +420,7 @@ test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necess
' '
test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" ' test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
add_upstream_commit && add_submodule_commits &&
echo a >> file && echo a >> file &&
git add file && git add file &&
git commit -m "new file" && git commit -m "new file" &&
@ -446,7 +441,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config
cd downstream && cd downstream &&
git fetch --recurse-submodules git fetch --recurse-submodules
) && ) &&
add_upstream_commit && add_submodule_commits &&
git config --global fetch.recurseSubmodules false && git config --global fetch.recurseSubmodules false &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
@ -472,7 +467,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override
cd downstream && cd downstream &&
git fetch --recurse-submodules git fetch --recurse-submodules
) && ) &&
add_upstream_commit && add_submodule_commits &&
git config fetch.recurseSubmodules false && git config fetch.recurseSubmodules false &&
git add submodule && git add submodule &&
git commit -m "new submodule" && git commit -m "new submodule" &&
@ -522,7 +517,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git
cd downstream && cd downstream &&
git fetch --recurse-submodules git fetch --recurse-submodules
) && ) &&
add_upstream_commit && add_submodule_commits &&
git add submodule && git add submodule &&
git rm .gitmodules && git rm .gitmodules &&
git commit -m "new submodule without .gitmodules" && git commit -m "new submodule without .gitmodules" &&