# BUG 1.7.9: git branch fails to create new branch when --edit-description is used

9 messages from 2012-01-27 to 2012-01-29. Participants: Mark Jason Dominus, Junio C Hamano, Michael Haggerty, Jeff King.
Thread: https://gitlist.dev/t/29458

## Mark Jason Dominus, 2012-01-27 21:52

Subject: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <2443.1327701165@plover.com>
URL: https://gitlist.dev/e/2443.1327701165%40plover.com

```

This should work, but doesn't:

        % git branch
        * master
        % git branch  --edit-description  blarf
        [Edit description and exit editor normally]
        % cat .git/BRANCH_DESCRIPTION 
        I like blarf
        # Please edit the description for the branch
        #   blarf
        # Lines starting with '#' will be stripped.
        % git branch -a
        * master

Where is branch blarf?

Creating the branch and editing the description afterwards works correctly:

        % git branch blarf
        % git branch  --edit-description  blarf
        % git branch -a
          blarf
        * master
        % cat .git/config 
        [core]
                repositoryformatversion = 0
                filemode = true
                bare = false
                logallrefupdates = true
        [branch "master"]
                description = I like pie\n
        [branch "blarf"]
                description = I like blarf\n


Mark Jason Dominus 	  			                 mjd@plover.com

```

## Junio C Hamano, 2012-01-27 23:21

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <7vr4ykybnl.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr4ykybnl.fsf%40alter.siamese.dyndns.org
In-Reply-To: <2443.1327701165@plover.com>

```
Mark Jason Dominus <mjd@plover.com> writes:

> This should work, but doesn't:
>
>         % git branch
>         * master
>         % git branch  --edit-description  blarf
>         [Edit description and exit editor normally]
>         % cat .git/BRANCH_DESCRIPTION 
>         I like blarf
>         # Please edit the description for the branch
>         #   blarf
>         # Lines starting with '#' will be stripped.
>         % git branch -a
>         * master
>
> Where is branch blarf?

You haven't created one in that sequence yet.

This is more of a documentation bug. 

As the SYNOPSIS section makes it clear, the '--edit-description' is a
separate mode from showing (the first group), creating or repointing (the
second), or renaming (the third).

After that you should be able to say "git branch blarf" and view its
description.

```

## Michael Haggerty, 2012-01-28 06:46

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <4F2399B6.8020507@alum.mit.edu>
URL: https://gitlist.dev/e/4F2399B6.8020507%40alum.mit.edu
In-Reply-To: <7vr4ykybnl.fsf@alter.siamese.dyndns.org>

```
On 01/28/2012 12:21 AM, Junio C Hamano wrote:
> Mark Jason Dominus <mjd@plover.com> writes:
> 
>> This should work, but doesn't:
>>
>>         % git branch
>>         * master
>>         % git branch  --edit-description  blarf
>>         [Edit description and exit editor normally]
>>         % cat .git/BRANCH_DESCRIPTION 
>>         I like blarf
>>         # Please edit the description for the branch
>>         #   blarf
>>         # Lines starting with '#' will be stripped.
>>         % git branch -a
>>         * master
>>
>> Where is branch blarf?
> 
> You haven't created one in that sequence yet.
> 
> This is more of a documentation bug. 
> 
> As the SYNOPSIS section makes it clear, the '--edit-description' is a
> separate mode from showing (the first group), creating or repointing (the
> second), or renaming (the third).
> 
> After that you should be able to say "git branch blarf" and view its
> description.

Given this design, shouldn't "git branch --edit-description" fail if the
branch doesn't already exist?

Shouldn't it also resolve ambiguous reference names?

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

```

## Junio C Hamano, 2012-01-28 07:27

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <7vbopoxp5q.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbopoxp5q.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4F2399B6.8020507@alum.mit.edu>

