git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* BUG or FEATURE? Use of '/' in branch names
       [not found] <5363D1B4.1000503@lge.com>
@ 2014-05-02 22:04 ` Keith Derrick
  2014-05-02 22:10   ` Felipe Contreras
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Keith Derrick @ 2014-05-02 22:04 UTC (permalink / raw)
  To: Keith Derrick, git; +Cc: simon.busch

According to https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html a '/' is character to use in a branch name.


git imposes the following rules on how references are named:
1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.


git-flow, for example,  uses it extensively to prefix branches with 'release/', 'bugfix/', 'hotfix/' etc.

However, I just ran into the following problem


    $git init
    Initialized empty Git repository in /home/keith/play/bug2/.git/
    $touch a
    $git add a
    $git commit -m "C1"
    [master (root-commit) d569d5b] C1
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 a
    $git checkout -b hotfix
    Switched to a new branch 'hotfix'
    $git checkout -b hotfix/b2
    error: unable to resolve reference refs/heads/hotfix/b2: Not a directory
    fatal: Failed to lock ref for update: Not a directory
    $

The problem arises when a branch already exists with a name matching the stem of the new branch name.

As far as I can see, this comes from the use of the branch name to create a directory under .git/refs/heads with the name 'hotfix/b2' because .git/refs/heads/hotfix already exists as a plain file.

Note, however that this works

    $git init
    Initialized empty Git repository in /home/keith/play/bug3/.git/
    $touch a
    $git add a && git commit -m 'C1'
    [master (root-commit) 304052c] C1
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 a
    $git checkout -b hotfix/b1
    Switched to a new branch 'hotfix/b1'
    $git checkout -b hotfix/b2
    Switched to a new branch 'hotfix/b2'
    $ls .git/refs/heads/ -R
    .git/refs/heads/:
    hotfix  master

    .git/refs/heads/hotfix:
    b1  b2
    $

But, for the reverse reason, I can't now create the branch named 'hotfix'

I can see the value in grouping branches in a directory tree under refs/heads, but wouldn't it make more sense to simply escape the '/' in the branch name so that 'hotfix/b1' is stored on disk as 'hotfix\/b1'?

I found this when trying to document a branching workflow for support branches. The repositories already had branches such as 'release1', 'release2' and I wanted to add branches such as 'release1/develop', 'release2/develop', 'release1/staging', 'release2/staging' etc.

Renaming the existing published branches is not an option for us, I'm afraid.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: BUG or FEATURE? Use of '/' in branch names
  2014-05-02 22:04 ` BUG or FEATURE? Use of '/' in branch names Keith Derrick
@ 2014-05-02 22:10   ` Felipe Contreras
  2014-05-02 22:16   ` Junio C Hamano
  2014-05-02 22:16   ` Jonathan Nieder
  2 siblings, 0 replies; 8+ messages in thread
From: Felipe Contreras @ 2014-05-02 22:10 UTC (permalink / raw)
  To: Keith Derrick, Keith Derrick, git; +Cc: simon.busch

Keith Derrick wrote:
> I can see the value in grouping branches in a directory tree under
> refs/heads, but wouldn't it make more sense to simply escape the '/'
> in the branch name so that 'hotfix/b1' is stored on disk as
> 'hotfix\/b1'?

This would be nice for remote helpers: Mercurial can have "hotfix" and
"hotifx/b1", so importing such a Mercurial repository creates problems.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: BUG or FEATURE? Use of '/' in branch names
  2014-05-02 22:04 ` BUG or FEATURE? Use of '/' in branch names Keith Derrick
  2014-05-02 22:10   ` Felipe Contreras
@ 2014-05-02 22:16   ` Junio C Hamano
  2014-05-02 22:16   ` Jonathan Nieder
  2 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2014-05-02 22:16 UTC (permalink / raw)
  To: Keith Derrick; +Cc: git, simon.busch

Keith Derrick <keith.derrick@lge.com> writes:

> The problem arises when a branch already exists with a name
> matching the stem of the new branch name.
> ...
> But, for the reverse reason, I can't now create the branch named 'hotfix'

