Issue 2080: git clone can be confused by having two names for the ref pointed to by HEAD
Status:  Invalid
Owner: ----
Closed:  Aug 2013
Reported by david.black.co.at@gmail.com, Aug 21, 2013
Affected Version: 2.6.1

What steps will reproduce the problem?
1. Create a repository with a few commits on master.
2. git push origin master:test master:devs/private
3. Update the HEAD on gerrit using git update-ref to refs/heads/test
3. Clone the repository into a new directory
4. Run "git branch" to display the current branch

What is the expected output? What do you see instead?

I'd expect this setup to clone a repo where the master branch is checked out, tracking origin/master. Instead it has checked out a_test and tracks that.


Please provide any additional information below.

Here're some cuts from my actual setup:

from the review_site/git:

    [root@gerrit bi-configuration.git]# head HEAD refs/heads/test refs/heads/devs/private
    ==> HEAD <==
    ref: refs/heads/test
     
    ==> refs/heads/test <==
    55b0681e2aa921c13459cf300940b516a9bcb435
     
    ==> refs/heads/devs/private <==
    55b0681e2aa921c13459cf300940b516a9bcb435
    [root@gerrit bi-configuration.git]#

from the clone:

    schmidav2@gerrit ~$ git clone ssh://schmidav@gerrit:29418/bi-configuration.git
    Initialized empty Git repository in /home/schmidav2/bi-configuration/.git/
    remote: Counting objects: 46924, done
    remote: Finding sources: 100% (46924/46924)
    remote: Total 46924 (delta 23719), reused 46924 (delta 23719)
    Receiving objects: 100% (46924/46924), 230.82 MiB | 18.18 MiB/s, done.
    Resolving deltas: 100% (23719/23719), done.
    schmidav2@gerrit ~$ cd bi-configuration/
    schmidav2@gerrit ~/bi-configuration$ git status
    # On branch devs/private
    nothing to commit (working directory clean)
    schmidav2@gerrit ~/bi-configuration$ git branch
    * devs/private
    schmidav2@gerrit ~/bi-configuration$ cd .git
    schmidav2@gerrit ~/bi-configuration/.git$ head HEAD refs/heads/devs/private refs/remotes/origin/HEAD 
    ==> HEAD <==
    ref: refs/heads/devs/private
     
    ==> refs/heads/devs/private <==
    55b0681e2aa921c13459cf300940b516a9bcb435
     
    ==> refs/remotes/origin/HEAD <==
    ref: refs/remotes/origin/devs/private
    schmidav2@gerrit ~/bi-configuration/.git$





Aug 21, 2013
Project Member #1 edwin.ke...@gmail.com
> I'd expect this setup to clone a repo
> where the master branch is checked out
Why? This expectation is wrong. After the clone you get a local branch for the remote branch to which HEAD is pointing in the remote repository. Since you have set HEAD in the remote repository to refs/heads/test it is correct that you get a test branch checked out locally after clone which tracks origin/test. That's whole purpose of having and setting HEAD in a bare remote repository.
Status: Invalid
Aug 21, 2013
Project Member #2 jrn@google.com
I think David mean that he expected a clone with branch "test" checked out instead of "devs/private".  But you're right that this isn't a Gerrit bug --- instead, it's a weakness in git's wire protocol (ls-remote only tells what commit HEAD points to, and the client uses that to guess which branch to check out, using heuristics like preferring "master" when more than one branch points to that commit).
Aug 22, 2013
#3 david.black.co.at@gmail.com
jrn has it right. I typoed there and would have expected "test" instead of "devs/private".

Thanks for the clarification.