Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.StoredConfig


    try {
      Repository db = RepositoryCache.open(loc, false);
      db.create(true /* bare */);

      StoredConfig config = db.getConfig();
      config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION,
        null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
      config.save();

      onCreateProject(name);

      return db;
    } catch (IOException e1) {
View Full Code Here


    if (gitdir == null)
      gitdir = new File(localName, Constants.DOT_GIT).getAbsolutePath();

    dst = new FileRepositoryBuilder().setGitDir(new File(gitdir)).build();
    dst.create();
    final StoredConfig dstcfg = dst.getConfig();
    dstcfg.setBoolean("core", null, "bare", false); //$NON-NLS-1$ //$NON-NLS-2$
    dstcfg.save();
    db = dst;

    outw.print(MessageFormat.format(
        CLIText.get().initializedEmptyGitRepositoryIn, gitdir));
    outw.println();
View Full Code Here

    doCheckout(checkoutRef);
  }

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

    Git repo = Git.open(stagingDirectory);

    String remoteUrl = "git@heroku.com:" + app + ".git";
   
    StoredConfig config = repo.getRepository().getConfig();
   
    config.setString("remote", "heroku", "url", remoteUrl);
   
    config.save();

    log("Pushing from %s to %s", stagingDirectory, remoteUrl);

    JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {
      @Override
View Full Code Here

        RefSpec branchSpec = new RefSpec(prefixedBranchName + ":" + Constants.R_HEADS + prefixedBranchName);
        git.push().setRemote("origin").setRefSpecs(branchSpec).call();
        git.fetch().setRemote("origin").call();
       
        //setup tracking
        StoredConfig config = git.getRepository().getConfig();
        config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,prefixedBranchName, ConfigConstants.CONFIG_KEY_REMOTE,"origin");
        config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,prefixedBranchName, ConfigConstants.CONFIG_KEY_MERGE,Constants.R_HEADS + prefixedBranchName);
        config.save();
       
        //checkout the branch
        git.checkout().setName(prefixedBranchName).call();
       
        return null;
View Full Code Here

            .name()));

      if (fullNewName.startsWith(Constants.R_HEADS)) {
        String shortOldName = fullOldName.substring(Constants.R_HEADS
            .length());
        final StoredConfig repoConfig = repo.getConfig();
        // Copy all configuration values over to the new branch
        for (String name : repoConfig.getNames(
            ConfigConstants.CONFIG_BRANCH_SECTION, shortOldName)) {
          String[] values = repoConfig.getStringList(
              ConfigConstants.CONFIG_BRANCH_SECTION,
              shortOldName, name);
          if (values.length == 0)
            continue;
          // Keep any existing values already configured for the
          // new branch name
          String[] existing = repoConfig.getStringList(
              ConfigConstants.CONFIG_BRANCH_SECTION, newName,
              name);
          if (existing.length > 0) {
            String[] newValues = new String[values.length
                + existing.length];
            System.arraycopy(existing, 0, newValues, 0,
                existing.length);
            System.arraycopy(values, 0, newValues, existing.length,
                values.length);
            values = newValues;
          }

          repoConfig.setStringList(
              ConfigConstants.CONFIG_BRANCH_SECTION, newName,
              name, Arrays.asList(values));
        }
        repoConfig.unsetSection(ConfigConstants.CONFIG_BRANCH_SECTION,
            shortOldName);
        repoConfig.save();
      }

      Ref resultRef = repo.getRef(newName);
      if (resultRef == null)
        throw new JGitInternalException(
View Full Code Here

          doConfigure = baseBranch.startsWith(Constants.R_REMOTES);
        }
      }

      if (doConfigure) {
        StoredConfig config = repo.getConfig();
        String[] tokens = baseBranch.split("/", 4);
        boolean isRemote = tokens[1].equals("remotes");
        if (isRemote) {
          // refs/remotes/<remote name>/<branch>
          String remoteName = tokens[2];
          String branchName = tokens[3];
          config
              .setString(ConfigConstants.CONFIG_BRANCH_SECTION,
                  name, ConfigConstants.CONFIG_KEY_REMOTE,
                  remoteName);
          config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,
              name, ConfigConstants.CONFIG_KEY_MERGE,
              Constants.R_HEADS + branchName);
        } else {
          // set "." as remote
          config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,
              name, ConfigConstants.CONFIG_KEY_REMOTE, ".");
          config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,
              name, ConfigConstants.CONFIG_KEY_MERGE, baseBranch);
        }
        config.save();
      }
      return result;
    } catch (IOException ioe) {
      throw new JGitInternalException(ioe.getMessage(), ioe);
    } finally {
View Full Code Here

                RefSpec branchSpec = new RefSpec(prefixedBranchName + ":" + Constants.R_HEADS + prefixedBranchName);
                git.push().setRemote("origin").setRefSpecs(branchSpec).call();
                git.fetch().setRemote("origin").call();

                //setup tracking
                StoredConfig config = git.getRepository().getConfig();
                config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, prefixedBranchName, ConfigConstants.CONFIG_KEY_REMOTE, "origin");
                config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, prefixedBranchName, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + prefixedBranchName);
                config.save();
            }

            return newBranch;

        }
