public void relativeFetch()

in javatests/com/googlesource/gerrit/plugins/supermanifest/JiriSuperManifestIT.java [544:634]


  public void relativeFetch() throws Exception {
    // Test that first party gerrit repos are represented by relative URLs in supermanifest and
    // external repos by their absolute URLs.
    setupTestRepos("platform/project");

    String realPrefix = testRepoKeys[0].get().split("/")[0];

    Project.NameKey manifestKey =
        projectOperations.newProject().name(name(realPrefix + "/manifest")).create();
    TestRepository<InMemoryRepository> manifestRepo = cloneProject(manifestKey, admin);

    Project.NameKey superKey = projectOperations.newProject().name(name("superproject")).create();
    pushConfig(
        "[superproject \""
            + superKey.get()
            + ":refs/heads/destbranch\"]\n"
            + "  srcRepo = "
            + manifestKey.get()
            + "\n"
            + "  srcRef = refs/heads/srcbranch\n"
            + "  srcPath = default\n"
            + "  toolType = jiri\n");

    // XML change will trigger commit to superproject.
    String xml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<manifest>\n<projects>\n"
            + "<project name=\""
            + testRepoKeys[0].get()
            + "\" remote=\""
            + canonicalWebUrl.get()
            + testRepoKeys[0].get()
            + "\" path=\"project1\" />\n"
            + "<project name=\"external1\""
            + " remote=\"https://external/repo\""
            + " revision=\"c438d02cdf08a08fe29550cb11cb6ae8190919f1\""
            + " path=\"project2\" />\n"
            + "<project name=\"external2\""
            + " remote=\"https://external/"
            + testRepoKeys[1].get()
            + "\""
            + " revision=\"c438d02cdf08a08fe29550cb11cb6ae8190919f1\""
            + " path=\"project3\" />\n"
            + "</projects>\n</manifest>\n";

    pushFactory
        .create(admin.newIdent(), manifestRepo, "Subject", "default", xml)
        .to("refs/heads/srcbranch")
        .assertOkStatus();

    BranchApi branch = gApi.projects().name(superKey.get()).branch("refs/heads/destbranch");
    assertThat(branch.file("project1").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8");
    assertThat(branch.file("project2").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8");

    Config base = new Config();
    BlobBasedConfig cfg =
        new BlobBasedConfig(base, branch.file(".gitmodules").asString().getBytes(UTF_8));

    String subUrl = cfg.getString("submodule", "project1", "url");

    // URL is valid.
    URI.create(subUrl);

    // The suburl must be interpreted as relative to the parent project as a directory, i.e.
    // to go from superproject/ to platform/project0, you have to do ../platform/project0

    // URL is clean.
    assertThat(subUrl).isEqualTo("../" + realPrefix + "/project0");

    subUrl = cfg.getString("submodule", "project2", "url");

    // URL is valid.
    URI.create(subUrl);

    // The suburl must be absolute as this is external repo

    assertThat(subUrl).isEqualTo("https://external/repo");

    subUrl = cfg.getString("submodule", "project3", "url");

    // URL is valid.
    URI.create(subUrl);

    // Though the this project has the same name as a local repo, the subUrl must be absolute
    // as this is an external repo.
    assertThat(subUrl).isEqualTo("https://external/" + testRepoKeys[1].get());

    assertThat(cfg.getString("submodule", "project1", "branch")).isEqualTo("master");
    assertThat(cfg.getString("submodule", "project2", "branch")).isNull();
    assertThat(cfg.getString("submodule", "project3", "branch")).isNull();
  }