Re: BUG or FEATURE? Use of '/' in branch names

2014-05-03 Thread Dennis Kaarsemaker
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

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG or FEATURE? Use of '/' in branch names

2014-05-03 Thread Michael Haggerty
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
mhag...@alum.mit.edu
http://softwareswirl.blogspot.com/
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


BUG or FEATURE? Use of '/' in branch names

2014-05-02 Thread Keith Derrick
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.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG or FEATURE? Use of '/' in branch names

2014-05-02 Thread Junio C Hamano
Keith Derrick keith.derr...@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.

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG or FEATURE? Use of '/' in branch names

2014-05-02 Thread Jonathan Nieder
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
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: BUG or FEATURE? Use of '/' in branch names

2014-05-02 Thread Felipe Contreras
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
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG or FEATURE? Use of '/' in branch names

2014-05-02 Thread Keith Derrick
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
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG or FEATURE? Use of '/' in branch names

2014-05-02 Thread Jonathan Nieder
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
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html