summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2013-03-04 17:53:02 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-03-04 17:53:02 -0500
commit22625cd1d89257d9564d87c9bbbe8f4863c413e3 (patch)
tree240eab307d3d1742bc59f8fde963999cae729a40
parent8d4f227c138bf3ccf13cf83ab63fde2fc49d3756 (diff)
parenta46b0429053288de4435ac26dc22f27f4ac43978 (diff)
downloadjgit-22625cd1d89257d9564d87c9bbbe8f4863c413e3.tar.gz
jgit-22625cd1d89257d9564d87c9bbbe8f4863c413e3.zip
Merge "Fix corrupted CloneCommand bare-repo fetch-refspec (#402031)"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java27
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java9
2 files changed, 31 insertions, 5 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 99e05d4d55..7422951920 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
@@ -50,6 +50,7 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -71,6 +72,8 @@ import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.submodule.SubmoduleStatus;
import org.eclipse.jgit.submodule.SubmoduleStatusType;
import org.eclipse.jgit.submodule.SubmoduleWalk;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Test;
@@ -105,7 +108,7 @@ public class CloneCommandTest extends RepositoryTestCase {
@Test
public void testCloneRepository() throws IOException,
- JGitInternalException, GitAPIException {
+ JGitInternalException, GitAPIException, URISyntaxException {
File directory = createTempDirectory("testCloneRepository");
CloneCommand command = Git.cloneRepository();
command.setDirectory(directory);
@@ -130,6 +133,28 @@ public class CloneCommandTest extends RepositoryTestCase {
"test", ConfigConstants.CONFIG_KEY_MERGE));
assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE).call()
.size());
+ assertEquals(new RefSpec("+refs/heads/*:refs/remotes/origin/*"),
+ fetchRefSpec(git2.getRepository()));
+ }
+
+ @Test
+ public void testBareCloneRepository() throws IOException,
+ JGitInternalException, GitAPIException, URISyntaxException {
+ File directory = createTempDirectory("testCloneRepository_bare");
+ CloneCommand command = Git.cloneRepository();
+ command.setBare(true);
+ command.setDirectory(directory);
+ command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+ assertEquals(new RefSpec("+refs/heads/*:refs/heads/*"),
+ fetchRefSpec(git2.getRepository()));
+ }
+
+ public static RefSpec fetchRefSpec(Repository r) throws URISyntaxException {
+ RemoteConfig remoteConfig =
+ new RemoteConfig(r.getConfig(), Constants.DEFAULT_REMOTE_NAME);
+ return remoteConfig.getFetchRefSpecs().get(0);
}
@Test
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 22bda612fb..35bf75dcc4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -154,12 +154,13 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote);
config.addURI(u);
- final String dst = bare ? Constants.R_HEADS : Constants.R_REMOTES
- + config.getName();
+ final String dst = (bare ? Constants.R_HEADS : Constants.R_REMOTES
+ + config.getName() + "/") + "*";
RefSpec refSpec = new RefSpec();
refSpec = refSpec.setForceUpdate(true);
refSpec = refSpec.setSourceDestination(
- Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$
+ Constants.R_HEADS + "*", dst); //$NON-NLS-1$ //$NON-NLS-2$
+
config.addFetchRefSpec(refSpec);
config.update(clonedRepo.getConfig());
@@ -182,7 +183,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
private List<RefSpec> calculateRefSpecs(final String dst) {
RefSpec wcrs = new RefSpec();
wcrs = wcrs.setForceUpdate(true);
- wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst + "/*"); //$NON-NLS-1$ //$NON-NLS-2$
+ wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst); //$NON-NLS-1$ //$NON-NLS-2$
List<RefSpec> specs = new ArrayList<RefSpec>();
if (cloneAllBranches)
specs.add(wcrs);