Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.StoredConfig


          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);
    }
View Full Code Here


      if (ok) {
        if (fullNewName.startsWith(Constants.R_HEADS)) {
          // move the upstream configuration over to the new branch
          String shortOldName = fullOldName
              .substring(Constants.R_HEADS.length());
          final StoredConfig repoConfig = repo.getConfig();
          String oldRemote = repoConfig.getString(
              ConfigConstants.CONFIG_BRANCH_SECTION,
              shortOldName, ConfigConstants.CONFIG_KEY_REMOTE);
          if (oldRemote != null) {
            repoConfig.setString(
                ConfigConstants.CONFIG_BRANCH_SECTION, newName,
                ConfigConstants.CONFIG_KEY_REMOTE, oldRemote);
          }
          String oldMerge = repoConfig.getString(
              ConfigConstants.CONFIG_BRANCH_SECTION,
              shortOldName, ConfigConstants.CONFIG_KEY_MERGE);
          if (oldMerge != null) {
            repoConfig.setString(
                ConfigConstants.CONFIG_BRANCH_SECTION, newName,
                ConfigConstants.CONFIG_KEY_MERGE, oldMerge);
          }
          repoConfig
              .unsetSection(
                  ConfigConstants.CONFIG_BRANCH_SECTION,
                  shortOldName);
          repoConfig.save();
        }

      } else
        throw new JGitInternalException(MessageFormat.format(JGitText
            .get().renameBranchUnexpectedResult, renameResult
View Full Code Here

          result.add(fullName);
          if (fullName.startsWith(Constants.R_HEADS)) {
            String shortenedName = fullName
                .substring(Constants.R_HEADS.length());
            // remove upstream configuration if any
            final StoredConfig cfg = repo.getConfig();
            cfg.unsetSection(
                ConfigConstants.CONFIG_BRANCH_SECTION,
                shortenedName);
            cfg.save();
          }
        } else
          throw new JGitInternalException(MessageFormat.format(
              JGitText.get().deleteBranchUnexpectedResult,
              deleteResult.name()));
View Full Code Here

     * @param branchName
     * @throws JGitFlowIOException
     */
    public void setMaster(String branchName) throws JGitFlowIOException
    {
        StoredConfig config = git.getRepository().getConfig();
        config.setString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, branchName);
        try
        {
            config.save();
        }
        catch (IOException e)
        {
            throw new JGitFlowIOException(e);
        }
View Full Code Here

     * @param branchName
     * @throws JGitFlowIOException
     */
    public void setDevelop(String branchName) throws JGitFlowIOException
    {
        StoredConfig config = git.getRepository().getConfig();
        config.setString(JGitFlowConstants.SECTION, ConfigConstants.CONFIG_BRANCH_SECTION, JGitFlowConstants.DEVELOP_KEY, branchName);
        try
        {
            config.save();
        }
        catch (IOException e)
        {
            throw new JGitFlowIOException(e);
        }
View Full Code Here

     * @param prefixValue
     * @throws JGitFlowIOException
     */
    public void setPrefix(String prefixName, String prefixValue) throws JGitFlowIOException
    {
        StoredConfig config = git.getRepository().getConfig();
        if (getPrefixNames().contains(prefixName))
        {
            config.setString(JGitFlowConstants.SECTION, JGitFlowConstants.PREFIX_SUB, prefixName, prefixValue);
            try
            {
                config.save();
            }
            catch (IOException e)
            {
                throw new JGitFlowIOException(e);
            }
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();

        }
View Full Code Here

     * @return {@link CredentialsProvider} in case there are credentials
     *         informations configured in the repository.
     */
    public static CredentialsProvider prepareSession( ScmLogger logger, Git git, GitScmProviderRepository repository )
    {
        StoredConfig config = git.getRepository().getConfig();
        config.setString( "remote", "origin", "url", repository.getFetchUrl() );
        config.setString( "remote", "origin", "pushURL", repository.getPushUrl() );

        // make sure we do not log any passwords to the output
        String password =
            StringUtils.isNotBlank( repository.getPassword() ) ? repository.getPassword().trim() : "no-pwd-defined";
        logger.info( "fetch url: " + repository.getFetchUrl().replace( password, "******" ) );
View Full Code Here

        createAndCommitFile( fooJava, null );

        // change user in config
        git = Git.open( getWorkingCopy() );
        StoredConfig config = git.getRepository().getConfig();
        unsetConfig( config );
        config.setString( "user", null, "name", "Dominik" );
        config.setString( "user", null, "email", "domi@mycomp.com" );
        config.save();

        // make a commit
        createAndCommitFile( fooJava, null );

        // check new commit is done with new user in config
        head = getHeadCommit( git.getRepository() );
        assertEquals( "Dominik", head.getCommitterIdent().getName() );
        assertEquals( "Dominik", head.getAuthorIdent().getName() );
        assertEquals( "domi@mycomp.com", head.getAuthorIdent().getEmailAddress() );
        assertEquals( "domi@mycomp.com", head.getCommitterIdent().getEmailAddress() );
        JGitUtils.closeRepo( git );

        // change user in config
        git = Git.open( getWorkingCopy() );
        config = git.getRepository().getConfig();
        unsetConfig( config );
        config.setString( "user", null, "name", "dbartholdi" );
        config.save();

        // make a change
        createAndCommitFile( fooJava, null );

        // check new commit is done with new user in config
        head = getHeadCommit( git.getRepository() );
        assertEquals( "dbartholdi", head.getCommitterIdent().getName() );
        assertFalse( "no mail domain is configured, git system default should be used",
                     head.getCommitterIdent().getEmailAddress().contains( "dbartholdi" ) );
        JGitUtils.closeRepo( git );

        // unset a user and maven user but set default mail domain
        git = Git.open( getWorkingCopy() );
        config = git.getRepository().getConfig();
        unsetConfig( config );
        config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN, "comp.com" );
        config.save();

        // make a change with an user on the commandline
        createAndCommitFile( fooJava, "dude" );

        // check new commit is done with new maven user in config
        head = getHeadCommit( git.getRepository() );
        assertEquals( "dude", head.getCommitterIdent().getName() );
        assertEquals( "dude@comp.com", head.getCommitterIdent().getEmailAddress() );
        assertEquals( "dude", head.getAuthorIdent().getName() );
        assertEquals( "dude@comp.com", head.getAuthorIdent().getEmailAddress() );
        JGitUtils.closeRepo( git );

        // unset a user and maven user but set default mail domain
        git = Git.open( getWorkingCopy() );
        config = git.getRepository().getConfig();
        unsetConfig( config );
        config.setString( "user", null, "name", "dbartholdi" );
        config.setBoolean( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_FORCE, true );
        config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN, "anycomp.com" );
        config.save();

        // make a change with an user on the commandline
        createAndCommitFile( fooJava, "dude" );

        // check new commit is done with new maven user in config
        head = getHeadCommit( git.getRepository() );
        assertEquals( "dude", head.getCommitterIdent().getName() );
        assertEquals( "dude@anycomp.com", head.getCommitterIdent().getEmailAddress() );
        assertEquals( "dude", head.getAuthorIdent().getName() );
        assertEquals( "dude@anycomp.com", head.getAuthorIdent().getEmailAddress() );
        JGitUtils.closeRepo( git );

        // unset a user and maven user but set default mail domain
        git = Git.open( getWorkingCopy() );
        config = git.getRepository().getConfig();
        unsetConfig( config );
        config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN, "anycomp.com" );
        config.save();

        // make a change with no username given
        createAndCommitFile( fooJava, null );

        // check new commit does not contain the configured email domain
        head = getHeadCommit( git.getRepository() );
        assertFalse( head.getCommitterIdent().getEmailAddress().contains( "anycomp.com" ) );
        assertFalse( head.getAuthorIdent().getEmailAddress().contains( "anycomp.com" ) );
        JGitUtils.closeRepo( git );

        // unset a user and full maven section
        git = Git.open( getWorkingCopy() );
        config = git.getRepository().getConfig();
        unsetConfig( config );
        config.save();

        // make a change with an user on the commandline
        createAndCommitFile( fooJava, "dundy" );

        // check new commit is done with new maven user in config
        head = getHeadCommit( git.getRepository() );
        assertEquals( "dundy", head.getCommitterIdent().getName() );
        assertEquals( "dundy", head.getAuthorIdent().getName() );
        assertTrue( "the maven user (from parameter) name must be in the committer mail when nothing else is configured",
                    head.getCommitterIdent().getEmailAddress().contains( "dundy" ) );
        assertTrue( "the user name (from parameter) must be in the author mail when nothing else is configured",
                    head.getAuthorIdent().getEmailAddress().contains( "dundy" ) );
        JGitUtils.closeRepo( git );

        // unset all configs
        git = Git.open( getWorkingCopy() );
        config = git.getRepository().getConfig();
        unsetConfig( config );
        config.save();

        // make a change with no user on the commandline
        createAndCommitFile( fooJava, null );

        // check new commit is has a committer/author with email set
View Full Code Here

      return labelsCache.get(key);
    }
    List<TicketLabel> list = new ArrayList<TicketLabel>();
    Repository db = repositoryManager.getRepository(repository.name);
    try {
      StoredConfig config = db.getConfig();
      Set<String> names = config.getSubsections(LABEL);
      for (String name : names) {
        TicketLabel label = new TicketLabel(name);
        label.color = config.getString(LABEL, name, COLOR);
        list.add(label);
      }
      labelsCache.put(key,  Collections.unmodifiableList(list));
    } catch (Exception e) {
      log.error("invalid tickets settings for " + repository, e);
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.