Message ID | 20220224100842.95827-4-chooglen@google.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | fetch --recurse-submodules: fetch unpopulated submodules | expand |
Glen Choo <chooglen@google.com> writes: > +# 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" > + ) && The indentation looks off. Also, no need for "-q". > @@ -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)" ' > - add_upstream_commit && > - ( > - 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) && > - check_sub $new_head > - ) && > + add_submodule_commits && > ( > cd downstream && > git config fetch.recurseSubmodules true && Hmm...I'm surprised that this still passes even when code is deleted but the replacement is not added. What's happening here, I guess, is that we're checking that nothing has happened. The test probably should be rewritten but that's outside the scope of this patch set. So for now, just add the add_superproject_commits call. > @@ -402,10 +399,7 @@ 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)" ' > - git add submodule && > - git commit -m "new submodule" && > - new_head=$(git rev-parse --short HEAD) && > - check_super $new_head && > + add_superproject_commits && > ( > cd downstream && > git config fetch.recurseSubmodules false && add_superproject_commits without add_submodule_commits? The rest looks good and overall this looks like a good idea to simplify the test.
Jonathan Tan <jonathantanmy@google.com> writes: > Glen Choo <chooglen@google.com> writes: >> +# 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" >> + ) && > > The indentation looks off. Also, no need for "-q". Ah thanks. I think the "-q" is there to suppress the detached HEAD warning, which is very large. I'd prefer to keep it unless there are stronger reasons than "it's not needed for correctness". >> @@ -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)" ' >> - add_upstream_commit && >> - ( >> - 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) && >> - check_sub $new_head >> - ) && >> + add_submodule_commits && >> ( >> cd downstream && >> git config fetch.recurseSubmodules true && > > Hmm...I'm surprised that this still passes even when code is deleted but > the replacement is not added. What's happening here, I guess, is that > we're checking that nothing has happened. The test probably should be > rewritten but that's outside the scope of this patch set. So for now, > just add the add_superproject_commits call. Yeah this test could use some fixing up; I spent a lot of time trying to understand this one. It could use comments at least. The suggestion to add the add_superproject_commits call defeats the purpose of the test though - which is to assert that "on-demand" recursion only fetches submodule commits if a superproject commit says the submodule has changed, unlike "yes", which unconditionally fetches submodule commits. So we need to consider these cases: 1. no new upstream commits 2. new upstream submodule commits, but not superproject (call add_submodule_commits() only) 3. new upstream submodule and superproject commits (call add_submodule_commits() and add_superproject_commits()) (1): "on-demand" and "yes" both fetch nothing (2): "yes" fetches submodule commits but "on-demand" doesn't (3): "on-demand" and "yes" both fetch submodule and superproject commits So this test can't call add_superproject_commits(), because we would no longer be testing scenario (2) - we'd be 'testing' (3) instead (which doesn't tell us how "on-demand" is different from "yes"). >> @@ -402,10 +399,7 @@ 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)" ' >> - git add submodule && >> - git commit -m "new submodule" && >> - new_head=$(git rev-parse --short HEAD) && >> - check_super $new_head && >> + add_superproject_commits && >> ( >> cd downstream && >> git config fetch.recurseSubmodules false && > > add_superproject_commits without add_submodule_commits? This is a silly holdover from before my rewrite.. These lines: - git add submodule && - git commit -m "new submodule" && - new_head=$(git rev-parse --short HEAD) && don't make any sense either until you realize that these commits were set up in the _previous_ test. I should clean this up though, there's no reason for others to have to struggle with this the way I did. The easiest approach would be to add the add_submodule_commits() call, with a comment explaining that it's technically unnecessary work (because the previous test already calls add_submodule_commits()) but it makes the test easier to read.
On Fri, Feb 25 2022, Glen Choo wrote: > Jonathan Tan <jonathantanmy@google.com> writes: > >> Glen Choo <chooglen@google.com> writes: >>> +# 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" >>> + ) && >> >> The indentation looks off. Also, no need for "-q". > > Ah thanks. I think the "-q" is there to suppress the detached HEAD > warning, which is very large. > > I'd prefer to keep it unless there are stronger reasons than "it's not > needed for correctness". FWIW I was going to comment on the -q, but didn't because you're just moving this around. I think even for large warnings it's fine to omit -q etc, since that's what --verbose (as in the test-lib.sh argument) is for. But in this case it's probably better to leave it as-is.
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > On Fri, Feb 25 2022, Glen Choo wrote: > >> Jonathan Tan <jonathantanmy@google.com> writes: >> >>> Glen Choo <chooglen@google.com> writes: >>>> +# 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" >>>> + ) && >>> >>> The indentation looks off. Also, no need for "-q". >> >> Ah thanks. I think the "-q" is there to suppress the detached HEAD >> warning, which is very large. >> >> I'd prefer to keep it unless there are stronger reasons than "it's not >> needed for correctness". > > FWIW I was going to comment on the -q, but didn't because you're just > moving this around. > > I think even for large warnings it's fine to omit -q etc, since that's > what --verbose (as in the test-lib.sh argument) is for. Ah interesting, I didn't consider that. Thanks! > But in this case it's probably better to leave it as-is. I'm also leaning towards this because I'm just moving things around, but I could be convinced otherwise.
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index a3890e2f6c..ee4dd5a4a9 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -43,7 +43,7 @@ check_super() { # a file that contains the expected err if that new commit were fetched. # These output files get concatenated in the right order by # verify_fetch_result(). -add_upstream_commit() { +add_submodule_commits() { ( cd submodule && echo new >> subfile && @@ -64,6 +64,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) && + check_super $super_head && + check_sub $sub_head +} + # Verifies that the expected repositories were fetched. This is done by # concatenating the files expect.err.[super|sub|deep] in the correct # 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && ( @@ -270,7 +294,7 @@ test_expect_success "--recurse-submodules overrides config in submodule" ' ' test_expect_success "--no-recurse-submodules overrides config setting" ' - add_upstream_commit && + add_submodule_commits && ( cd downstream && 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" ' - add_upstream_commit && + add_submodule_commits && echo a > file && git add file && git commit -m "new file" && @@ -334,7 +358,7 @@ test_expect_success "Recursion picks up config in submodule" ' git config fetch.recurseSubmodules true ) ) && - add_upstream_commit && + add_submodule_commits && git add submodule && git commit -m "new submodule" && 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" ' - add_upstream_commit && - ( - 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) && - check_sub $new_head - ) && - git add submodule && - git commit -m "new submodule" && - new_head=$(git rev-parse --short HEAD) && - check_super $new_head && + add_submodule_commits && + add_superproject_commits && ( cd downstream && 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)" ' - add_upstream_commit && - ( - 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) && - check_sub $new_head - ) && + add_submodule_commits && ( cd downstream && git config fetch.recurseSubmodules true && @@ -402,10 +399,7 @@ 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)" ' - git add submodule && - git commit -m "new submodule" && - new_head=$(git rev-parse --short HEAD) && - check_super $new_head && + add_superproject_commits && ( cd downstream && git config fetch.recurseSubmodules false && @@ -425,7 +419,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)" ' - add_upstream_commit && + add_submodule_commits && echo a >> file && git add file && git commit -m "new file" && @@ -446,7 +440,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config cd downstream && git fetch --recurse-submodules ) && - add_upstream_commit && + add_submodule_commits && git config --global fetch.recurseSubmodules false && git add submodule && git commit -m "new submodule" && @@ -472,7 +466,7 @@ test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' override cd downstream && git fetch --recurse-submodules ) && - add_upstream_commit && + add_submodule_commits && git config fetch.recurseSubmodules false && git add submodule && git commit -m "new submodule" && @@ -522,7 +516,7 @@ test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .git cd downstream && git fetch --recurse-submodules ) && - add_upstream_commit && + add_submodule_commits && git add submodule && git rm .gitmodules && git commit -m "new submodule without .gitmodules" &&
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> --- t/t5526-fetch-submodules.sh | 94 +++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 50 deletions(-)