{"thread":{"id":"36569","subject":"BUG or FEATURE? Use of '/' in branch names","startedAt":"2014-05-02T22:04:29Z","lastAt":"2014-05-04T05:39:48Z","messageCount":8,"participants":["Keith Derrick","Junio C Hamano","Jonathan Nieder","Felipe Contreras","Dennis Kaarsemaker","Michael Haggerty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"240580","messageId":"AAC0CF0A2CCEC34CBE983015FD81C4F7392A504B61@AICEXMBXCL02.LGE.NET","threadId":"36569","inReplyTo":"5363D1B4.1000503@lge.com","subject":"BUG or FEATURE? Use of '/' in branch names","fromName":"Keith Derrick","fromEmail":"keith.derrick@lge.com","sentAt":"2014-05-02T22:04:29Z","receivedAt":"2014-05-02T22:04:29Z","isPatch":false,"sender":{"key":"keith.derrick@lge.com","avatar":null},"body":"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.\n\n\ngit imposes the following rules on how references are named:\n1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.\n\n\ngit-flow, for example,  uses it extensively to prefix branches with 'release/', 'bugfix/', 'hotfix/' etc.\n\nHowever, I just ran into the following problem\n\n\n    $git init\n    Initialized empty Git repository in /home/keith/play/bug2/.git/\n    $touch a\n    $git add a\n    $git commit -m \"C1\"\n    [master (root-commit) d569d5b] C1\n     1 file changed, 0 insertions(+), 0 deletions(-)\n     create mode 100644 a\n    $git checkout -b hotfix\n    Switched to a new branch 'hotfix'\n    $git checkout -b hotfix/b2\n    error: unable to resolve reference refs/heads/hotfix/b2: Not a directory\n    fatal: Failed to lock ref for update: Not a directory\n    $\n\nThe problem arises when a branch already exists with a name matching the stem of the new branch name.\n\nAs 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.\n\nNote, however that this works\n\n    $git init\n    Initialized empty Git repository in /home/keith/play/bug3/.git/\n    $touch a\n    $git add a && git commit -m 'C1'\n    [master (root-commit) 304052c] C1\n     1 file changed, 0 insertions(+), 0 deletions(-)\n     create mode 100644 a\n    $git checkout -b hotfix/b1\n    Switched to a new branch 'hotfix/b1'\n    $git checkout -b hotfix/b2\n    Switched to a new branch 'hotfix/b2'\n    $ls .git/refs/heads/ -R\n    .git/refs/heads/:\n    hotfix  master\n\n    .git/refs/heads/hotfix:\n    b1  b2\n    $\n\nBut, for the reverse reason, I can't now create the branch named 'hotfix'\n\nI 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'?\n\nI 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.\n\nRenaming the existing published branches is not an option for us, I'm afraid.\n"},{"id":"240586","messageId":"536417ecd0104_1c7bdcd2f0b9@nysa.notmuch","threadId":"36569","inReplyTo":"AAC0CF0A2CCEC34CBE983015FD81C4F7392A504B61@AICEXMBXCL02.LGE.NET","subject":"RE: BUG or FEATURE? Use of '/' in branch names","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2014-05-02T22:10:52Z","receivedAt":"2014-05-02T22:10:52Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Keith Derrick wrote:\n> I can see the value in grouping branches in a directory tree under\n> refs/heads, but wouldn't it make more sense to simply escape the '/'\n> in the branch name so that 'hotfix/b1' is stored on disk as\n> 'hotfix\\/b1'?\n\nThis would be nice for remote helpers: Mercurial can have \"hotfix\" and\n\"hotifx/b1\", so importing such a Mercurial repository creates problems.\n\n-- \nFelipe Contreras\n"},{"id":"240584","messageId":"xmqq61lnakt4.fsf@gitster.dls.corp.google.com","threadId":"36569","inReplyTo":"AAC0CF0A2CCEC34CBE983015FD81C4F7392A504B61@AICEXMBXCL02.LGE.NET","subject":"Re: BUG or FEATURE? Use of '/' in branch names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-05-02T22:16:07Z","receivedAt":"2014-05-02T22:16:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Keith Derrick <keith.derrick@lge.com> writes:\n\n> The problem arises when a branch already exists with a name\n> matching the stem of the new branch name.\n> ...\n> But, for the reverse reason, I can't now create the branch named 'hotfix'\n\nAll correct.  Allowing '/' in branch names came about not with a\ncareful design but was done by a happy accident, and we accepted it\nunder the condition \"as long as users know that they cannot have\nbranches D and D/F at the same time, that is fine\".\n\nAn obvious alternative convention you can adopt would be to use not\n'/' but some other separating characters (e.g. \"_\") as your\nhierarchy delimiter, if you must have D and D_F at the same time.\n"},{"id":"240585","messageId":"20140502221617.GO9218@google.com","threadId":"36569","inReplyTo":"AAC0CF0A2CCEC34CBE983015FD81C4F7392A504B61@AICEXMBXCL02.LGE.NET","subject":"Re: BUG or FEATURE? Use of '/' in branch names","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-05-02T22:16:17Z","receivedAt":"2014-05-02T22:16:17Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Keith,\n\nKeith Derrick wrote:\n\n>     $ git checkout -b hotfix\n>     Switched to a new branch 'hotfix'\n>     $ git checkout -b hotfix/b2\n>     error: unable to resolve reference refs/heads/hotfix/b2: Not a directory\n>     fatal: Failed to lock ref for update: Not a directory\n>     $\n\nThat's an ugly message.  I think we can do better. (hint hint)\n\nLonger term, I think people would like to make it possible for a\n'hotfix' and 'hotfix/b2' branch to coexist, but that will take some\nwork, and until then, git tries to be careful about enforcing the\nconstraint that they cannot coexist.\n\nFixing it would be complicated by the need to avoid breaking people\nwith older versions of git when they fetch from you (what happens to\nthe origin/hotfix and origin/hotfix/b2 remote-tracking refs on the\nclient side?).\n\nThanks and hope that helps,\nJonathan\n"},{"id":"240591","messageId":"53641E0B.5000706@lge.com","threadId":"36569","inReplyTo":"20140502221617.GO9218@google.com","subject":"Re: BUG or FEATURE? Use of '/' in branch names","fromName":"Keith Derrick","fromEmail":"keith.derrick@lge.com","sentAt":"2014-05-02T22:36:59Z","receivedAt":"2014-05-02T22:36:59Z","isPatch":false,"sender":{"key":"keith.derrick@lge.com","avatar":null},"body":"Yes, I've since found some discussion on this, and had already changed \nto use '-' to append the classifier.\n\nBut the other problem is that I can't easily find this restriction \ndocumented anywhere - which means it comes as a suprise to people.\n\nAs it stands, the documentation implies that what I tried should work. \nIn which case, how it's been *implemented* seems to be breaking the \npromise of the functional specification (if you view the documentation \nas such).\n\nKeith\n\nOn 05/02/2014 03:16 PM, Jonathan Nieder wrote:\n> Hi Keith,\n>\n> Keith Derrick wrote:\n>\n>>      $ git checkout -b hotfix\n>>      Switched to a new branch 'hotfix'\n>>      $ git checkout -b hotfix/b2\n>>      error: unable to resolve reference refs/heads/hotfix/b2: Not a directory\n>>      fatal: Failed to lock ref for update: Not a directory\n>>      $\n> That's an ugly message.  I think we can do better. (hint hint)\n>\n> Longer term, I think people would like to make it possible for a\n> 'hotfix' and 'hotfix/b2' branch to coexist, but that will take some\n> work, and until then, git tries to be careful about enforcing the\n> constraint that they cannot coexist.\n>\n> Fixing it would be complicated by the need to avoid breaking people\n> with older versions of git when they fetch from you (what happens to\n> the origin/hotfix and origin/hotfix/b2 remote-tracking refs on the\n> client side?).\n>\n> Thanks and hope that helps,\n> Jonathan\n"},{"id":"240592","messageId":"20140502224312.GP9218@google.com","threadId":"36569","inReplyTo":"53641E0B.5000706@lge.com","subject":"Re: BUG or FEATURE? Use of '/' in branch names","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-05-02T22:43:12Z","receivedAt":"2014-05-02T22:43:12Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nKeith Derrick wrote:\n\n> Yes, I've since found some discussion on this, and had already changed \n> to use '-' to append the classifier.\n>\n> But the other problem is that I can't easily find this restriction \n> documented anywhere - which means it comes as a suprise to people.\n\nThat sounds like another serious bug (the first one was the lousy\nerror message).  The current behavior is intended, and it sounds like\nthe documentation is lagging.\n\nWhere did you expect to find information about this?  Knowing that\nwould help a lot in fixing it.\n\n(The nicest way to indicate where you expected to read about this\nis with a patch against the relevant file in Documentation/*.txt,\nof course.)\n\nThanks again,\nJonathan\n"},{"id":"240613","messageId":"1399102525.2716.1.camel@spirit","threadId":"36569","inReplyTo":"20140502221617.GO9218@google.com","subject":"Re: BUG or FEATURE? Use of '/' in branch names","fromName":"Dennis Kaarsemaker","fromEmail":"dennis@kaarsemaker.net","sentAt":"2014-05-03T07:35:25Z","receivedAt":"2014-05-03T07:35:25Z","isPatch":false,"sender":{"key":"dennis@kaarsemaker.net","avatar":"https://avatars.githubusercontent.com/u/200649?v=4"},"body":"On vr, 2014-05-02 at 15:16 -0700, Jonathan Nieder wrote:\n> >     $ git checkout -b hotfix/b2\n> >     error: unable to resolve reference refs/heads/hotfix/b2: Not a\n> directory\n> >     fatal: Failed to lock ref for update: Not a directory\n> >     $\n> \n> That's an ugly message.  I think we can do better. (hint hint)\n\n2.0.0-rc2 has a better message already:\n\n$ git checkout -b hotfix/b2\nerror: 'refs/heads/hotfix' exists; cannot create 'refs/heads/hotfix/b2'\nfatal: Failed to lock ref for update: Not a directory\n\n\n-- \nDennis Kaarsemaker\nwww.kaarsemaker.net\n"},{"id":"240660","messageId":"5365D2A4.9010702@alum.mit.edu","threadId":"36569","inReplyTo":"1399102525.2716.1.camel@spirit","subject":"Re: BUG or FEATURE? Use of '/' in branch names","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-05-04T05:39:48Z","receivedAt":"2014-05-04T05:39:48Z","isPatch":false,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 05/03/2014 09:35 AM, Dennis Kaarsemaker wrote:\n> On vr, 2014-05-02 at 15:16 -0700, Jonathan Nieder wrote:\n>>>     $ git checkout -b hotfix/b2\n>>>     error: unable to resolve reference refs/heads/hotfix/b2: Not a\n>> directory\n>>>     fatal: Failed to lock ref for update: Not a directory\n>>>     $\n>>\n>> That's an ugly message.  I think we can do better. (hint hint)\n> \n> 2.0.0-rc2 has a better message already:\n> \n> $ git checkout -b hotfix/b2\n> error: 'refs/heads/hotfix' exists; cannot create 'refs/heads/hotfix/b2'\n> fatal: Failed to lock ref for update: Not a directory\n\nI was trying to remember when this was changed, but at first I couldn't\nreproduce the \"fixed\" error message at all.  Finally I figured out that\nthe the error message that you get depends on whether the existing\nreference is loose:\n\n    $ bin-wrappers/git checkout -b master/foo\n    error: unable to resolve reference refs/heads/master/foo: Not a\ndirectory\n    fatal: Failed to lock ref for update: Not a directory\n\nvs. packed:\n\n    $ bin-wrappers/git checkout -b base/foo\n    error: 'refs/heads/base' exists; cannot create 'refs/heads/base/foo'\n    fatal: Failed to lock ref for update: Not a directory\n\nIt would be good to make the error message uniform and to document this\nrestriction.\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"}]}