Package org.eclipse.jgit.storage.file

Examples of org.eclipse.jgit.storage.file.FileBasedConfig


            return repository;
        }

        if (!dotGit.exists()) {
            Git.cloneRepository().setDirectory(gitRoot).setCloneAllBranches(true).setURI(gitUrl).call();
            FileBasedConfig config = new FileBasedConfig(new File(dotGit, "config"), FS.DETECTED);
            config.load();
            if (gitPushUrl != null) {
                config.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "pushurl", gitPushUrl);
            }
            config.save();
        }

        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        repository = builder.setGitDir(dotGit).readEnvironment().findGitDir().build();
        localRepos.put(dotGit, repository);
View Full Code Here


        throw die(MessageFormat.format(
            CLIText.get().configFileNotFound, //
            configFile.getAbsolutePath()));
      }

      FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
      cfg.load();
      packConfig.fromConfig(cfg);
    }

    int threads = packConfig.getThreads();
    if (threads <= 0)
View Full Code Here

    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }

    // Save path and URL to parent repository's .gitmodules file
    FileBasedConfig modulesConfig = new FileBasedConfig(new File(
        repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS());
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_PATH, path);
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_URL, uri);
    try {
      modulesConfig.save();
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }

    AddCommand add = new AddCommand(repo);
View Full Code Here

  private void loadModulesConfig() throws IOException, ConfigInvalidException {
    if (modulesConfig == null) {
      File modulesFile = new File(repository.getWorkTree(),
          Constants.DOT_GIT_MODULES);
      FileBasedConfig config = new FileBasedConfig(modulesFile,
          repository.getFS());
      config.load();
      modulesConfig = config;
    }
  }
View Full Code Here

      // We only want the repository's configuration file, and not
      // the user file, as these parameters must be unique to this
      // repository and not inherited from other files.
      //
      File path = safeFS().resolve(getGitDir(), Constants.CONFIG);
      FileBasedConfig cfg = new FileBasedConfig(path, safeFS());
      try {
        cfg.load();
      } catch (ConfigInvalidException err) {
        throw new IllegalArgumentException(MessageFormat.format(
            JGitText.get().repositoryConfigFileInvalid, path
                .getAbsolutePath(), err.getMessage()));
      }
View Full Code Here

      {
         final URIish uri = new URIish(sourceUri);
         File gitdir = new File(projectDir, Constants.DOT_GIT);
         db = new FileRepository(gitdir);
         db.create();
         final FileBasedConfig dstcfg = db.getConfig();
         dstcfg.setBoolean("core", null, "bare", false);
         dstcfg.save();

         saveRemote(uri);
         final FetchResult r = runFetch();
         final Ref branch = guessHEAD(r);
         doCheckout(branch);
View Full Code Here

   }

   private void saveRemote(final URIish uri) throws URISyntaxException,
            IOException
   {
      final FileBasedConfig dstcfg = db.getConfig();
      final RemoteConfig rc = new RemoteConfig(dstcfg, remoteName);
      rc.addURI(uri);
      rc.addFetchRefSpec(new RefSpec().setForceUpdate(true)
               .setSourceDestination(Constants.R_HEADS + "*",
                        Constants.R_REMOTES + remoteName + "/*"));
      rc.update(dstcfg);
      dstcfg.save();
   }
View Full Code Here

      // We only want the repository's configuration file, and not
      // the user file, as these parameters must be unique to this
      // repository and not inherited from other files.
      //
      File path = safeFS().resolve(getGitDir(), "config");
      FileBasedConfig cfg = new FileBasedConfig(path, safeFS());
      try {
        cfg.load();
      } catch (ConfigInvalidException err) {
        throw new IllegalArgumentException(MessageFormat.format(
            JGitText.get().repositoryConfigFileInvalid, path
                .getAbsolutePath(), err.getMessage()));
      }