```
Michael Haggerty <mhagger@alum.mit.edu> writes:

>>> Where is branch blarf?
>> 
>> You haven't created one in that sequence yet.
>> 
>> This is more of a documentation bug. 
>> 
>> As the SYNOPSIS section makes it clear, the '--edit-description' is a
>> separate mode from showing (the first group), creating or repointing (the
>> second), or renaming (the third).
>> 
>> After that you should be able to say "git branch blarf" and view its
>> description.
>
> Given this design, shouldn't "git branch --edit-description" fail if the
> branch doesn't already exist?


The only use scenario in the original design was to have a way to store
the description given a branch name, and giving a description to a branch
that does not yet exist is outside the scope of the design. So it all
boils down to what is the most convenient and the simplest to explain.

We could error it out (i.e. you cannot name a thing that does not yet
exist), or we could consider it is a convenience feature that you can
prepare a description even before you create one, or we could even tweak
it more like "-t $name" that tries to work both on existing one (without
changing any base) or non-existing one, creating it while at it. The last
approach historically is the most error prone (we had numerous bugs in the
create_branch() helper after it started allowing an existing branch when
updating the "track" information) and I would rather not go that route if
we can avoid it.

Honestly speaking, I haven't formed an opinion.

> Shouldn't it also resolve ambiguous reference names?

As this mode, just like other modes of "git branch" _always_ takes a
branch name, I do not think there is any "ambiguous reference name".

You give $name to it, and it should always mean refs/heads/$name, and
there shouldn't be any DWIMming to something like refs/heads/mh/$name

Or do you have other kinds of ambiguity in mind?

```

## Jeff King, 2012-01-29 03:18

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <20120129031843.GA1347@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120129031843.GA1347%40sigill.intra.peff.net
In-Reply-To: <7vbopoxp5q.fsf@alter.siamese.dyndns.org>

```
On Fri, Jan 27, 2012 at 11:27:29PM -0800, Junio C Hamano wrote:

> > Given this design, shouldn't "git branch --edit-description" fail if the
> > branch doesn't already exist?
> 
> The only use scenario in the original design was to have a way to store
> the description given a branch name, and giving a description to a branch
> that does not yet exist is outside the scope of the design. So it all
> boils down to what is the most convenient and the simplest to explain.

How do we define "branch exists"? That the ref exists? What about a HEAD
that points to a branch-to-be-born?

Specifically, I am wondering whether this:

  $ git init
  $ git branch --edit-description

should work. Right now it edits the description for "master", even
though you haven't yet committed to it.

-Peff

```

## Michael Haggerty, 2012-01-29 06:30

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <4F24E78A.7060502@alum.mit.edu>
URL: https://gitlist.dev/e/4F24E78A.7060502%40alum.mit.edu
In-Reply-To: <7vbopoxp5q.fsf@alter.siamese.dyndns.org>

```
On 01/28/2012 08:27 AM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
> 
>>>> Where is branch blarf?
>>>
>>> You haven't created one in that sequence yet.
>>>
>>> This is more of a documentation bug. 
>>>
>>> As the SYNOPSIS section makes it clear, the '--edit-description' is a
>>> separate mode from showing (the first group), creating or repointing (the
>>> second), or renaming (the third).
>>>
>>> After that you should be able to say "git branch blarf" and view its
>>> description.
>>
>> Given this design, shouldn't "git branch --edit-description" fail if the
>> branch doesn't already exist?
> 
> The only use scenario in the original design was to have a way to store
> the description given a branch name, and giving a description to a branch
> that does not yet exist is outside the scope of the design. So it all
> boils down to what is the most convenient and the simplest to explain.
> 
> We could error it out (i.e. you cannot name a thing that does not yet
> exist), or we could consider it is a convenience feature that you can
> prepare a description even before you create one, or we could even tweak
> it more like "-t $name" that tries to work both on existing one (without
> changing any base) or non-existing one, creating it while at it. The last
> approach historically is the most error prone (we had numerous bugs in the
> create_branch() helper after it started allowing an existing branch when
> updating the "track" information) and I would rather not go that route if
> we can avoid it.
> 
> Honestly speaking, I haven't formed an opinion.

I vote for an error.  Otherwise a typo in the branch name would lead to
the description's apparent disappearance into Nirvana.  An error would,
for example, have made it clear to the OP what was happening.

A more useful option might be

    git branch --with-description <branchname> [<start-point>]

i.e., that a branch's description can be set at the same time as the
branch is created.

>> Shouldn't it also resolve ambiguous reference names?
> 
> As this mode, just like other modes of "git branch" _always_ takes a
> branch name, I do not think there is any "ambiguous reference name".
> 
> You give $name to it, and it should always mean refs/heads/$name, and
> there shouldn't be any DWIMming to something like refs/heads/mh/$name
> 
> Or do you have other kinds of ambiguity in mind?

OK, I wasn't aware that only local branches can have descriptions
attached to them.  Given that fact, you are correct that DWIMming
doesn't make sense.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

```

