Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce2011-11-29 02:59:52 +0000
committerCode Review2011-11-29 02:59:52 +0000
commite9f20c982a0eddad826f4fe6d3c8ff691106eda4 (patch)
treebc386e9e1a2f77e4d31c4ed30f6c6fdc001d045e
parent47ef4db6bbb7a8c87ea67cec18f8f85b35d41a0c (diff)
parent899114f63c24223b697afb42e1564fc21a3b622d (diff)
downloadjgit-e9f20c982a0eddad826f4fe6d3c8ff691106eda4.tar.gz
jgit-e9f20c982a0eddad826f4fe6d3c8ff691106eda4.tar.xz
jgit-e9f20c982a0eddad826f4fe6d3c8ff691106eda4.zip
Merge "Always checkout master when it matches the advertised HEAD"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java6
2 files changed, 22 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
index f16fe83d6a..0e9f6721c7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
@@ -236,4 +236,20 @@ public class CloneCommandTest extends RepositoryTestCase {
assertTrue(e.getMessage().contains(dirName));
}
}
+
+ @Test
+ public void testCloneRepositoryWithMultipleHeadBranches() throws Exception {
+ git.checkout().setName(Constants.MASTER).call();
+ git.branchCreate().setName("a").call();
+
+ File directory = createTempDirectory("testCloneRepositoryWithMultipleHeadBranches");
+ CloneCommand clone = Git.cloneRepository();
+ clone.setDirectory(directory);
+ clone.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ Git git2 = clone.call();
+ addRepoToClose(git2.getRepository());
+ assertNotNull(git2);
+
+ assertEquals(Constants.MASTER, git2.getRepository().getBranch());
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index dbc126e895..b779c488aa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -229,6 +229,12 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
if (idHEAD == null)
return null;
+
+ Ref master = result.getAdvertisedRef(Constants.R_HEADS
+ + Constants.MASTER);
+ if (master != null && master.getObjectId().equals(idHEAD.getObjectId()))
+ return master;
+
Ref foundBranch = null;
for (final Ref r : result.getAdvertisedRefs()) {
final String n = r.getName();

Back to the top