Subject: Re: [PATCH v3 3/4] refs: make refs/worktree/* per-worktree

From: Michael Haggerty <[email-masked]>
Date: Fri, 14 Aug 2015 10:18:13 +0200

On 08/13/2015 10:32 PM, David Turner wrote:
> On Thu, 2015-08-13 at 22:16 +0200, Michael Haggerty wrote:
>> On 08/13/2015 07:41 PM, David Turner wrote:
>>> On Thu, 2015-08-13 at 13:15 -0400, Eric Sunshine wrote:
>>>> On Wed, Aug 12, 2015 at 5:57 PM, David Turner <[email-masked]> wrote:
>>>>> diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
>>>>> index 93605f4..28e6dff 100755
>>>>> --- a/t/t0060-path-utils.sh
>>>>> +++ b/t/t0060-path-utils.sh
>>>>> +test_expect_success 'handle per-worktree refs in refs/worktree' '
>>>>> +       git commit --allow-empty -m "initial commit" &&
>>>>> +       git worktree add -b branch worktree &&
>>>>> +       (
>>>>> +               cd worktree &&
>>>>> +               git commit --allow-empty -m "test commit"  &&
>>>>> +               git for-each-ref | test_must_fail grep refs/worktree &&
>>>>
>>>> s/test_must_fail/!/
>>>>
>>>> From t/README:
>>>>
>>>>    On the other hand, don't use test_must_fail for running regular
>>>>    platform commands; just use '! cmd'.  We are not in the business
>>>>    of verifying that the world given to us sanely works.
>>>
>>> When I make that change, my test fails with:
>>>
>>> FATAL: Unexpected exit with code 2
>>>
>>> Apparently, you can't use ! in pipelines like that.  So that's why I
>>> used test_must_fail.
>>
>> You would have to negate the whole pipeline, like
>>
>>     ! git for-each-ref | grep refs/worktree
>>
>> The result of a pipeline is taken from the last command.
> 
> Yes, but that would pass if for-each-ref fails, which I do not want.  
> 
> Jacob's suggestion of parentheses around (! grep refs/worktree) seems to
> work.

I don't see how that can help. The result of a pipeline is taken from
the last command. The exit codes of earlier commands in the pipeline are
lost in the sands of time:

    $ false | true
    $ echo $?
    0
    $ false | ( ! false )
    $ echo $?
    0

Working around this POSIX shell limitation is surprisingly awkward in a
general-purpose script. But in this case you could use a temporary file:

    git for-each-ref >refs-actual &&
    ! grep refs/worktree <refs-actual && [...]

Michael

-- 
Michael Haggerty
[email-masked]