Browse Source

Merge "Always checkout master when it matches the advertised HEAD"

stable-1.2
Shawn Pearce 13 years ago committed by Code Review
parent
commit
e9f20c982a
  1. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
  2. 6
      org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

16
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)); 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());
}
} }

6
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); final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
if (idHEAD == null) if (idHEAD == null)
return 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; Ref foundBranch = null;
for (final Ref r : result.getAdvertisedRefs()) { for (final Ref r : result.getAdvertisedRefs()) {
final String n = r.getName(); final String n = r.getName();

Loading…
Cancel
Save