1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.api;
11
12 import static org.junit.Assert.assertEquals;
13
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16
17 import org.eclipse.jgit.junit.RepositoryTestCase;
18 import org.eclipse.jgit.lib.Constants;
19 import org.eclipse.jgit.lib.Repository;
20 import org.eclipse.jgit.lib.StoredConfig;
21 import org.eclipse.jgit.transport.RefSpec;
22 import org.eclipse.jgit.transport.RemoteConfig;
23 import org.eclipse.jgit.transport.URIish;
24
25 public class AbstractRemoteCommandTest extends RepositoryTestCase {
26
27 protected static final String REMOTE_NAME = "test";
28
29 protected RemoteConfig setupRemote()
30 throws IOException, URISyntaxException {
31
32 Repository remoteRepository = createWorkRepository();
33
34
35 final StoredConfig config = db.getConfig();
36 RemoteConfig remoteConfig = new RemoteConfig(config, REMOTE_NAME);
37
38 RefSpec refSpec = new RefSpec();
39 refSpec = refSpec.setForceUpdate(true);
40 refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*",
41 Constants.R_REMOTES + REMOTE_NAME + "/*");
42 remoteConfig.addFetchRefSpec(refSpec);
43
44 URIish uri = new URIish(
45 remoteRepository.getDirectory().toURI().toURL());
46 remoteConfig.addURI(uri);
47
48 remoteConfig.update(config);
49 config.save();
50
51 return remoteConfig;
52 }
53
54 protected void assertRemoteConfigEquals(RemoteConfig expected,
55 RemoteConfig actual) {
56 assertEquals(expected.getName(), actual.getName());
57 assertEquals(expected.getURIs(), actual.getURIs());
58 assertEquals(expected.getPushURIs(), actual.getPushURIs());
59 assertEquals(expected.getFetchRefSpecs(), actual.getFetchRefSpecs());
60 assertEquals(expected.getPushRefSpecs(), actual.getPushRefSpecs());
61 }
62
63 }