# [PATCH] t4015: let the test pass with any default branch name

4 messages from 2020-11-18 to 2020-11-18. Participants: Johannes Schindelin via GitGitGadget, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/54671

## Johannes Schindelin via GitGitGadget, 2020-11-18 19:26

Subject: [PATCH] t4015: let the test pass with any default branch name
Message-ID: <pull.794.git.1605727594021.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.794.git.1605727594021.gitgitgadget%40gmail.com

```
From: Johannes Schindelin <johannes.schindelin@gmx.de>

We do not need to hard-code the actual branch name, as we have access to
the reflog and can be a lot more precise at what we want.

Strangely enough, this test case would have succeeded even with an
overridden default branch name, obviously for the wrong reason. Let's
verify that it passes for the expected reason, by looking for a
tell-tale in Git's output.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    t4015: let the test pass with any default branch name
    
    Aaaaand another issue, also found while working on 
    https://github.com/gitgitgadget/git/pull/762.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-794%2Fdscho%2Ft4015-and-default-branch-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-794/dscho/t4015-and-default-branch-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/794

 t/t4015-diff-whitespace.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 8bdaa0a693..c9dd62b70e 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -883,7 +883,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
 	echo >x goodbye &&
 	git commit -m "the other side" x &&
 	git config core.autocrlf true &&
-	test_must_fail git merge master &&
+	test_must_fail git merge @{2} >actual &&
+	test_i18ngrep "Automatic merge failed" actual &&
 
 	git diff >actual.raw &&
 	sed -e "1,/^@@@/d" actual.raw >actual &&

base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500
-- 
gitgitgadget

```

## Junio C Hamano, 2020-11-18 20:20

Subject: Re: [PATCH] t4015: let the test pass with any default branch name
Message-ID: <xmqqd00a1knr.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqd00a1knr.fsf%40gitster.c.googlers.com
In-Reply-To: <pull.794.git.1605727594021.gitgitgadget@gmail.com>

```
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> We do not need to hard-code the actual branch name, as we have access to
> the reflog and can be a lot more precise at what we want.

I am not enthused to see us going beyond "@{1}" or "@{-1}".  It
would make the test a bit too brittle as a future changes need to
refrain from creating another commit and/or switching to a third
branch to do some more set-up before coming here to attempt an
merge.  

In this particular case, "git merge @{-1}" may be more robust from
that point of view

Thanks.

>  t/t4015-diff-whitespace.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
> index 8bdaa0a693..c9dd62b70e 100755
> --- a/t/t4015-diff-whitespace.sh
> +++ b/t/t4015-diff-whitespace.sh
> @@ -883,7 +883,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
>  	echo >x goodbye &&
>  	git commit -m "the other side" x &&
>  	git config core.autocrlf true &&
> -	test_must_fail git merge master &&
> +	test_must_fail git merge @{2} >actual &&
> +	test_i18ngrep "Automatic merge failed" actual &&
>  
>  	git diff >actual.raw &&
>  	sed -e "1,/^@@@/d" actual.raw >actual &&
>
> base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500

```

## Johannes Schindelin, 2020-11-18 23:13

Subject: Re: [PATCH] t4015: let the test pass with any default branch name
Message-ID: <nycvar.QRO.7.76.6.2011190011340.56@tvgsbejvaqbjf.bet>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.2011190011340.56%40tvgsbejvaqbjf.bet
In-Reply-To: <xmqqd00a1knr.fsf@gitster.c.googlers.com>

```
Hi Junio,

On Wed, 18 Nov 2020, Junio C Hamano wrote:

> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> >
> > We do not need to hard-code the actual branch name, as we have access to
> > the reflog and can be a lot more precise at what we want.
>
> I am not enthused to see us going beyond "@{1}" or "@{-1}".

Right. It also makes it a bit harder to understand the test case for the
occasional reader.

> It would make the test a bit too brittle as a future changes need to
> refrain from creating another commit and/or switching to a third branch
> to do some more set-up before coming here to attempt an merge.
>
> In this particular case, "git merge @{-1}" may be more robust from
> that point of view

It might be _slightly_ more robust, but not by a lot. I opted to use
`test_commit` instead and then refer to the revision via the tag that is
created by that function.

Ciao,
Dscho

> > diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
> > index 8bdaa0a693..c9dd62b70e 100755
> > --- a/t/t4015-diff-whitespace.sh
> > +++ b/t/t4015-diff-whitespace.sh
> > @@ -883,7 +883,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
> >  	echo >x goodbye &&
> >  	git commit -m "the other side" x &&
> >  	git config core.autocrlf true &&
> > -	test_must_fail git merge master &&
> > +	test_must_fail git merge @{2} >actual &&
> > +	test_i18ngrep "Automatic merge failed" actual &&
> >
> >  	git diff >actual.raw &&
> >  	sed -e "1,/^@@@/d" actual.raw >actual &&
> >
> > base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500
>
>

```

