# [PATCH] t3200: add test for single parameter passed to -m option

6 messages from 2017-06-05 to 2017-06-13. Participants: Sahil Dua, Junio C Hamano.
Thread: https://gitlist.dev/t/46123

## Sahil Dua, 2017-06-05 22:38

Subject: [PATCH] t3200: add test for single parameter passed to -m option
Message-ID: <0102015c7a68c647-372a5a13-5412-4838-921d-66980bac4099-000000@eu-west-1.amazonses.com>
URL: https://gitlist.dev/e/0102015c7a68c647-372a5a13-5412-4838-921d-66980bac4099-000000%40eu-west-1.amazonses.com

```
Adds a test for the case when only one parameter is passed to '-m'
(move/rename) option.

For example - if 'git branch -m bbb' is run, it should rename the
currently checked out branch to bbb. There was no test for this
particular case with only one parameter for -m option. However,
there's one similar test case for -M option.

Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
---
 t/t3200-branch.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index fe62e7c775da6..7504f14bc52f8 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -100,6 +100,14 @@ test_expect_success 'git branch -m n/n n should work' '
 	git reflog exists refs/heads/n
 '
 
+test_expect_success 'git branch -m bbb should rename checked out branch' '
+	test_when_finished git branch -d bbb &&
+	test_when_finished git checkout master &&
+	git checkout -b aaa &&
+	git branch -m bbb &&
+	git reflog exists refs/heads/bbb
+'
+
 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
 	git branch o/o &&
 	git branch o/p &&

--
https://github.com/git/git/pull/371

```

## Junio C Hamano, 2017-06-06 01:27

Subject: Re: [PATCH] t3200: add test for single parameter passed to -m option
Message-ID: <xmqqzidl9a8l.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqzidl9a8l.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <0102015c7a68c647-372a5a13-5412-4838-921d-66980bac4099-000000@eu-west-1.amazonses.com>

```
Sahil Dua <sahildua2305@gmail.com> writes:

> Adds a test for the case when only one parameter is passed to '-m'
> (move/rename) option.
>
> For example - if 'git branch -m bbb' is run, it should rename the
> currently checked out branch to bbb. There was no test for this
> particular case with only one parameter for -m option. However,
> there's one similar test case for -M option.
>
> Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
> ---
>  t/t3200-branch.sh | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index fe62e7c775da6..7504f14bc52f8 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -100,6 +100,14 @@ test_expect_success 'git branch -m n/n n should work' '
>  	git reflog exists refs/heads/n
>  '
>  
> +test_expect_success 'git branch -m bbb should rename checked out branch' '
> +	test_when_finished git branch -d bbb &&
> +	test_when_finished git checkout master &&
> +	git checkout -b aaa &&
> +	git branch -m bbb &&
> +	git reflog exists refs/heads/bbb
> +'

Looks almost good.  Don't we want to also make sure that HEAD points
at bbb branch, e.g.

	git symbolic-ref HEAD >actual &&
	echo refs/heads/bbb >expect &&
	test_cmp expect actual &&

after the "do we have reflog for the bbb branch?" test?

Also, I suspect that we care about the reflog that is moved to 'bbb'
retains entries created for 'aaa'.  So perhaps "reflog exists" needs
to be replaced by something like

	git checkout -b aaa &&
	git commit --allow-empty -m "a new commit" &&
	git rev-parse aaa@{1} >expect &&
	git branch -m bbb &&
	# the topmost entry is about branch creation
	git rev-parse bbb@{2} >actual

no?

>  test_expect_success 'git branch -m o/o o should fail when o/p exists' '
>  	git branch o/o &&
>  	git branch o/p &&
>
> --
> https://github.com/git/git/pull/371

```

## Sahil Dua, 2017-06-06 08:51

Subject: Re: [PATCH] t3200: add test for single parameter passed to -m option
Message-ID: <CALiud+mvAuDhcLr1DSxAxaf+-NtotBBSxgPM6tMJNueNdR8eAQ@mail.gmail.com>
URL: https://gitlist.dev/e/CALiud%2BmvAuDhcLr1DSxAxaf%2B-NtotBBSxgPM6tMJNueNdR8eAQ%40mail.gmail.com
In-Reply-To: <xmqqzidl9a8l.fsf@gitster.mtv.corp.google.com>