## Junio C Hamano, 2012-01-29 06:42

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <7v39azxb5l.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v39azxb5l.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4F24E78A.7060502@alum.mit.edu>

```
Michael Haggerty <mhagger@alum.mit.edu> writes:

> On 01/28/2012 08:27 AM, Junio C Hamano wrote:
>> 
>> We could error it out (i.e. you cannot name a thing that does not yet
>> exist), or we could consider it is a convenience feature that you can
>> prepare a description even before you create one, or we could even tweak
>> it more like "-t $name" that tries to work both on existing one (without
>> changing any base) or non-existing one, creating it while at it. The last
>> approach historically is the most error prone (we had numerous bugs in the
>> create_branch() helper after it started allowing an existing branch when
>> updating the "track" information) and I would rather not go that route if
>> we can avoid it.
>> 
>> Honestly speaking, I haven't formed an opinion.
>
> I vote for an error.  Otherwise a typo in the branch name would lead to
> the description's apparent disappearance into Nirvana.  An error would,
> for example, have made it clear to the OP what was happening.
>
> A more useful option might be
>
>     git branch --with-description <branchname> [<start-point>]
>
> i.e., that a branch's description can be set at the same time as the
> branch is created.

So you are saying either option 1 or 3 is preferrable, while I was saying
I would rather avoid 3 if we could avoid it. Is that the short version?

```

## Michael Haggerty, 2012-01-29 10:11

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <4F251B50.5080602@alum.mit.edu>
URL: https://gitlist.dev/e/4F251B50.5080602%40alum.mit.edu
In-Reply-To: <7v39azxb5l.fsf@alter.siamese.dyndns.org>

```
On 01/29/2012 07:42 AM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
> 
>> On 01/28/2012 08:27 AM, Junio C Hamano wrote:
>>>
>>> We could error it out (i.e. you cannot name a thing that does not yet
>>> exist), or we could consider it is a convenience feature that you can
>>> prepare a description even before you create one, or we could even tweak
>>> it more like "-t $name" that tries to work both on existing one (without
>>> changing any base) or non-existing one, creating it while at it. The last
>>> approach historically is the most error prone (we had numerous bugs in the
>>> create_branch() helper after it started allowing an existing branch when
>>> updating the "track" information) and I would rather not go that route if
>>> we can avoid it.
>>>
>>> Honestly speaking, I haven't formed an opinion.
>>
>> I vote for an error.  Otherwise a typo in the branch name would lead to
>> the description's apparent disappearance into Nirvana.  An error would,
>> for example, have made it clear to the OP what was happening.
>>
>> A more useful option might be
>>
>>     git branch --with-description <branchname> [<start-point>]
>>
>> i.e., that a branch's description can be set at the same time as the
>> branch is created.
> 
> So you are saying either option 1 or 3 is preferrable, while I was saying
> I would rather avoid 3 if we could avoid it. Is that the short version?

Not quite.  I agree that "--add-description" should fail if the branch
already exists.  But I was suggesting that there be a new *different*
option that can be used when creating a branch.  "--with-description" is
probably not a great name, but I think it is a good idea that it be
spelled differently than "--add-description".  Perhaps even "--message",
even though the abbreviation "-m" is precluded by the existing "-m" option.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

```

## Junio C Hamano, 2012-01-29 21:49

Subject: Re: BUG 1.7.9: git branch fails to create new branch when --edit-description is used
Message-ID: <7vzkd6dvrm.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzkd6dvrm.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4F24E78A.7060502@alum.mit.edu>

```
Michael Haggerty <mhagger@alum.mit.edu> writes:

> On 01/28/2012 08:27 AM, Junio C Hamano wrote:
>> Michael Haggerty <mhagger@alum.mit.edu> writes:
>> 
> I vote for an error.  Otherwise a typo in the branch name would lead to
> the description's apparent disappearance into Nirvana.  An error would,
> for example, have made it clear to the OP what was happening.

I agree with this statement.

Unless or until we update --edit-description to create a new branch when
given a name of a branch that does not exist, the existing behaviour is
simply an accident waiting to happen.

```
