Search in sources :

Example 6 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gerrit by GerritCodeReview.

the class PushPermissionsIT method administrateServerForUpdateParentDenied.

@Test
public void administrateServerForUpdateParentDenied() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref("refs/meta/config").group(REGISTERED_USERS)).add(allow(Permission.OWNER).ref("refs/*").group(REGISTERED_USERS)).update();
    String project2 = name("project2");
    projectOperations.newProject().name(project2).create();
    ObjectId oldId = forceFetch("refs/meta/config");
    Config cfg = new BlobBasedConfig(null, testRepo.getRepository(), oldId, "project.config");
    cfg.setString("access", null, "inheritFrom", project2);
    ObjectId newId = testRepo.branch("refs/meta/config").commit().add("project.config", cfg.toText()).create();
    PushResult r = push(newId.name() + ":refs/meta/config");
    assertThat(r).onlyRef("refs/meta/config").isRejected("invalid project configuration: only Gerrit admin can set parent");
    assertThat(r).hasNoMessages();
    assertThat(r).hasProcessed(ImmutableMap.of("refs", 1));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Config(org.eclipse.jgit.lib.Config) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig) PushResult(org.eclipse.jgit.transport.PushResult) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with BlobBasedConfig

use of org.eclipse.jgit.lib.BlobBasedConfig in project gitblit by gitblit.

the class JGitUtils method getSubmodules.

/**
 * Returns the list of submodules for this repository.
 *
 * @param repository
 * @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;
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ArrayList(java.util.ArrayList) SubmoduleModel(com.gitblit.models.SubmoduleModel) BlobBasedConfig(org.eclipse.jgit.lib.BlobBasedConfig)

Aggregations

BlobBasedConfig (org.eclipse.jgit.lib.BlobBasedConfig)7 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 IdString (com.google.gerrit.extensions.restapi.IdString)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)2 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)2 Config (org.eclipse.jgit.lib.Config)2 Repository (org.eclipse.jgit.lib.Repository)2 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)2 SubmoduleModel (com.gitblit.models.SubmoduleModel)1 ImmutableList (com.google.common.collect.ImmutableList)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 DashboardInfo (com.google.gerrit.extensions.api.projects.DashboardInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 AuthConfig (com.google.gerrit.server.config.AuthConfig)1 DashboardResource (com.google.gerrit.server.project.DashboardResource)1 DashboardInfo (com.google.gerrit.server.project.DashboardsCollection.DashboardInfo)1 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)1 PushResult (org.eclipse.jgit.transport.PushResult)1