# [PATCH] Do not display 'Switched to a new branch' when the branch existed

10 messages from 2010-08-18 to 2010-08-25. Participants: Knittl, Jonathan Nieder, Tay Ray Chuan, Junio C Hamano.
Thread: https://gitlist.dev/t/24778

## Knittl, 2010-08-18 08:28

Subject: [PATCH] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTimaZF1Q6BPB7CN0Wa5-Ov2ejVfPsmL34vps2VqK@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimaZF1Q6BPB7CN0Wa5-Ov2ejVfPsmL34vps2VqK%40mail.gmail.com

```
From cc6410b89b85822aadc5a7843b7398209957e549 Mon Sep 17 00:00:00 2001
From: Tay Ray Chuan <rctay89@gmail.com>
Date: Thu, 24 Jun 2010 03:29:00 +0800
Subject: [PATCH] builtin/checkout: fix info message for `git checkout <branch>`

Since 02ac98374eefbe4a46d4b53a8a78057ad8ad39b7 `git checkout` would
always display 'Switched to a new branch <branch>` even if the branch
had already existed.

Signed-off-by: Daniel Knittl-Frank <knittl89+git@googlemail.com>
---

git checkout should only display 'Switched to a new branch <branch>'
when it creates a new branch, not when it simply switches branches.

