git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH v3 2/2] t7406: add test for non-default branch in submodule

From
Stefan Beller <sbeller@google.com>
Date
Apr 4, 2018, 18:36 UTC
Message-ID
<CAGZ79kYu-9vzee=R7uE4fhhrRj19ZT0Z5+7fPLwOpXhEr7aqUw@mail.gmail.com>
In-Reply-To
<CAK0XTWf=ubDK-4=FknLSFObZrShg=7UDgR5c6iNSjrwiDngayA@mail.gmail.com>
On Tue, Apr 3, 2018 at 3:26 PM, Eddy Petrișor <eddy.petrisor@gmail.com> wrote:
Show 5 quoted lines
> Notes:
>     I am aware this test is not probably the best one and maybe I
> should have first one test that does a one level non-default, before
> trying a test with 2 levels of submodules, but I wanted to express the
> goal of the patch.

This patch only contains the test, I presume this goes on top of https://public-inbox.org/git/20180403222053.23132-1-eddy.petrisor@codeaurora.org/ which you plan to later submit as one patch including both the change as well as the test.

Show 25 quoted lines
>     Currently the test fails, so I am obviously missing something.
> Help would be appreciated.
>
>
> 2018-04-04 1:20 GMT+03:00 Eddy Petrișor <eddy.petrisor@codeaurora.org>:
>> From: Eddy Petrișor <eddy.petrisor@gmail.com>
>>
>> If a submodule uses a non-default branch and the branch info is versioned, on
>> submodule update --recursive --init the correct branch should be checked out.
>>
>> Signed-off-by: Eddy Petrișor <eddy.petrisor@gmail.com>
>> ---
>>  t/t7406-submodule-update.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 54 insertions(+)
>>
>> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
>> index 6f083c4d6..7b65f1dd1 100755
>> --- a/t/t7406-submodule-update.sh
>> +++ b/t/t7406-submodule-update.sh
>> @@ -259,6 +259,60 @@ test_expect_success 'submodule update --remote should fetch upstream changes wit
>>         )
>>  '
>>
>> +test_expect_success 'submodule update --remote --recursive --init should fetch module branch from .gitmodules' '
>> +       git clone . super5 &&

I found adding "test_pause &&" to be a great helper as it will drop you in a shell where you can inspect the repository.

>> +       git clone super5 submodl2b2 &&
>> +       git clone super5 submodl1b1 &&
We may want to cleanup after the test is done:
  test_when_finished "rm submodl2b2" &&
  test_when_finished "rm submodl1b2" &&
>> +       cd submodl2b2 &&
I'd think the test suite prefers subshells to operate in other dirs
instead of direct cd's, just like at the end of the test.
For short parts, we make heavy use of the -C option,
So for example the code below
       (
               cd super &&
               git submodule update --recursive --init
       ) &&
can be written as
    git -C super submodule update --recursive --init
which is shorter.
>> +       echo linel2b2 > l2b2 &&
style: The Git test suite prefers to have the redirect adjacent to the
file name:
  echo hello >world
Show 5 quoted lines
>> +       git checkout -b b2 &&
>> +       git add l2b2 &&
>> +       test_tick &&
>> +       git commit -m "commit on b2 branch in l2" &&
>> +       git rev-parse --verify HEAD >../expectl2 &&

So until now we made a commit in a submodule on branch b2 and wrote it out to an expect file.

Show 7 quoted lines
>> +       git checkout master &&
>> +       cd ../submodl1b1 &&
>> +       git checkout -b b1 &&
>> +       echo linel1b1 > l1b1 &&
>> +       git add l1b1 &&
>> +       test_tick &&
>> +       git commit -m "commit on b1 branch in l1" &&
very similar to above, just in another repo
instead of making a commit yourself, you may want to use
    test_commit <name>
then you don't need to call echo/add/commit yourself.
Show 5 quoted lines
>> +       git submodule add ../submodl2b2 submodl2b2 &&
>> +       git config -f .gitmodules submodule."submodl2b2".branch b2 &&
>> +       git add .gitmodules &&
>> +       test_tick &&
>> +       git commit -m "add l2 module with branch b2 in l1 module in branch b1" &&

