Subject: Re: [PATCH v2 1/7] fetch: increase test coverage of fetches

From: Patrick Steinhardt <[email-masked]>
Date: Mon, 21 Feb 2022 08:57:09 +0100

On Thu, Feb 17, 2022 at 04:18:07PM +0100, Christian Couder wrote:
> On Thu, Feb 17, 2022 at 2:04 PM Patrick Steinhardt <[email-masked]> wrote:
> 
> > +test_expect_success 'atomic fetch with failing backfill' '
> > +       git init clone3 &&
> > +
> > +       # We want to test whether a failure when backfilling tags correctly
> > +       # aborts the complete transaction when `--atomic` is passed: we should
> > +       # neither create the branch nor should we create the tag when either
> > +       # one of both fails to update correctly.
> > +       #
> > +       # To trigger failure we simply abort when backfilling a tag.
> > +       write_script clone3/.git/hooks/reference-transaction <<-\EOF &&
> > +               while read oldrev newrev reference
> > +               do
> > +                       if test "$reference" = refs/tags/tag1
> > +                       then
> > +                               exit 1
> > +                       fi
> 
> Maybe the following could save a few lines:
> 
>                        test "$reference" = refs/tags/tag1 && exit 1
> 
> It would make the code look a bit different than in another hook
> script written below though, so not a big deal.

If `$reference` does not match the tag we want to continue and
eventually return successfully from this hook. But:

    $ while read foo; do test "$foo" = bar && echo match; done < <(echo bar)
    match
    $ while read foo; do test "$foo" = bar && echo match; done < <(echo foo)
    $ echo $?
    1

So with the proposed change we'd now exit the hook with an error code
instead of returning successfully.

Patrick