## Johannes Schindelin via GitGitGadget, 2020-11-18 23:35

Subject: [PATCH v2] t4015: let the test pass with any default branch name
Message-ID: <pull.794.v2.git.1605742544801.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.794.v2.git.1605742544801.gitgitgadget%40gmail.com
In-Reply-To: <pull.794.git.1605727594021.gitgitgadget@gmail.com>

```
From: Johannes Schindelin <johannes.schindelin@gmx.de>

We do not need to hard-code the actual branch name, as we can use the
`test_commit` function to simplify the code and use the tag it
generates, thereby being a lot more precise in what we want.

Strangely enough, this test case would have succeeded even with an
overridden default branch name, obviously for the wrong reason. Let's
verify that it passes for the expected reason, by looking for a
tell-tale in Git's output.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    t4015: let the test pass with any default branch name
    
    Aaaaand another issue, also found while working on 
    https://github.com/gitgitgadget/git/pull/762.
    
    Changes since v1:
    
     * We now use test_commit and the tag it creates, rather than the
       reflog.
     *

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-794%2Fdscho%2Ft4015-and-default-branch-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-794/dscho/t4015-and-default-branch-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/794

Range-diff vs v1:

 1:  5467cae0dd ! 1:  2f6d07fe90 t4015: let the test pass with any default branch name
     @@ Metadata
       ## Commit message ##
          t4015: let the test pass with any default branch name
      
     -    We do not need to hard-code the actual branch name, as we have access to
     -    the reflog and can be a lot more precise at what we want.
     +    We do not need to hard-code the actual branch name, as we can use the
     +    `test_commit` function to simplify the code and use the tag it
     +    generates, thereby being a lot more precise in what we want.
      
          Strangely enough, this test case would have succeeded even with an
          overridden default branch name, obviously for the wrong reason. Let's
     @@ Commit message
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
       ## t/t4015-diff-whitespace.sh ##
     -@@ t/t4015-diff-whitespace.sh: test_expect_success 'combined diff with autocrlf conversion' '
     +@@ t/t4015-diff-whitespace.sh: test_expect_success 'rename empty' '
     + test_expect_success 'combined diff with autocrlf conversion' '
     + 
     + 	git reset --hard &&
     +-	echo >x hello &&
     +-	git commit -m "one side" x &&
     ++	test_commit "one side" x hello one-side &&
     + 	git checkout HEAD^ &&
       	echo >x goodbye &&
       	git commit -m "the other side" x &&
       	git config core.autocrlf true &&
      -	test_must_fail git merge master &&
     -+	test_must_fail git merge @{2} >actual &&
     ++	test_must_fail git merge one-side >actual &&
      +	test_i18ngrep "Automatic merge failed" actual &&
       
       	git diff >actual.raw &&


 t/t4015-diff-whitespace.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 8bdaa0a693..47f0e2889d 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -877,13 +877,13 @@ test_expect_success 'rename empty' '
 test_expect_success 'combined diff with autocrlf conversion' '
 
 	git reset --hard &&
-	echo >x hello &&
-	git commit -m "one side" x &&
+	test_commit "one side" x hello one-side &&
 	git checkout HEAD^ &&
 	echo >x goodbye &&
 	git commit -m "the other side" x &&
 	git config core.autocrlf true &&
-	test_must_fail git merge master &&
+	test_must_fail git merge one-side >actual &&
+	test_i18ngrep "Automatic merge failed" actual &&
 
 	git diff >actual.raw &&
 	sed -e "1,/^@@@/d" actual.raw >actual &&

base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500
-- 
gitgitgadget

```
