Exemplo n.º 1
0
  @Test
  public void testRemoveOnlyURI() throws Exception {
    readConfig("");

    final URIish a = new URIish("/some/dir");
    final RemoteConfig rc = new RemoteConfig(config, "backup");
    assertTrue(rc.addURI(a));

    assertEquals(1, rc.getURIs().size());
    assertSame(a, rc.getURIs().get(0));

    assertTrue(rc.removeURI(a));
    assertEquals(0, rc.getURIs().size());
  }
Exemplo n.º 2
0
 private static List<URIish> getURIs(final RemoteConfig cfg, final Operation op) {
   switch (op) {
     case FETCH:
       return cfg.getURIs();
     case PUSH:
       {
         List<URIish> uris = cfg.getPushURIs();
         if (uris.isEmpty()) uris = cfg.getURIs();
         return uris;
       }
     default:
       throw new IllegalArgumentException(op.toString());
   }
 }
Exemplo n.º 3
0
  @Test
  public void testAddURI() throws Exception {
    readConfig("");

    final URIish uri = new URIish("/some/dir");
    final RemoteConfig rc = new RemoteConfig(config, "backup");
    assertEquals(0, rc.getURIs().size());

    assertTrue(rc.addURI(uri));
    assertEquals(1, rc.getURIs().size());
    assertSame(uri, rc.getURIs().get(0));

    assertFalse(rc.addURI(new URIish(uri.toString())));
    assertEquals(1, rc.getURIs().size());
  }
Exemplo n.º 4
0
  @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());
  }
Exemplo n.º 5
0
  @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());
  }
Exemplo n.º 6
0
  @Test
  public void testSaveRemoveFirstURI() throws Exception {
    readConfig(
        "[remote \"spearce\"]\n"
            + "url = http://www.spearce.org/egit.git\n"
            + "url = /some/dir\n"
            + "fetch = +refs/heads/*:refs/remotes/spearce/*\n");

    final RemoteConfig rc = new RemoteConfig(config, "spearce");
    assertEquals(2, rc.getURIs().size());
    rc.removeURI(new URIish("http://www.spearce.org/egit.git"));
    assertEquals(1, rc.getURIs().size());
    rc.update(config);
    checkConfig(
        "[remote \"spearce\"]\n"
            + "\turl = /some/dir\n"
            + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n");
  }
Exemplo n.º 7
0
  @Test
  public void testUnknown() throws Exception {
    readConfig("");

    final RemoteConfig rc = new RemoteConfig(config, "backup");
    assertEquals(0, rc.getURIs().size());
    assertEquals(0, rc.getFetchRefSpecs().size());
    assertEquals(0, rc.getPushRefSpecs().size());
    assertEquals("git-upload-pack", rc.getUploadPack());
    assertEquals("git-receive-pack", rc.getReceivePack());
  }
Exemplo n.º 8
0
  @Test
  public void testRemoveLastURI() throws Exception {
    readConfig("");

    final URIish a = new URIish("/some/dir");
    final URIish b = new URIish("/another/dir");
    final URIish c = new URIish("/more/dirs");
    final RemoteConfig rc = new RemoteConfig(config, "backup");
    assertTrue(rc.addURI(a));
    assertTrue(rc.addURI(b));
    assertTrue(rc.addURI(c));

    assertEquals(3, rc.getURIs().size());
    assertSame(a, rc.getURIs().get(0));
    assertSame(b, rc.getURIs().get(1));
    assertSame(c, rc.getURIs().get(2));

    assertTrue(rc.removeURI(c));
    assertEquals(2, rc.getURIs().size());
    assertSame(a, rc.getURIs().get(0));
    assertSame(b, rc.getURIs().get(1));
  }
Exemplo n.º 9
0
  @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());
  }
Exemplo n.º 10
0
 private static boolean doesNotExist(final RemoteConfig cfg) {
   return cfg.getURIs().isEmpty() && cfg.getPushURIs().isEmpty();
 }