Browse Source

Merge "Fix corrupted CloneCommand bare-repo fetch-refspec (#402031)"

stable-3.0
Shawn Pearce 12 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
22625cd1d8
  1. 27
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
  2. 9
      org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

27
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

9
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);

Loading…
Cancel
Save