Subject: Re: [PATCH] t2024: fix loose/strict local base branch DWIM test

From: Junio C Hamano <[email-masked]>
Date: Mon, 10 Apr 2023 10:37:10 -0700

Andrei Rybak <[email-masked]> writes:

>> 3. t2024-checkout-dwim.sh
>> Test 'loosely defined local base branch is reported correctly' in t2024
>> has an interesting validation of output of "git checkout":
>> 
>>      git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect &&
>>      status_uno_is_clean &&
>>      git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual &&
>>      status_uno_is_clean &&
>> 
>>      test_cmp expect actual
>> 
>> which is fine, except that neither file "expect" nor "actual" contain
>> the string "BRANCHNAME".  And this test was broken when it was
>> introduced in 05e73682cd (checkout: report upstream correctly even with
>> loosely defined branch.*.merge, 2014-10-14).  It was probably intended
>> for this test to redirect standard error of "git checkout".  It should
>> be cleaned up as a separate patch/topic.
>
> Here's the patch.  Alternatively, the fix could be to just drop the sed
> invocation from this test.

Or we could check both stdout and stderr separately.  I think the
change in this patch reflects the intention of the original most
closely, so let's queue it as-is.

Thanks.

>
>  t/t2024-checkout-dwim.sh | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh
> index 4a1c901456..74049a9812 100755
> --- a/t/t2024-checkout-dwim.sh
> +++ b/t/t2024-checkout-dwim.sh
> @@ -305,10 +305,13 @@ test_expect_success 'loosely defined local base branch is reported correctly' '
>  	test_config branch.strict.merge refs/heads/main &&
>  	test_config branch.loose.merge main &&
>  
> -	git checkout strict | sed -e "s/strict/BRANCHNAME/g" >expect &&
> +	git checkout strict >expect.raw 2>&1 &&
> +	sed -e "s/strict/BRANCHNAME/g" <expect.raw >expect &&
>  	status_uno_is_clean &&
> -	git checkout loose | sed -e "s/loose/BRANCHNAME/g" >actual &&
> +	git checkout loose >actual.raw 2>&1 &&
> +	sed -e "s/loose/BRANCHNAME/g" <actual.raw >actual &&
>  	status_uno_is_clean &&
> +	grep BRANCHNAME actual &&
>  
>  	test_cmp expect actual
>  '