So one submodule is made to be a submodule of the other with a specific branch (b2)

>> +       git submodule init submodl2b2 &&

git submodule add ought to have initialized that submodule already, I am not sure we need the explicit init here.

>> +       git rev-parse --verify HEAD >../expectl1 &&
>> +       git checkout master &&
We go back to master, which doesn't have the nested submodule?
Show 10 quoted lines
>> +       cd ../super5 &&
>> +       echo super_with_2_chained_modules > super5 &&
>> +       git add super5 &&
>> +       test_tick &&
>> +       git commit -m "commit on default branch in super5" &&
>> +       git submodule add ../submodl1b1 submodl1b1 &&
>> +       git config -f .gitmodules submodule."submodl1b1".branch b1 &&
>> +       git add .gitmodules &&
>> +       test_tick &&
>> +       git commit -m "add l1 module with branch b1 in super5" &&

now we do this again without the nested submodule, just one repo as a submodule?

>> +       git submodule init submodl1b1 &&
>> +       git clone super5 super &&

does super exist here already? (I did not check, but IIRC super and super{1-4} are there as we count upwards to find a name that is ok.

Show 14 quoted lines
>> +       (
>> +               cd super &&
>> +               git submodule update --recursive --init
>> +       ) &&
>> +       (
>> +               cd submodl1b1 &&
>> +               git rev-parse --verify HEAD >../../actuall1 &&
>> +               test_cmp ../../expectl1 ../../actuall1
>> +       ) &&
>> +       (
>> +               cd submodl2b2 &&
>> +               git rev-parse --verify HEAD >../../../actuall2 &&
>> +               test_cmp ../../../expectl2 ../../../actuall2
>> +       )
Stefan
Previous: Eddy PetrișorNext: Eddy Petrișor
Message 14 of 29 in “Re: [RFC PATCH] git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of default”
  1. Jonathan NiederMar 6, 2018
  2. Eddy PetrișorMar 8, 2018
  3. Eddy PetrișorMar 8, 2018
  4. Thomas GummererMar 16, 2018
  5. Eric SunshineMar 16, 2018
  6. Thomas GummererMar 17, 2018
  7. Eric SunshineMar 18, 2018
  8. Stefan BellerMar 26, 2018
  9. Fwd: [RFC PATCH] git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of defaultEddy Petrișor, Mar 29, 2018
  10. Eddy PetrișorMar 29, 2018
  11. 1/2 git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of defaultEddy Petrișor, Apr 3, 2018
  12. 2/2 t7406: add test for non-default branch in submoduleEddy Petrișor, Apr 3, 2018
  13. Eddy PetrișorApr 3, 2018
  14. Stefan BellerApr 4, 2018
  15. Eddy PetrișorApr 4, 2018
  16. Stefan BellerApr 4, 2018
  17. 1/9 git-submodule.sh:cmd_update: if submodule branch exists, fetch that instead of defaultEddy Petrișor, Apr 18, 2018
  18. 2/9 t7406: add test for non-default branch in submoduleEddy Petrișor, Apr 18, 2018
  19. 3/9 fixup:t7406: use test_commit instead of echo/add/commit as suggested by Stefan BellerEddy Petrișor, Apr 18, 2018
  20. 5/9 fixup:t7406:cleanup chained submodules after test is doneEddy Petrișor, Apr 18, 2018
  21. 4/9 fixup:t7404:use 'git -C' instead of cd .. && gitEddy Petrișor, Apr 18, 2018
  22. 6/9 fixup:t7406:don't call init after add, is redundantEddy Petrișor, Apr 18, 2018
  23. 7/9 fixup:t7406:supr5 commit is done before submodules chainingEddy Petrișor, Apr 18, 2018
  24. 9/9 fixup:t7406:change branches in submodules after the link is doneEddy Petrișor, Apr 18, 2018
  25. 8/9 fixup:t7406:use super_w instead of the existing superEddy Petrișor, Apr 18, 2018
  26. Stefan BellerApr 18, 2018
  27. Eddy PetrișorApr 19, 2018
  28. Eddy PetrișorApr 19, 2018
  29. Stefan BellerApr 19, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.