```
On Tue, Jun 6, 2017 at 3:27 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Sahil Dua <sahildua2305@gmail.com> writes:
>
>> Adds a test for the case when only one parameter is passed to '-m'
>> (move/rename) option.
>>
>> For example - if 'git branch -m bbb' is run, it should rename the
>> currently checked out branch to bbb. There was no test for this
>> particular case with only one parameter for -m option. However,
>> there's one similar test case for -M option.
>>
>> Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
>> ---
>>  t/t3200-branch.sh | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
>> index fe62e7c775da6..7504f14bc52f8 100755
>> --- a/t/t3200-branch.sh
>> +++ b/t/t3200-branch.sh
>> @@ -100,6 +100,14 @@ test_expect_success 'git branch -m n/n n should work' '
>>       git reflog exists refs/heads/n
>>  '
>>
>> +test_expect_success 'git branch -m bbb should rename checked out branch' '
>> +     test_when_finished git branch -d bbb &&
>> +     test_when_finished git checkout master &&
>> +     git checkout -b aaa &&
>> +     git branch -m bbb &&
>> +     git reflog exists refs/heads/bbb
>> +'
>
> Looks almost good.  Don't we want to also make sure that HEAD points
> at bbb branch, e.g.
>
>         git symbolic-ref HEAD >actual &&
>         echo refs/heads/bbb >expect &&
>         test_cmp expect actual &&
>
> after the "do we have reflog for the bbb branch?" test?
>
> Also, I suspect that we care about the reflog that is moved to 'bbb'
> retains entries created for 'aaa'.  So perhaps "reflog exists" needs
> to be replaced by something like
>
>         git checkout -b aaa &&
>         git commit --allow-empty -m "a new commit" &&
>         git rev-parse aaa@{1} >expect &&
>         git branch -m bbb &&
>         # the topmost entry is about branch creation
>         git rev-parse bbb@{2} >actual
>
> no?

Both of these changes make complete sense and in my opinion will
increase the quality of the tests if applied to the other tests too. I
notice that no other test for this (-m|-M) option checks if the branch
is actually checked out. Similarly, no other test checks if the
operation retains reflog entries. They just check if the new reflog
exists.

Do you think I should make similar changes to the other tests for
(-m|-M) option as well?

>
>>  test_expect_success 'git branch -m o/o o should fail when o/p exists' '
>>       git branch o/o &&
>>       git branch o/p &&
>>
>> --
>> https://github.com/git/git/pull/371

```

## Sahil Dua, 2017-06-11 11:42

Subject: [PATCH v2] t3200: add test for single parameter passed to -m option
Message-ID: <0102015c96f631f3-557a7960-2557-4aab-894b-efccf6728f31-000000@eu-west-1.amazonses.com>
URL: https://gitlist.dev/e/0102015c96f631f3-557a7960-2557-4aab-894b-efccf6728f31-000000%40eu-west-1.amazonses.com
In-Reply-To: <0102015c7a68c647-372a5a13-5412-4838-921d-66980bac4099-000000@eu-west-1.amazonses.com>

```
Add a test for the case when only one parameter is passed to '-m'
(move/rename) option.

For example - if 'git branch -m bbb' is run, it should rename the
currently checked out branch to bbb. There was no test for this
particular case with only one parameter for -m option. However,
there's one similar test case for -M option.

Add test for making sure HEAD points to the bbb (new branch name). Also
add a test for making sure the reflog that is moved to 'bbb' retains
entries created for the currently checked out branch.

Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
---
 t/t3200-branch.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index fe62e7c775da6..720400c0e42af 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -100,6 +100,20 @@ test_expect_success 'git branch -m n/n n should work' '
 	git reflog exists refs/heads/n
 '
 
+test_expect_success 'git branch -m bbb should rename checked out branch' '
+	test_when_finished git branch -D bbb &&
+	test_when_finished git checkout master &&
+	git checkout -b aaa &&
+	git commit --allow-empty -m "a new commit" &&
+	git rev-parse aaa@{0} >expect &&
+	git branch -m bbb &&
+	git rev-parse bbb@{1} >actual &&
+	test_cmp expect actual &&
+	git symbolic-ref HEAD >actual &&
+	echo refs/heads/bbb >expect &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
 	git branch o/o &&
 	git branch o/p &&

--
https://github.com/git/git/pull/371

```

## Junio C Hamano, 2017-06-12 15:16