All correct.  Allowing '/' in branch names came about not with a
careful design but was done by a happy accident, and we accepted it
under the condition "as long as users know that they cannot have
branches D and D/F at the same time, that is fine".

An obvious alternative convention you can adopt would be to use not
'/' but some other separating characters (e.g. "_") as your
hierarchy delimiter, if you must have D and D_F at the same time.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: BUG or FEATURE? Use of '/' in branch names
  2014-05-02 22:04 ` BUG or FEATURE? Use of '/' in branch names Keith Derrick
  2014-05-02 22:10   ` Felipe Contreras
  2014-05-02 22:16   ` Junio C Hamano
@ 2014-05-02 22:16   ` Jonathan Nieder
  2014-05-02 22:36     ` Keith Derrick
  2014-05-03  7:35     ` Dennis Kaarsemaker
  2 siblings, 2 replies; 8+ messages in thread
From: Jonathan Nieder @ 2014-05-02 22:16 UTC (permalink / raw)
  To: Keith Derrick; +Cc: git, simon.busch

Hi Keith,

Keith Derrick wrote:

>     $ git checkout -b hotfix
>     Switched to a new branch 'hotfix'
>     $ git checkout -b hotfix/b2
>     error: unable to resolve reference refs/heads/hotfix/b2: Not a directory
>     fatal: Failed to lock ref for update: Not a directory
>     $

That's an ugly message.  I think we can do better. (hint hint)

Longer term, I think people would like to make it possible for a
'hotfix' and 'hotfix/b2' branch to coexist, but that will take some
work, and until then, git tries to be careful about enforcing the
constraint that they cannot coexist.

Fixing it would be complicated by the need to avoid breaking people
with older versions of git when they fetch from you (what happens to
the origin/hotfix and origin/hotfix/b2 remote-tracking refs on the
client side?).

Thanks and hope that helps,
Jonathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: BUG or FEATURE? Use of '/' in branch names
  2014-05-02 22:16   ` Jonathan Nieder
@ 2014-05-02 22:36     ` Keith Derrick
  2014-05-02 22:43       ` Jonathan Nieder
  2014-05-03  7:35     ` Dennis Kaarsemaker
  1 sibling, 1 reply; 8+ messages in thread
From: Keith Derrick @ 2014-05-02 22:36 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, simon.busch

Yes, I've since found some discussion on this, and had already changed 
to use '-' to append the classifier.

But the other problem is that I can't easily find this restriction 
documented anywhere - which means it comes as a suprise to people.

As it stands, the documentation implies that what I tried should work. 
In which case, how it's been *implemented* seems to be breaking the 
promise of the functional specification (if you view the documentation 
as such).

Keith

On 05/02/2014 03:16 PM, Jonathan Nieder wrote:
> Hi Keith,
>
> Keith Derrick wrote:
>
>>      $ git checkout -b hotfix
>>      Switched to a new branch 'hotfix'
>>      $ git checkout -b hotfix/b2
>>      error: unable to resolve reference refs/heads/hotfix/b2: Not a directory
>>      fatal: Failed to lock ref for update: Not a directory
>>      $
> That's an ugly message.  I think we can do better. (hint hint)
>
> Longer term, I think people would like to make it possible for a
> 'hotfix' and 'hotfix/b2' branch to coexist, but that will take some
> work, and until then, git tries to be careful about enforcing the
> constraint that they cannot coexist.
>
> Fixing it would be complicated by the need to avoid breaking people
> with older versions of git when they fetch from you (what happens to
> the origin/hotfix and origin/hotfix/b2 remote-tracking refs on the
> client side?).
>
> Thanks and hope that helps,
> Jonathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: BUG or FEATURE? Use of '/' in branch names
  2014-05-02 22:36     ` Keith Derrick
@ 2014-05-02 22:43       ` Jonathan Nieder
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Nieder @ 2014-05-02 22:43 UTC (permalink / raw)
  To: Keith Derrick; +Cc: git, simon.busch

Hi,

Keith Derrick wrote:

