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

This commit is contained in:
Shawn Pearce 2013-03-04 17:53:02 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit 22625cd1d8
2 changed files with 31 additions and 5 deletions

View File

@ -50,6 +50,7 @@
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.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 void setUp() throws Exception {
@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 void testCloneRepository() throws IOException,
"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

View File

@ -154,12 +154,13 @@ private FetchResult fetch(Repository clonedRepo, URIish u)
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 @@ private FetchResult fetch(Repository clonedRepo, URIish u)
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);