Package org.eclipse.jgit.api

Examples of org.eclipse.jgit.api.CommitCommand


  private List<String> paths = new ArrayList<String>();

  @Override
  protected void run() throws NoHeadException, NoMessageException,
      ConcurrentRefUpdateException, JGitInternalException, Exception {
    CommitCommand commitCmd = new Git(db).commit();
    if (author != null)
      commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
    if (message != null)
      commitCmd.setMessage(message);
    if (only && paths.isEmpty())
      throw die(CLIText.get().pathsRequired);
    if (only && all)
      throw die(CLIText.get().onlyOneOfIncludeOnlyAllInteractiveCanBeUsed);
    if (!paths.isEmpty())
      for (String p : paths)
        commitCmd.setOnly(p);
    commitCmd.setAmend(amend);
    commitCmd.setAll(all);
    Ref head = db.getRef(Constants.HEAD);
    RevCommit commit;
    try {
      commit = commitCmd.call();
    } catch (JGitInternalException e) {
      throw die(e.getMessage());
    }

    String branchName;
View Full Code Here


        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
            "Missing commit message.", null));
      }

      Git git = new Git(db);
      CommitCommand cc = git.commit();
      Config config = git.getRepository().getConfig();

      boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null));
      boolean insertChangeId = config.getBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, ConfigConstants.CONFIG_KEY_CREATECHANGEID, false)
          || Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_CHANGE_ID, null));

      String committerName = requestObject.optString(GitConstants.KEY_COMMITTER_NAME, null);
      String committerEmail = requestObject.optString(GitConstants.KEY_COMMITTER_EMAIL, null);
      String authorName = requestObject.optString(GitConstants.KEY_AUTHOR_NAME, null);
      String authorEmail = requestObject.optString(GitConstants.KEY_AUTHOR_EMAIL, null);

      // workaround of a bug in JGit which causes invalid
      // support of null values of author/committer name/email, see bug
      // 352984
      PersonIdent defPersonIdent = new PersonIdent(db);
      if (committerName == null)
        committerName = defPersonIdent.getName();
      if (committerEmail == null)
        committerEmail = defPersonIdent.getEmailAddress();
      if (authorName == null)
        authorName = committerName;
      if (authorEmail == null)
        authorEmail = committerEmail;
      cc.setCommitter(committerName, committerEmail);
      cc.setAuthor(authorName, authorEmail);
      if (insertChangeId)
        cc.setInsertChangeId(true);

      // support for committing by path: "git commit -o path"
      if (!pattern.isEmpty()) {
        cc.setOnly(pattern);
      }

      try {
        // "git commit [--amend] -m '{message}' [-a|{path}]"
        RevCommit lastCommit = cc.setAmend(amend).setMessage(message).call();

        URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT_REFRANGE);
        Commit commit = new Commit(cloneLocation, db, lastCommit, pattern);
        JSONObject result = commit.toJSON();
        OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
View Full Code Here

  private String message;

  @Override
  protected void run() throws NoHeadException, NoMessageException,
      ConcurrentRefUpdateException, JGitInternalException, Exception {
    CommitCommand commitCmd = new Git(db).commit();
    if (author != null)
      commitCmd.setAuthor(new PersonIdent(author));
    if (message != null)
      commitCmd.setMessage(message);
    Ref head = db.getRef(Constants.HEAD);
    RevCommit commit = commitCmd.call();

    String branchName;
    if (!head.isSymbolic())
      branchName = CLIText.get().branchDetachedHEAD;
    else {
View Full Code Here

            if ( doCommit )
            {
                UserInfo author = getAuthor( repo, git );
                UserInfo committer = getCommitter( repo, git );

                CommitCommand command = git.commit().setMessage( message ).setAuthor( author.name, author.email );
                command.setCommitter( committer.name, committer.email );
                RevCommit commitRev = command.call();

                getLogger().info( "commit done: " + commitRev.getShortMessage() );
                checkedInFiles = JGitUtils.getFilesInCommit( git.getRepository(), commitRev );
                if ( getLogger().isDebugEnabled() )
                {
View Full Code Here

      AddCommand add = git.add();
      add.addFilepattern(filePath).call();
      GitUser user = userMap.get(psoft_user);
      if (user == null)
        user = userMap.get("default");
      CommitCommand commit = git.commit();
      commit.setMessage(commitStr).setAuthor(user.user, user.email).setCommitter("Decode Peoplecode", "nobody@dummy.org").call();
      }
View Full Code Here

            Git git = new Git(r);
            AddCommand cmd = git.add();
            cmd.addFilepattern(filePattern);
            cmd.call();

            CommitCommand co = git.commit();
            co.setAuthor("Jenkow","noreply@jenkins-ci.org");
            co.setMessage(msg);
            co.call();
        } catch (GitAPIException e) {
            LOGGER.log(Level.WARNING, "Adding seeded jenkow-repository content to Git failed",e);
        }
  }
View Full Code Here

        out.flush();
        out.close();

        Git git = new Git(repository);
        git.add().addFilepattern(fileName).call();
        CommitCommand commitCommand = git.commit().setMessage(message);
        if (author != null) {
            commitCommand
                .setAuthor(author.loginId, author.email)
                .setCommitter(author.loginId, author.email);
        }
        return commitCommand.call();
    }
View Full Code Here

  }

  private void commit() throws TeamException {
    Git git = new Git(repo);
    try {
      CommitCommand commitCommand = git.commit();
      setAuthorAndCommitter(commitCommand);
      commitCommand.setAmend(amending)
          .setMessage(message)
          .setInsertChangeId(createChangeId);
      if (!commitIndex)
        for(String path:commitFileList)
          commitCommand.setOnly(path);
      commit = commitCommand.call();
    } catch (Exception e) {
      throw new TeamException(
          CoreText.MergeOperation_InternalError, e);
    }
  }
View Full Code Here

  // TODO: can the commit message be change by the user in case of a merge commit?
  private void commitAll() throws TeamException {

    Git git = new Git(repo);
    try {
      CommitCommand commitCommand = git.commit();
      setAuthorAndCommitter(commitCommand);
      commit = commitCommand.setAll(true).setMessage(message)
          .setInsertChangeId(createChangeId).call();
    } catch (JGitInternalException e) {
      throw new TeamException(CoreText.MergeOperation_InternalError, e);
    } catch (GitAPIException e) {
      throw new TeamException(e.getLocalizedMessage(), e);
View Full Code Here

  public RevCommit commit(String message) throws NoHeadException,
      NoMessageException, UnmergedPathException,
      ConcurrentRefUpdateException, JGitInternalException,
      WrongRepositoryStateException, GitAPIException {
    Git git = new Git(repository);
    CommitCommand commitCommand = git.commit();
    commitCommand.setAuthor("J. Git", "j.git@egit.org");
    commitCommand.setCommitter(commitCommand.getAuthor());
    commitCommand.setMessage(message);
    return commitCommand.call();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.api.CommitCommand

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.