in javatests/com/googlesource/gerrit/plugins/supermanifest/JiriSuperManifestIT.java [93:195]
public void basicFunctionalityWorks() throws Exception {
setupTestRepos("project");
// Make sure the manifest exists so the configuration loads successfully.
Project.NameKey manifestKey = projectOperations.newProject().name(name("manifest")).create();
TestRepository<InMemoryRepository> manifestRepo = cloneProject(manifestKey, admin);
Project.NameKey superKey = projectOperations.newProject().name(name("superproject")).create();
cloneProject(superKey, admin);
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"
+ "</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");
Config base = new Config();
BlobBasedConfig cfg =
new BlobBasedConfig(base, branch.file(".gitmodules").asString().getBytes(UTF_8));
assertThat(cfg.getString("submodule", "project1", "branch")).isEqualTo("master");
assertThrows(ResourceNotFoundException.class, () -> branch.file("project2"));
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=\""
+ testRepoKeys[1].get()
+ "\" remote=\""
+ canonicalWebUrl.get()
+ testRepoKeys[1].get()
+ "\" path=\"project2\" />\n"
+ "</projects>\n</manifest>\n";
pushFactory
.create(admin.newIdent(), manifestRepo, "Subject", "default", xml)
.to("refs/heads/srcbranch")
.assertOkStatus();
BranchApi branch2 = gApi.projects().name(superKey.get()).branch("refs/heads/destbranch");
assertThat(branch2.file("project2").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8");
// Make sure config change gets picked up.
pushConfig(
"[superproject \""
+ superKey.get()
+ ":refs/heads/other\"]\n"
+ " srcRepo = "
+ manifestKey.get()
+ "\n"
+ " srcRef = refs/heads/srcbranch\n"
+ " srcPath = default\n"
+ " toolType = jiri\n");
// Push another XML change; this should trigger a commit using the new config.
xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<manifest>\n<projects>\n"
+ " <project name=\""
+ testRepoKeys[1].get()
+ "\" remote=\""
+ canonicalWebUrl.get()
+ testRepoKeys[1].get()
+ "\" path=\"project3\" />\n"
+ "</projects>\n</manifest>\n";
pushFactory
.create(admin.newIdent(), manifestRepo, "Subject", "default", xml)
.to("refs/heads/srcbranch")
.assertOkStatus();
BranchApi branch3 = gApi.projects().name(superKey.get()).branch("refs/heads/other");
assertThat(branch3.file("project3").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8");
}