View Full Code Here

  @Override
  protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    SystemConfig sc = db.systemConfig().get(new SystemConfig.Key());
    Project.NameKey allProjects = sc.wildProjectName;

    FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
    boolean cfgDirty = false;
    try {
      cfg.load();
    } catch (ConfigInvalidException err) {
      throw new OrmException("Cannot read " + site.gerrit_config, err);
    } catch (IOException err) {
      throw new OrmException("Cannot read " + site.gerrit_config, err);
    }

    if (!allProjects.get().equals(AllProjectsNameProvider.DEFAULT)) {
      ui.message("Setting gerrit.allProjects = " + allProjects.get());
      cfg.setString("gerrit", null, "allProjects", allProjects.get());
      cfgDirty = true;
    }

    try {
      Repository git = mgr.openRepository(allProjects);
      try {
        MetaDataUpdate md =
            new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjects, git);
        md.getCommitBuilder().setAuthor(serverUser);
        md.getCommitBuilder().setCommitter(serverUser);

        ProjectConfig config = ProjectConfig.read(md);
        AccessSection cap = config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true);

        // Move the Administrators group reference to All-Projects.
        cap.getPermission(GlobalCapability.ADMINISTRATE_SERVER, true)
            .add(new PermissionRule(config.resolve(db.accountGroups().get(sc.adminGroupId))));

        // Move the repository.*.createGroup to Create Project.
        String[] createGroupList = cfg.getStringList("repository", "*", "createGroup");
        for (String name : createGroupList) {
          AccountGroup.NameKey key = new AccountGroup.NameKey(name);
          AccountGroupName groupName = db.accountGroupNames().get(key);
          if (groupName == null) {
            continue;
          }

          AccountGroup group = db.accountGroups().get(groupName.getId());
          if (group == null) {
            continue;
          }

          cap.getPermission(GlobalCapability.CREATE_PROJECT, true)
              .add(new PermissionRule(config.resolve(group)));
        }
        if (createGroupList.length != 0) {
          ui.message("Moved repository.*.createGroup to 'Create Project' capability");
          cfg.unset("repository", "*", "createGroup");
          cfgDirty = true;
        }

        AccountGroup batch = db.accountGroups().get(sc.batchUsersGroupId);
        if (batch != null
            && db.accountGroupMembers().byGroup(sc.batchUsersGroupId).toList().isEmpty()
            &&  db.accountGroupIncludes().byGroup(sc.batchUsersGroupId).toList().isEmpty()) {
          // If the batch user group is not used, delete it.
          //
          db.accountGroups().delete(Collections.singleton(batch));

          AccountGroupName name = db.accountGroupNames().get(batch.getNameKey());
          if (name != null) {
            db.accountGroupNames().delete(Collections.singleton(name));
          }
        } else if (batch != null) {
          cap.getPermission(GlobalCapability.PRIORITY, true)
              .getRule(config.resolve(batch), true)
              .setAction(Action.BATCH);
        }

        md.setMessage("Upgrade to Gerrit Code Review schema 57\n");
        config.commit(md);
      } finally {
        git.close();
      }
    } catch (ConfigInvalidException err) {
      throw new OrmException("Cannot read " + allProjects, err);
    } catch (IOException err) {
      throw new OrmException("Cannot update " + allProjects, err);
    }

    if (cfgDirty) {
      try {
        cfg.save();
      } catch (IOException err) {
        throw new OrmException("Cannot update " + site.gerrit_config, err);
      }
    }

View Full Code Here

  }

  private void list() throws IOException, ConfigInvalidException {
    final FS fs = getRepository().getFS();
    if (configFile != null) {
      list(new FileBasedConfig(configFile, fs));
      return;
    }
    if (system || isListAll())
      list(SystemReader.getInstance().openSystemConfig(null, fs));
    if (global || isListAll())
      list(SystemReader.getInstance().openUserConfig(null, fs));
    if (local || isListAll())
      list(new FileBasedConfig(fs.resolve(getRepository().getDirectory(),
          Constants.CONFIG), fs));
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.storage.file.FileBasedConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.