Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 364853 - Always checkout master when it matches the advertised HEAD
Summary: Always checkout master when it matches the advertised HEAD
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.2   Edit
Assignee: Kevin Sawicki CLA
QA Contact:
URL: http://egit.eclipse.org/r/#change,4687
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-25 11:41 EST by Tomasz Zarna CLA
Modified: 2011-11-29 04:21 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.