View Full Code Here

                RefSpec branchSpec = new RefSpec(prefixedHotfixName + ":" + Constants.R_HEADS + prefixedHotfixName);
                git.push().setRemote("origin").setRefSpecs(branchSpec).call();
                git.fetch().setRemote("origin").call();

                //setup tracking
                StoredConfig config = git.getRepository().getConfig();
                config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, prefixedHotfixName, ConfigConstants.CONFIG_KEY_REMOTE, "origin");
                config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, prefixedHotfixName, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + prefixedHotfixName);
                config.save();
            }

            return newBranch;
        }
        catch (GitAPIException e)
View Full Code Here

   */
  private synchronized void write() throws IOException {
    // Write a temporary copy of the users file
    File realmFileCopy = new File(realmFile.getAbsolutePath() + ".tmp");

    StoredConfig config = new FileBasedConfig(realmFileCopy, FS.detect());

    // write users
    for (UserModel model : users.values()) {
      if (!StringUtils.isEmpty(model.password)) {
        config.setString(USER, model.username, PASSWORD, model.password);
      }
      if (!StringUtils.isEmpty(model.cookie)) {
        config.setString(USER, model.username, COOKIE, model.cookie);
      }
      if (!StringUtils.isEmpty(model.displayName)) {
        config.setString(USER, model.username, DISPLAYNAME, model.displayName);
      }
      if (!StringUtils.isEmpty(model.emailAddress)) {
        config.setString(USER, model.username, EMAILADDRESS, model.emailAddress);
      }
      if (model.accountType != null) {
        config.setString(USER, model.username, ACCOUNTTYPE, model.accountType.name());
      }
      if (!StringUtils.isEmpty(model.organizationalUnit)) {
        config.setString(USER, model.username, ORGANIZATIONALUNIT, model.organizationalUnit);
      }
      if (!StringUtils.isEmpty(model.organization)) {
        config.setString(USER, model.username, ORGANIZATION, model.organization);
      }
      if (!StringUtils.isEmpty(model.locality)) {
        config.setString(USER, model.username, LOCALITY, model.locality);
      }
      if (!StringUtils.isEmpty(model.stateProvince)) {
        config.setString(USER, model.username, STATEPROVINCE, model.stateProvince);
      }
      if (!StringUtils.isEmpty(model.countryCode)) {
        config.setString(USER, model.username, COUNTRYCODE, model.countryCode);
      }
      if (model.disabled) {
        config.setBoolean(USER, model.username, DISABLED, true);
      }
      if (model.getPreferences() != null) {
        if (!StringUtils.isEmpty(model.getPreferences().locale)) {
          config.setString(USER, model.username, LOCALE, model.getPreferences().locale);
        }
      }

      // user roles
      List<String> roles = new ArrayList<String>();
      if (model.canAdmin) {
        roles.add(Constants.ADMIN_ROLE);
      }
      if (model.canFork) {
        roles.add(Constants.FORK_ROLE);
      }
      if (model.canCreate) {
        roles.add(Constants.CREATE_ROLE);
      }
      if (model.excludeFromFederation) {
        roles.add(Constants.NOT_FEDERATED_ROLE);
      }
      if (roles.size() == 0) {
        // we do this to ensure that user record with no password
        // is written.  otherwise, StoredConfig optimizes that account
        // away. :(
        roles.add(Constants.NO_ROLE);
      }
      config.setStringList(USER, model.username, ROLE, roles);

      // discrete repository permissions
      if (model.permissions != null && !model.canAdmin) {
        List<String> permissions = new ArrayList<String>();
        for (Map.Entry<String, AccessPermission> entry : model.permissions.entrySet()) {
          if (entry.getValue().exceeds(AccessPermission.NONE)) {
            permissions.add(entry.getValue().asRole(entry.getKey()));
          }
        }
        config.setStringList(USER, model.username, REPOSITORY, permissions);
      }

      // user preferences
      if (model.getPreferences() != null) {
        List<String> starred =  model.getPreferences().getStarredRepositories();
        if (starred.size() > 0) {
          config.setStringList(USER, model.username, STARRED, starred);
        }
      }
    }

    // write teams
    for (TeamModel model : teams.values()) {
      // team roles
      List<String> roles = new ArrayList<String>();
      if (model.canAdmin) {
        roles.add(Constants.ADMIN_ROLE);
      }
      if (model.canFork) {
        roles.add(Constants.FORK_ROLE);
      }
      if (model.canCreate) {
        roles.add(Constants.CREATE_ROLE);
      }
      if (roles.size() == 0) {
        // we do this to ensure that team record is written.
        // Otherwise, StoredConfig might optimizes that record away.
        roles.add(Constants.NO_ROLE);
      }
      config.setStringList(TEAM, model.name, ROLE, roles);
      if (model.accountType != null) {
        config.setString(TEAM, model.name, ACCOUNTTYPE, model.accountType.name());
      }

      if (!model.canAdmin) {
        // write team permission for non-admin teams
        if (model.permissions == null) {
          // null check on "final" repositories because JSON-sourced TeamModel
          // can have a null repositories object
          if (!ArrayUtils.isEmpty(model.repositories)) {
            config.setStringList(TEAM, model.name, REPOSITORY, new ArrayList<String>(
                model.repositories));
          }
        } else {
          // discrete repository permissions
          List<String> permissions = new ArrayList<String>();
          for (Map.Entry<String, AccessPermission> entry : model.permissions.entrySet()) {
            if (entry.getValue().exceeds(AccessPermission.NONE)) {
              // code:repository (e.g. RW+:~james/myrepo.git
              permissions.add(entry.getValue().asRole(entry.getKey()));
            }
          }
          config.setStringList(TEAM, model.name, REPOSITORY, permissions);
        }
      }

      // null check on "final" users because JSON-sourced TeamModel
      // can have a null users object
      if (!ArrayUtils.isEmpty(model.users)) {
        config.setStringList(TEAM, model.name, USER, new ArrayList<String>(model.users));
      }

      // null check on "final" mailing lists because JSON-sourced
      // TeamModel can have a null users object
      if (!ArrayUtils.isEmpty(model.mailingLists)) {
        config.setStringList(TEAM, model.name, MAILINGLIST, new ArrayList<String>(
            model.mailingLists));
      }

      // null check on "final" preReceiveScripts because JSON-sourced
      // TeamModel can have a null preReceiveScripts object
      if (!ArrayUtils.isEmpty(model.preReceiveScripts)) {
        config.setStringList(TEAM, model.name, PRERECEIVE, model.preReceiveScripts);
      }

      // null check on "final" postReceiveScripts because JSON-sourced
      // TeamModel can have a null postReceiveScripts object
      if (!ArrayUtils.isEmpty(model.postReceiveScripts)) {
        config.setStringList(TEAM, model.name, POSTRECEIVE, model.postReceiveScripts);
      }
    }

    config.save();
    // manually set the forceReload flag because not all JVMs support real
    // millisecond resolution of lastModified. (issue-55)
    forceReload = true;

    // If the write is successful, delete the current file and rename
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.StoredConfig

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.