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

Re: [PATCH 4/4] t5509: add basic tests for hideRefs

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 2, 2015, 07:30 UTC
Message-ID
<CAPig+cSv1x50ZoXLRAW55v7H6K5828GhvkeptuHd-Jsr+u74qA@mail.gmail.com>
In-Reply-To
<20151102062449.24971.39537@typhoon>
On Mon, Nov 2, 2015 at 1:25 AM, Lukas Fleischer <lfleischer@lfos.de> wrote:
Show 38 quoted lines
> On Sun, 01 Nov 2015 at 22:13:51, Eric Sunshine wrote:
>> On Sun, Nov 1, 2015 at 2:34 PM, Lukas Fleischer <lfleischer@lfos.de> wrote:
>> > +       cd pushee &&
>> > +       test_config transfer.hideRefs refs/tags &&
>> > +       GIT_NAMESPACE=namespace git ls-remote "ext::git %s ." >actual &&
>> > +       printf "$commit1    refs/heads/master\n" >expected &&
>> > +       test_cmp expected actual &&
>> > +       cd ..
>>
>> If any of the commands above "cd .." fail, then "cd .." will never be
>> invoked, thus subsequent tests will fail since they won't be executed
>> in the expected directory. The typical way to handle this is to place
>> the "cd foo" and remaining test body in a subshell, and drop "cd .."
>> altogether. When the subshell exits (via success or failure), the
>> working directory will be restored automatically.
>>
>>     test_expect_success '...' '
>>         (
>>             cd pushee &&
>>             test_config ... &&
>>             ...
>>         )
>>     '
>> [...]
>
> I chose the `cd ..` approach because test_config does not work from a
> subshell. However, searching the Git log for "test_config", I found
> 1a9a23e (t7610: don't use test_config in a subshell, 2015-09-05) and
> da568b6 (t7800: don't use test_config in a subshell, 2015-09-05) which
> suggest to use the -C switch. The test cases now look like this:
>
>     test_expect_success '[...]' '
>         test_config -C pushee transfer.hideRefs [...] &&
>         (
>             cd pushee &&
>             [...]
>         )
>     '

Yes, that can work, although for these simple cases, it might be more straightforward to use the git -c option to set the config variable just for the duration of the one git command. For instance:

test_expect_success 'hide namespaced refs with transfer.hideRefs' '
    (
        cd pushee &&
        GIT_NAMESPACE=namespace \
            git -c transfer.hideRefs=refs/tags \
            ls-remote "ext::git %s ." >actual &&
        printf "$commit1\trefs/heads/master\n" >expected &&
        test_cmp expected actual &&
    )
'

In fact, these test are so simple, that you don't really need the 'cd' at all. You could just use -C (along with -c):

test_expect_success 'hide namespaced refs with transfer.hideRefs' '
    GIT_NAMESPACE=namespace \
        git -C pushee -c transfer.hideRefs=refs/tags \
        ls-remote "ext::git %s ." >actual &&
    printf "$commit1\trefs/heads/master\n" >expected &&
    test_cmp expected actual &&
'
Previous: Lukas Fleischer
Message 10 of 10 in “Improve hideRefs when used with namespaces”
  1. 0/4 Improve hideRefs when used with namespacesLukas Fleischer, Nov 1, 2015
  2. 1/4 Document the semantics of hideRefs with namespacesLukas Fleischer, Nov 1, 2015
  3. 2/4 upload-pack: strip refs before calling ref_is_hidden()Lukas Fleischer, Nov 1, 2015
  4. 3/4 Add support for matching full refs in hideRefsLukas Fleischer, Nov 1, 2015
  5. Eric SunshineNov 1, 2015
  6. Lukas FleischerNov 2, 2015
  7. 4/4 t5509: add basic tests for hideRefsLukas Fleischer, Nov 1, 2015
  8. Eric SunshineNov 1, 2015
  9. Lukas FleischerNov 2, 2015
  10. Eric SunshineNov 2, 2015

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.