List of usage examples for org.eclipse.jgit.lib BlobBasedConfig BlobBasedConfig
public BlobBasedConfig(Config base, byte[] blob) throws ConfigInvalidException
From source file:com.gitblit.utils.JGitUtils.java
License:Apache License
/** * Returns the list of submodules for this repository. * * @param repository//from w w w .ja v a2 s.co m * @param commit * @return list of submodules */ public static List<SubmoduleModel> getSubmodules(Repository repository, RevTree tree) { List<SubmoduleModel> list = new ArrayList<SubmoduleModel>(); byte[] blob = getByteContent(repository, tree, ".gitmodules", false); if (blob == null) { return list; } try { BlobBasedConfig config = new BlobBasedConfig(repository.getConfig(), blob); for (String module : config.getSubsections("submodule")) { String path = config.getString("submodule", module, "path"); String url = config.getString("submodule", module, "url"); list.add(new SubmoduleModel(module, path, url)); } } catch (ConfigInvalidException e) { LOGGER.error("Failed to load .gitmodules file for " + repository.getDirectory(), e); } return list; }
From source file:com.googlesource.gerrit.plugins.supermanifest.JiriSuperManifestIT.java
License:Apache License
@Test 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=\"external\"" + " remote=\"https://external/repo\"" + " revision=\"c438d02cdf08a08fe29550cb11cb6ae8190919f1\"" + " path=\"project2\" />\n" + "</projects>\n</manifest>\n"; pushFactory.create(admin.getIdent(), manifestRepo, "Subject", "default", xml).to("refs/heads/srcbranch") .assertOkStatus();//w ww . j a v a 2 s.co m 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"); }
From source file:com.googlesource.gerrit.plugins.supermanifest.RepoSuperManifestIT.java
License:Apache License
@Test public void relativeFetch() throws Exception { // Test the setup that Android uses, where the "fetch" field is relative to the location of the // manifest repo. setupTestRepos("platform/project"); // The test framework adds more cruft to the prefix. 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.xml\n"); String url = canonicalWebUrl.get(); String remoteXml = " <remote name=\"origin\" fetch=\"..\" review=\"" + url + "\" />\n"; String defaultXml = " <default remote=\"origin\" revision=\"refs/heads/master\" />\n"; String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<manifest>\n" + remoteXml + defaultXml + " <project name=\"" + testRepoKeys[0].get() + "\" path=\"path1\" />\n" + "</manifest>\n"; pushFactory.create(admin.getIdent(), manifestRepo, "Subject", "default.xml", xml).to("refs/heads/srcbranch") .assertOkStatus();//from w w w . jav a 2 s. c o m BranchApi branch = gApi.projects().name(superKey.get()).branch("refs/heads/destbranch"); assertThat(branch.file("path1").getContentType()).isEqualTo("x-git/gitlink; charset=UTF-8"); Config base = new Config(); String gitmodule = branch.file(".gitmodules").asString(); BlobBasedConfig cfg = new BlobBasedConfig(base, gitmodule.getBytes(UTF_8)); String subUrl = cfg.getString("submodule", testRepoKeys[0].get(), "url"); // URL is valid. URI.create(subUrl); // The suburls 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"); }