diff options
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java | 60 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 6 |
2 files changed, 65 insertions, 1 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 72cc51be98..ce11e1b1bc 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 @@ -202,6 +202,66 @@ public class CloneCommandTest extends RepositoryTestCase { fetchRefSpec(git2.getRepository())); } + @Test + public void testCloneRepositoryCustomRemote() throws Exception { + File directory = createTempDirectory("testCloneRemoteUpstream"); + CloneCommand command = Git.cloneRepository(); + command.setDirectory(directory); + command.setRemote("upstream"); + command.setURI(fileUri()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertEquals("+refs/heads/*:refs/remotes/upstream/*", + git2.getRepository() + .getConfig() + .getStringList("remote", "upstream", + "fetch")[0]); + assertEquals("upstream", + git2.getRepository() + .getConfig() + .getString("branch", "test", "remote")); + assertEquals(db.resolve("test"), + git2.getRepository().resolve("upstream/test")); + } + + @Test + public void testBareCloneRepositoryCustomRemote() throws Exception { + File directory = createTempDirectory("testCloneRemoteUpstream_bare"); + CloneCommand command = Git.cloneRepository(); + command.setBare(true); + command.setDirectory(directory); + command.setRemote("upstream"); + command.setURI(fileUri()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertEquals("+refs/heads/*:refs/heads/*", + git2.getRepository() + .getConfig() + .getStringList("remote", "upstream", + "fetch")[0]); + assertEquals("upstream", + git2.getRepository() + .getConfig() + .getString("branch", "test", "remote")); + assertNull(git2.getRepository().resolve("upstream/test")); + } + + @Test + public void testBareCloneRepositoryNullRemote() throws Exception { + File directory = createTempDirectory("testCloneRemoteNull_bare"); + CloneCommand command = Git.cloneRepository(); + command.setBare(true); + command.setDirectory(directory); + command.setRemote(null); + command.setURI(fileUri()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertEquals("+refs/heads/*:refs/heads/*", git2.getRepository() + .getConfig().getStringList("remote", "origin", "fetch")[0]); + assertEquals("origin", git2.getRepository().getConfig() + .getString("branch", "test", "remote")); + } + public static RefSpec fetchRefSpec(Repository r) throws URISyntaxException { RemoteConfig remoteConfig = new RemoteConfig(r.getConfig(), Constants.DEFAULT_REMOTE_NAME); 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 5ea8398741..20d06331d2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -403,10 +403,14 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { * * @see Constants#DEFAULT_REMOTE_NAME * @param remote - * name that keeps track of the upstream repository + * name that keeps track of the upstream repository. + * {@code null} means to use DEFAULT_REMOTE_NAME. * @return this instance */ public CloneCommand setRemote(String remote) { + if (remote == null) { + remote = Constants.DEFAULT_REMOTE_NAME; + } this.remote = remote; return this; } |