Subject: Re: [PATCH v2] t3200: add test for single parameter passed to -m option
Message-ID: <xmqqy3sxp779.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqy3sxp779.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <0102015c96f631f3-557a7960-2557-4aab-894b-efccf6728f31-000000@eu-west-1.amazonses.com>

```
Sahil Dua <sahildua2305@gmail.com> writes:

> Add a test for the case when only one parameter is passed to '-m'
> (move/rename) option.
>
> For example - if 'git branch -m bbb' is run, it should rename the
> currently checked out branch to bbb. There was no test for this
> particular case with only one parameter for -m option. However,
> there's one similar test case for -M option.
>
> Add test for making sure HEAD points to the bbb (new branch name). Also
> add a test for making sure the reflog that is moved to 'bbb' retains
> entries created for the currently checked out branch.
>
> Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
> ---
>  t/t3200-branch.sh | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index fe62e7c775da6..720400c0e42af 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -100,6 +100,20 @@ test_expect_success 'git branch -m n/n n should work' '
>  	git reflog exists refs/heads/n
>  '
>  
> +test_expect_success 'git branch -m bbb should rename checked out branch' '
> +	test_when_finished git branch -D bbb &&
> +	test_when_finished git checkout master &&
> +	git checkout -b aaa &&
> +	git commit --allow-empty -m "a new commit" &&
> +	git rev-parse aaa@{0} >expect &&
> +	git branch -m bbb &&
> +	git rev-parse bbb@{1} >actual &&
> +	test_cmp expect actual &&

I think future readers of this test would appreciate if there were
some comment explaining why aaa@{0} and bbb@{1} (not bbb@{0}) are
expected to be the same here.

> +	git symbolic-ref HEAD >actual &&
> +	echo refs/heads/bbb >expect &&
> +	test_cmp expect actual
> +'
> +
>  test_expect_success 'git branch -m o/o o should fail when o/p exists' '
>  	git branch o/o &&
>  	git branch o/p &&
>
> --
> https://github.com/git/git/pull/371

Other than that, looks sensible to me.

Thanks.

```

## Sahil Dua, 2017-06-13 10:47

Subject: [PATCH v3] t3200: add test for single parameter passed to -m option
Message-ID: <0102015ca110a839-f4703e91-1a4d-4d8e-8406-df06b24683da-000000@eu-west-1.amazonses.com>
URL: https://gitlist.dev/e/0102015ca110a839-f4703e91-1a4d-4d8e-8406-df06b24683da-000000%40eu-west-1.amazonses.com
In-Reply-To: <0102015c96f631f3-557a7960-2557-4aab-894b-efccf6728f31-000000@eu-west-1.amazonses.com>

```
Add a test for the case when only one parameter is passed to '-m'
(move/rename) option.

For example - if 'git branch -m bbb' is run while checked out on aaa
branch, it should rename the currently checked out branch to bbb.
There was no test for this particular case with only one parameter
for -m option. However, there's one similar test case for -M option.

Add test for making sure HEAD points to the bbb (new branch name). Also
add a test for making sure the reflog that is moved to 'bbb' retains
entries created for the currently checked out branch. Note that since
the topmost entry on reflog for bbb will be about branch creation, we
compare bbb@{1} (instead of bbb@{0}) with aaa@{0} to make sure the
reflog for bbb retains entries from aaa.

Signed-off-by: Sahil Dua <sahildua2305@gmail.com>
---
 t/t3200-branch.sh | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index fe62e7c775da6..8c9cd70696f87 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -100,6 +100,23 @@ test_expect_success 'git branch -m n/n n should work' '
 	git reflog exists refs/heads/n
 '
 
+# The topmost entry in reflog for branch bbb is about branch creation.
+# Hence, we compare bbb@{1} (instead of bbb@{0}) with aaa@{0}.
+
+test_expect_success 'git branch -m bbb should rename checked out branch' '
+	test_when_finished git branch -D bbb &&
+	test_when_finished git checkout master &&
+	git checkout -b aaa &&
+	git commit --allow-empty -m "a new commit" &&
+	git rev-parse aaa@{0} >expect &&
+	git branch -m bbb &&
+	git rev-parse bbb@{1} >actual &&
+	test_cmp expect actual &&
+	git symbolic-ref HEAD >actual &&
+	echo refs/heads/bbb >expect &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git branch -m o/o o should fail when o/p exists' '
 	git branch o/o &&
 	git branch o/p &&

--
https://github.com/git/git/pull/371

```
