@Test public void testSimple() throws Exception { readConfig( "[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" + "fetch = +refs/heads/*:refs/remotes/spearce/*\n"); final RemoteConfig rc = new RemoteConfig(config, "spearce"); final List<URIish> allURIs = rc.getURIs(); RefSpec spec; assertEquals("spearce", rc.getName()); assertNotNull(allURIs); assertNotNull(rc.getFetchRefSpecs()); assertNotNull(rc.getPushRefSpecs()); assertNotNull(rc.getTagOpt()); assertEquals(0, rc.getTimeout()); assertSame(TagOpt.AUTO_FOLLOW, rc.getTagOpt()); assertEquals(1, allURIs.size()); assertEquals("http://www.spearce.org/egit.git", allURIs.get(0).toString()); assertEquals(1, rc.getFetchRefSpecs().size()); spec = rc.getFetchRefSpecs().get(0); assertTrue(spec.isForceUpdate()); assertTrue(spec.isWildcard()); assertEquals("refs/heads/*", spec.getSource()); assertEquals("refs/remotes/spearce/*", spec.getDestination()); assertEquals(0, rc.getPushRefSpecs().size()); }
@Test public void testUploadPack() throws Exception { readConfig( "[remote \"example\"]\n" + "url = [email protected]:egit.git\n" + "fetch = +refs/heads/*:refs/remotes/example/*\n" + "uploadpack = /path/to/git/git-upload-pack\n" + "receivepack = /path/to/git/git-receive-pack\n"); final RemoteConfig rc = new RemoteConfig(config, "example"); final List<URIish> allURIs = rc.getURIs(); RefSpec spec; assertEquals("example", rc.getName()); assertNotNull(allURIs); assertNotNull(rc.getFetchRefSpecs()); assertNotNull(rc.getPushRefSpecs()); assertEquals(1, allURIs.size()); assertEquals("[email protected]:egit.git", allURIs.get(0).toString()); assertEquals(1, rc.getFetchRefSpecs().size()); spec = rc.getFetchRefSpecs().get(0); assertTrue(spec.isForceUpdate()); assertTrue(spec.isWildcard()); assertEquals("refs/heads/*", spec.getSource()); assertEquals("refs/remotes/example/*", spec.getDestination()); assertEquals(0, rc.getPushRefSpecs().size()); assertEquals("/path/to/git/git-upload-pack", rc.getUploadPack()); assertEquals("/path/to/git/git-receive-pack", rc.getReceivePack()); }
/** * Open a new transport instance to connect two repositories. * * @param local existing local repository. * @param cfg configuration describing how to connect to the remote repository. * @param op planned use of the returned Transport; the URI may differ based on the type of * connection desired. * @return the new transport instance. Never null. In case of multiple URIs in remote * configuration, only the first is chosen. * @throws NotSupportedException the protocol specified is not supported. * @throws IllegalArgumentException if provided remote configuration doesn't have any URI * associated. */ public static Transport open(final Repository local, final RemoteConfig cfg, final Operation op) throws NotSupportedException { final List<URIish> uris = getURIs(cfg, op); if (uris.isEmpty()) throw new IllegalArgumentException( "Remote config \"" + cfg.getName() + "\" has no URIs associated"); final Transport tn = open(local, uris.get(0)); tn.applyConfig(cfg); return tn; }
@Test public void testCreateOrigin() throws Exception { final RemoteConfig rc = new RemoteConfig(config, "origin"); rc.addURI(new URIish("/some/dir")); rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.getName() + "/*")); rc.update(config); checkConfig( "[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"); }
@Test public void testSaveAllTags() throws Exception { final RemoteConfig rc = new RemoteConfig(config, "origin"); rc.addURI(new URIish("/some/dir")); rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.getName() + "/*")); rc.setTagOpt(TagOpt.FETCH_TAGS); rc.update(config); checkConfig( "[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n" + "\ttagopt = --tags\n"); }
@Test public void testBackup() throws Exception { readConfig( "[remote \"backup\"]\n" + "url = http://www.spearce.org/egit.git\n" + "url = [email protected]:/srv/git/egit.git\n" + "push = +refs/heads/*:refs/heads/*\n" + "push = refs/tags/*:refs/tags/*\n"); final RemoteConfig rc = new RemoteConfig(config, "backup"); final List<URIish> allURIs = rc.getURIs(); RefSpec spec; assertEquals("backup", rc.getName()); assertNotNull(allURIs); assertNotNull(rc.getFetchRefSpecs()); assertNotNull(rc.getPushRefSpecs()); assertEquals(2, allURIs.size()); assertEquals("http://www.spearce.org/egit.git", allURIs.get(0).toString()); assertEquals("[email protected]:/srv/git/egit.git", allURIs.get(1).toString()); assertEquals(0, rc.getFetchRefSpecs().size()); assertEquals(2, rc.getPushRefSpecs().size()); spec = rc.getPushRefSpecs().get(0); assertTrue(spec.isForceUpdate()); assertTrue(spec.isWildcard()); assertEquals("refs/heads/*", spec.getSource()); assertEquals("refs/heads/*", spec.getDestination()); spec = rc.getPushRefSpecs().get(1); assertFalse(spec.isForceUpdate()); assertTrue(spec.isWildcard()); assertEquals("refs/tags/*", spec.getSource()); assertEquals("refs/tags/*", spec.getDestination()); }