Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 364853

Summary: Always checkout master when it matches the advertised HEAD
Product: [Technology] JGit Reporter: Tomasz Zarna <tomasz.zarna>
Component: JGitAssignee: Kevin Sawicki <kevin>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 1.2   
Target Milestone: 1.2   
Hardware: PC   
OS: Windows XP   
URL: http://egit.eclipse.org/r/#change,4687
Whiteboard:

Description Tomasz Zarna CLA 2011-11-25 11:41:02 EST
Steps:
1. Clone a repo
2. Create a new branch
3. Push it with the "--all" option
4. Clone the same repo again, to a different location
=> SHOULD BE: the current branch in the second repo = "master"
=> IS: the branch created in 2.
Comment 1 Tomasz Zarna CLA 2011-11-25 11:51:54 EST
A failing test case: http://egit.eclipse.org/r/4675
Comment 2 Kevin Sawicki CLA 2011-11-26 17:49:13 EST
I'm seeing the same behavior using the Git command-line
Comment 3 Tomasz Zarna CLA 2011-11-28 03:56:34 EST
Here is a minimal chain of commands I use to reproduce it in the Git CLI:

mkdir repo;cd repo;git init --bare;cd ..;git clone repo clone1;cd clone1;echo "f" > f;git add .;git commit -m 'init';git branch a;git push --all;cd ..;git clone repo clone2;cd clone2;git branch

The result of the last one is:

* master
Comment 4 Kevin Sawicki CLA 2011-11-28 13:31:22 EST
I'm not sure this is related to the --all option.

It looks like the JGit CloneCommand uses the first ref matching head to check out when cloning, while the command line makes a special case for master if multiple advertised refs that match head are found.

https://github.com/git/git/blob/b7f9bbd8754110b18535c5df293c3cb70a023e18/remote.c#L1579-1583

I pushed a change http://egit.eclipse.org/r/#change,4687 that special cases master similarly in JGit
Comment 5 Tomasz Zarna CLA 2011-11-28 14:28:36 EST
(In reply to comment #4)
> I pushed a change http://egit.eclipse.org/r/#change,4687 that special cases
> master similarly in JGit

Cool, the testCloneRepositoryWithMultipleHeadBranches test you added looks like a better version of my test from http://egit.eclipse.org/r/#change,4675. Is it ok to abandon the latter?
Comment 6 Kevin Sawicki CLA 2011-11-28 18:36:39 EST
> Is it ok to abandon the latter?

I think it is
Comment 7 Tomasz Zarna CLA 2011-11-29 04:21:36 EST
Done. I've changed the summary so it matches with your change's name.

The change has been merged, I'm matching the bug as fixed. Thanks Kev.