threads / bug / 29458

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

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

## tl;dr

9 messages between Jan 27, 2012 and Jan 29, 2012.

replies: 8people: 4as markdown or json

Mark Jason Dominus· Jan 27, 2012, 21:52 UTC · lore
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· Jan 27, 2012, 23:21 UTC · re: Mark Jason Dominus · lore

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

Mark Jason Dominus <mjd@plover.com> writes:
Show 15 quoted lines
> 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· Jan 28, 2012, 06:46 UTC · re: Junio C Hamano · lore

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

On 01/28/2012 12:21 AM, Junio C Hamano wrote:
Show 28 quoted lines
> 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· Jan 28, 2012, 07:27 UTC · re: Michael Haggerty · lore

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

Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 15 quoted lines
>>> 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· Jan 29, 2012, 03:18 UTC · re: Junio C Hamano · lore

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

On Fri, Jan 27, 2012 at 11:27:29PM -0800, Junio C Hamano wrote:
Show 7 quoted lines
> > 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· Jan 29, 2012, 06:30 UTC · re: Junio C Hamano · lore

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

On 01/28/2012 08:27 AM, Junio C Hamano wrote:
Show 34 quoted lines
> 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.

Show 9 quoted lines
>> 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· Jan 29, 2012, 06:42 UTC · re: Michael Haggerty · lore

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

Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 24 quoted lines
> 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· Jan 29, 2012, 10:11 UTC · re: Junio C Hamano · lore

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

On 01/29/2012 07:42 AM, Junio C Hamano wrote:
Show 29 quoted lines
> 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· Jan 29, 2012, 21:49 UTC · re: Michael Haggerty · lore

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

Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 6 quoted lines
> 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.

← back to recent threads