> Yes, I've since found some discussion on this, and had already changed 
> to use '-' to append the classifier.
>
> But the other problem is that I can't easily find this restriction 
> documented anywhere - which means it comes as a suprise to people.

That sounds like another serious bug (the first one was the lousy
error message).  The current behavior is intended, and it sounds like
the documentation is lagging.

Where did you expect to find information about this?  Knowing that
would help a lot in fixing it.

(The nicest way to indicate where you expected to read about this
is with a patch against the relevant file in Documentation/*.txt,
of course.)

Thanks again,
Jonathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: BUG or FEATURE? Use of '/' in branch names
  2014-05-02 22:16   ` Jonathan Nieder
  2014-05-02 22:36     ` Keith Derrick
@ 2014-05-03  7:35     ` Dennis Kaarsemaker
  2014-05-04  5:39       ` Michael Haggerty
  1 sibling, 1 reply; 8+ messages in thread
From: Dennis Kaarsemaker @ 2014-05-03  7:35 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: Keith Derrick, git, simon.busch

On vr, 2014-05-02 at 15:16 -0700, Jonathan Nieder wrote:
> >     $ git checkout -b hotfix/b2
> >     error: unable to resolve reference refs/heads/hotfix/b2: Not a
> directory
> >     fatal: Failed to lock ref for update: Not a directory
> >     $
> 
> That's an ugly message.  I think we can do better. (hint hint)

2.0.0-rc2 has a better message already:

$ git checkout -b hotfix/b2
error: 'refs/heads/hotfix' exists; cannot create 'refs/heads/hotfix/b2'
fatal: Failed to lock ref for update: Not a directory


-- 
Dennis Kaarsemaker
www.kaarsemaker.net

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: BUG or FEATURE? Use of '/' in branch names
  2014-05-03  7:35     ` Dennis Kaarsemaker
@ 2014-05-04  5:39       ` Michael Haggerty
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Haggerty @ 2014-05-04  5:39 UTC (permalink / raw)
  To: Dennis Kaarsemaker, Jonathan Nieder; +Cc: Keith Derrick, git, simon.busch

On 05/03/2014 09:35 AM, Dennis Kaarsemaker wrote:
> On vr, 2014-05-02 at 15:16 -0700, Jonathan Nieder wrote:
>>>     $ git checkout -b hotfix/b2
>>>     error: unable to resolve reference refs/heads/hotfix/b2: Not a
>> directory
>>>     fatal: Failed to lock ref for update: Not a directory
>>>     $
>>
>> That's an ugly message.  I think we can do better. (hint hint)
> 
> 2.0.0-rc2 has a better message already:
> 
> $ git checkout -b hotfix/b2
> error: 'refs/heads/hotfix' exists; cannot create 'refs/heads/hotfix/b2'
> fatal: Failed to lock ref for update: Not a directory

I was trying to remember when this was changed, but at first I couldn't
reproduce the "fixed" error message at all.  Finally I figured out that
the the error message that you get depends on whether the existing
reference is loose:

    $ bin-wrappers/git checkout -b master/foo
    error: unable to resolve reference refs/heads/master/foo: Not a
directory
    fatal: Failed to lock ref for update: Not a directory

vs. packed:

    $ bin-wrappers/git checkout -b base/foo
    error: 'refs/heads/base' exists; cannot create 'refs/heads/base/foo'
    fatal: Failed to lock ref for update: Not a directory

It would be good to make the error message uniform and to document this
restriction.

Michael

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-04  5:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5363D1B4.1000503@lge.com>
2014-05-02 22:04 ` BUG or FEATURE? Use of '/' in branch names Keith Derrick
2014-05-02 22:10   ` Felipe Contreras
2014-05-02 22:16   ` Junio C Hamano
2014-05-02 22:16   ` Jonathan Nieder
2014-05-02 22:36     ` Keith Derrick
2014-05-02 22:43       ` Jonathan Nieder
2014-05-03  7:35     ` Dennis Kaarsemaker
2014-05-04  5:39       ` Michael Haggerty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).