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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]