ps. I'm not sure about the style used in git for nested ternary
statements (if they should even be used …)

 builtin/checkout.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 4ad7427..ed7cde1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -536,7 +536,9 @@ static void update_refs_for_switch(struct
checkout_opts *opts,
 					new->name);
 			else
 				fprintf(stderr, "Switched to%s branch '%s'\n",
-					opts->branch_exists ? " and reset" : " a new",
+					opts->branch_exists
+						? " and reset"
+						: opts->new_branch ? " a new" : "",
 					new->name);
 		}
 		if (old->path && old->name) {
-- 
1.7.1.574.g421e3

```

## Knittl, 2010-08-18 08:38

Subject: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTi=3z9gJdT8LL3NANFyppUjvOVcrszjf5J5zAKPe@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3D3z9gJdT8LL3NANFyppUjvOVcrszjf5J5zAKPe%40mail.gmail.com
In-Reply-To: <AANLkTimaZF1Q6BPB7CN0Wa5-Ov2ejVfPsmL34vps2VqK@mail.gmail.com>

```
From 16f540c87f8c7b87692dfd488d507802ae975312 Mon Sep 17 00:00:00 2001
From: Daniel Knittl-Frank <knittl89+git@googlemail.com>
Date: Wed, 18 Aug 2010 10:35:42 +0200
Subject: [PATCH] builtin/checkout: fix info message for `git checkout <branch>`

Since 02ac98374eefbe4a46d4b53a8a78057ad8ad39b7 `git checkout` would
always display 'Switched to a new branch <branch>` even if the branch
had already existed.

Signed-off-by: Daniel Knittl-Frank <knittl89+git@googlemail.com>
---

stupid me, i forgot to reset author in re-used commit …

 builtin/checkout.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 4ad7427..ed7cde1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -536,7 +536,9 @@ static void update_refs_for_switch(struct
checkout_opts *opts,
 					new->name);
 			else
 				fprintf(stderr, "Switched to%s branch '%s'\n",
-					opts->branch_exists ? " and reset" : " a new",
+					opts->branch_exists
+						? " and reset"
+						: opts->new_branch ? " a new" : "",
 					new->name);
 		}
 		if (old->path && old->name) {
-- 
1.7.1.574.g421e3


-- 
typed with http://neo-layout.org
myFtPhp -- visit http://myftphp.sf.net -- v. 0.4.7 released!

```

## Jonathan Nieder, 2010-08-18 09:16

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <20100818091603.GA6263@burratino>
URL: https://gitlist.dev/e/20100818091603.GA6263%40burratino
In-Reply-To: <AANLkTi=3z9gJdT8LL3NANFyppUjvOVcrszjf5J5zAKPe@mail.gmail.com>

```
Hi,

Warning: nitpicks coming.

Knittl wrote:

> From 16f540c87f8c7b87692dfd488d507802ae975312 Mon Sep 17 00:00:00 2001
> From: Daniel Knittl-Frank <knittl89+git@googlemail.com>
> Date: Wed, 18 Aug 2010 10:35:42 +0200
> Subject: [PATCH] builtin/checkout: fix info message for `git checkout <branch>`

On the git list, there are two formats often used for patches (see
Documentation/SubmittingPatches for details): whole-message patches,
which look like this:

	git checkout should only display 'Switched to a new branch <branch>'
	when it creates a new branch, not when it simply switches branches.

	This fixes a bug introduced by 02ac9837 (builtin/checkout:
	learn -B, 2010-06-24).

	Signed-off-by: Daniel Knittl-Frank <knittl89+git@googlemail.com>
	---
	comments of the moment

	 diffstat
	...

and "inline" patches, which look like this:

	comments of the moment
	-- 8< --
	Subject: patch subject

	patch rationale
	---
	 diffstat
	...

and sometimes get used when it is more natural for discussion.

The "From " line and so on output by "git format-patch" are for your
mailer.  Clarifying From:, Date:, and Subject: lines at the start of
your message are allowed, though, and can be useful when forwarding
patches from someone else.

> +++ b/builtin/checkout.c
> @@ -536,7 +536,9 @@ static void update_refs_for_switch(struct
> checkout_opts *opts,
>  					new->name);
>  			else
>  				fprintf(stderr, "Switched to%s branch '%s'\n",
> -					opts->branch_exists ? " and reset" : " a new",
> +					opts->branch_exists
> +						? " and reset"
> +						: opts->new_branch ? " a new" : "",

Maybe it would be clearer to write

	opts->new_branch ? " a new"
		: opts->branch_exists ? " and reset"
		: "",

to emphasize that this is a list of condition/result pairs?

The functionality of your patch is obviously good.  Thanks.

Jonathan

```

## Tay Ray Chuan, 2010-08-18 13:39

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTikHbj4zA6Kj0wUp6uQUY3w6cM_z0=Pes1jLLTky@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikHbj4zA6Kj0wUp6uQUY3w6cM_z0%3DPes1jLLTky%40mail.gmail.com
In-Reply-To: <20100818091603.GA6263@burratino>

```
Hi,

On Wed, Aug 18, 2010 at 5:16 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Hi,

Johnathan, thanks for the heads up.

> [snip]
>
> The "From " line and so on output by "git format-patch" are for your
> mailer.  Clarifying From:, Date:, and Subject: lines at the start of
> your message are allowed, though, and can be useful when forwarding
> patches from someone else.

Knittl, I wonder how you generated this patch? Were you working on top
of the "bad" commit?

>> +++ b/builtin/checkout.c
>> @@ -536,7 +536,9 @@ static void update_refs_for_switch(struct
>> checkout_opts *opts,
>>                                       new->name);
>>                       else
>>                               fprintf(stderr, "Switched to%s branch '%s'\n",
>> -                                     opts->branch_exists ? " and reset" : " a new",
>> +                                     opts->branch_exists
>> +                                             ? " and reset"
>> +                                             : opts->new_branch ? " a new" : "",

Strange - I thought I had this sorted out. Thanks for spotting this.

> Maybe it would be clearer to write
>
>        opts->new_branch ? " a new"
>                : opts->branch_exists ? " and reset"
>                : "",
>
> to emphasize that this is a list of condition/result pairs?

We could do with some parentheses - here's my take:

	fprintf(stderr, "Switched to%s branch '%s'\n",
		(opts->branch_exists ? " and reset" :
			(opts->new_branch ? " a new" : "")),
		new->name);

-- 
Cheers,
Ray Chuan

```

## Junio C Hamano, 2010-08-18 20:59

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <7voccz8wo8.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7voccz8wo8.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20100818091603.GA6263@burratino>

```
Jonathan Nieder <jrnieder@gmail.com> writes:

> The functionality of your patch is obviously good.  Thanks.

In what way is it good?  I am especially worried about the word "reset"
being confusing.

You are switching to a new context to work on something else, so I don't
necessarily think it is confusing that the word "new branch" in this
message does not mean "a branch that did not exist before this operation
(i.e. a newly created branch)."

```

## Junio C Hamano, 2010-08-18 23:38

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <7v4oer8paz.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4oer8paz.fsf%40alter.siamese.dyndns.org
In-Reply-To: <7voccz8wo8.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Jonathan Nieder <jrnieder@gmail.com> writes:
>
>> The functionality of your patch is obviously good.  Thanks.
>
> In what way is it good?  I am especially worried about the word "reset"
> being confusing.
>
> You are switching to a new context to work on something else, so I don't
> necessarily think it is confusing that the word "new branch" in this
> message does not mean "a branch that did not exist before this operation
> (i.e. a newly created branch)."

Ahh, please disregard the above; I somehow failed to see that this is only
in the "-b/-B" codepath.  Sorry for the noise.

```

## Tay Ray Chuan, 2010-08-19 03:21

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTi=fkgmx4+oYO71OiaayEpehcmxb5aOeR6WvU7DL@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3Dfkgmx4%2BoYO71OiaayEpehcmxb5aOeR6WvU7DL%40mail.gmail.com
In-Reply-To: <AANLkTimU75krdgQFvw0fEvAPqJb-eKaPXHg_5Hv2A8wh@mail.gmail.com>

```
Hi,

oops, seems like you dropped everyone from the Cc list, including the
mailing list. Try using the "Reply to all" next time.

On Wed, Aug 18, 2010 at 9:56 PM, Knittl <knittl89@googlemail.com> wrote:
> [snip
> yes, i branched off of your bad commit (or rather the commit after
> your bad commit "fix detached head usage") and created the commit with
> git commit -c HEAD^ to have the same heading and similar wording
> without opening a second terminal to copy it over. so i accidentally
> sent the patch with your name as author, which i then fixed with git
> amend --reset-author

Why copy over the old commit message? You should be writing one that
fits what you're did, not what *I* did.

-- 
Cheers,
Ray Chuan

```

## Knittl, 2010-08-24 06:50

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTim7DNasVmaBxWBcUGyGBCZq_HXNdq_=4uKRdxE-@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTim7DNasVmaBxWBcUGyGBCZq_HXNdq_%3D4uKRdxE-%40mail.gmail.com
In-Reply-To: <AANLkTikHbj4zA6Kj0wUp6uQUY3w6cM_z0=Pes1jLLTky@mail.gmail.com>

```
sorry for the late reply, i hadn't had access to internet for the last
week and as it turns i sent my response only to tay

On Wed, Aug 18, 2010 at 3:39 PM, Tay Ray Chuan <rctay89@gmail.com> wrote:
> Hi,
>
> On Wed, Aug 18, 2010 at 5:16 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> [snip]
>
>> The "From " line and so on output by "git format-patch" are for your
>> mailer.  Clarifying From:, Date:, and Subject: lines at the start of
>> your message are allowed, though, and can be useful when forwarding
>> patches from someone else.
>
> Knittl, I wonder how you generated this patch? Were you working on top
> of the "bad" commit?

yes, i branched off of your bad commit (or rather the commit after
your bad commit "fix detached head usage") and created the commit with
git commit -c HEAD^ to have the same heading and similar wording
without opening a second terminal to copy it over. so i accidentally
sent the patch with your name as author, which i then fixed with git
amend --reset-author

>>> +++ b/builtin/checkout.c
>>> @@ -536,7 +536,9 @@ static void update_refs_for_switch(struct
>>> checkout_opts *opts,
>>>                                       new->name);
>>>                       else
>>>                               fprintf(stderr, "Switched to%s branch '%s'\n",
>>> -                                     opts->branch_exists ? " and reset" : " a new",
>>> +                                     opts->branch_exists
>>> +                                             ? " and reset"
>>> +                                             : opts->new_branch ? " a new" : "",
>
> Strange - I thought I had this sorted out. Thanks for spotting this.

i tested with next and pu and both tips had the same (confusing) message.

>> Maybe it would be clearer to write
>>
>>        opts->new_branch ? " a new"
>>                : opts->branch_exists ? " and reset"
>>                : "",
>>
>> to emphasize that this is a list of condition/result pairs?
>
> We could do with some parentheses - here's my take:
>
>        fprintf(stderr, "Switched to%s branch '%s'\n",
>                (opts->branch_exists ? " and reset" :
>                        (opts->new_branch ? " a new" : "")),
>                new->name);

that's not really for me to decide, but i'm fine with either version

cheers

-- 
typed with http://neo-layout.org
myFtPhp -- visit http://myftphp.sf.net -- v. 0.4.7 released!

```

## Tay Ray Chuan, 2010-08-24 13:06

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTinXKwUwfXuCzghUgiyck=JBoQLrUn=kPRe0X+a5@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinXKwUwfXuCzghUgiyck%3DJBoQLrUn%3DkPRe0X%2Ba5%40mail.gmail.com
In-Reply-To: <AANLkTim7DNasVmaBxWBcUGyGBCZq_HXNdq_=4uKRdxE-@mail.gmail.com>

```
Hi,

On Tue, Aug 24, 2010 at 2:50 PM, Knittl <knittl89@googlemail.com> wrote:
> sorry for the late reply, i hadn't had access to internet for the last
> week and as it turns i sent my response only to tay

just a heads-up - this has already been fixed since 09a0ec5 in master.

-- 
Cheers,
Ray Chuan

```

## Knittl, 2010-08-25 11:51

Subject: Re: [PATCH re-roll] Do not display 'Switched to a new branch' when the branch existed
Message-ID: <AANLkTi=1dRw_rkaAV174r2SVLbxE6v9Wu2NjjzZCZ63T@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTi%3D1dRw_rkaAV174r2SVLbxE6v9Wu2NjjzZCZ63T%40mail.gmail.com
In-Reply-To: <AANLkTinXKwUwfXuCzghUgiyck=JBoQLrUn=kPRe0X+a5@mail.gmail.com>

```
On Tue, Aug 24, 2010 at 3:06 PM, Tay Ray Chuan <rctay89@gmail.com> wrote:
> Hi,
>
> On Tue, Aug 24, 2010 at 2:50 PM, Knittl <knittl89@googlemail.com> wrote:
>> sorry for the late reply, i hadn't had access to internet for the last
>> week and as it turns i sent my response only to tay
>
> just a heads-up - this has already been fixed since 09a0ec5 in master.


oh. good :)


-- 
typed with http://neo-layout.org
myFtPhp -- visit http://myftphp.sf.net -- v. 0.4.7 released!

```
