Search in sources :

Example 6 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.

the class CommitOperation method commitAll.

// TODO: can the commit message be change by the user in case of a merge commit?
private void commitAll() throws TeamException {
    try (Git git = new Git(repo)) {
        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);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) TeamException(org.eclipse.team.core.TeamException) Git(org.eclipse.jgit.api.Git) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) CommitCommand(org.eclipse.jgit.api.CommitCommand)

Example 7 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.

the class TestRepository method commit.

/**
 * Commits the current index
 *
 * @param message
 *            commit message
 * @return commit object
 *
 * @throws NoHeadException
 * @throws NoMessageException
 * @throws UnmergedPathException
 * @throws ConcurrentRefUpdateException
 * @throws JGitInternalException
 * @throws GitAPIException
 * @throws WrongRepositoryStateException
 */
public RevCommit commit(String message) throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException, GitAPIException {
    try (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();
    }
}
Also used : Git(org.eclipse.jgit.api.Git) CommitCommand(org.eclipse.jgit.api.CommitCommand)

Example 8 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project egit by eclipse.

the class AbstractGitflowHandlerTest method setContentAddAndCommit.

protected RevCommit setContentAddAndCommit(String newContent) throws Exception, GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException, IOException {
    setTestFileContent(newContent);
    Git git = Git.wrap(repository);
    git.add().addFilepattern(".").call();
    CommitCommand commit = git.commit().setMessage(newContent);
    commit.setAuthor(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL);
    commit.setCommitter(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL);
    return commit.call();
}
Also used : Git(org.eclipse.jgit.api.Git) CommitCommand(org.eclipse.jgit.api.CommitCommand)

Example 9 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project Android-Password-Store by zeapo.

the class GitAsyncTask method doInBackground.

@Override
protected String doInBackground(GitCommand... commands) {
    Integer nbChanges = null;
    for (GitCommand command : commands) {
        Log.d("doInBackground", "Executing the command <" + command.toString() + ">");
        try {
            if (command instanceof StatusCommand) {
                // in case we have changes, we want to keep track of it
                org.eclipse.jgit.api.Status status = ((StatusCommand) command).call();
                nbChanges = status.getChanged().size() + status.getMissing().size();
            } else if (command instanceof CommitCommand) {
                // the previous status will eventually be used to avoid a commit
                if (nbChanges == null || nbChanges > 0)
                    command.call();
            } else if (command instanceof PushCommand) {
                for (final PushResult result : ((PushCommand) command).call()) {
                    // Code imported (modified) from Gerrit PushOp, license Apache v2
                    for (final RemoteRefUpdate rru : result.getRemoteUpdates()) {
                        switch(rru.getStatus()) {
                            case REJECTED_NONFASTFORWARD:
                                return activity.getString(R.string.git_push_nff_error);
                            case REJECTED_NODELETE:
                            case REJECTED_REMOTE_CHANGED:
                            case NON_EXISTING:
                            case NOT_ATTEMPTED:
                                return activity.getString(R.string.git_push_generic_error) + rru.getStatus().name();
                            case REJECTED_OTHER_REASON:
                                if ("non-fast-forward".equals(rru.getMessage())) {
                                    return activity.getString(R.string.git_push_other_error);
                                } else {
                                    return activity.getString(R.string.git_push_generic_error) + rru.getMessage();
                                }
                            default:
                                break;
                        }
                    }
                }
            } else {
                command.call();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage() + "\nCaused by:\n" + e.getCause();
        }
    }
    return "";
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) CommitCommand(org.eclipse.jgit.api.CommitCommand) PushResult(org.eclipse.jgit.transport.PushResult) StatusCommand(org.eclipse.jgit.api.StatusCommand) PushCommand(org.eclipse.jgit.api.PushCommand) GitCommand(org.eclipse.jgit.api.GitCommand)

Example 10 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project jbosstools-openshift by jbosstools.

the class TestRepository method commit.

/**
 * Commits the current index
 *
 * @param message
 *            commit message
 * @return commit object
 *
 * @throws UnmergedPathException
 * @throws JGitInternalException
 * @throws GitAPIException
 * @throws UnmergedPathsException
 */
public RevCommit commit(String message) throws UnmergedPathException, JGitInternalException, UnmergedPathsException, 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();
}
Also used : Git(org.eclipse.jgit.api.Git) CommitCommand(org.eclipse.jgit.api.CommitCommand)

Aggregations

CommitCommand (org.eclipse.jgit.api.CommitCommand)16 Git (org.eclipse.jgit.api.Git)10 AddCommand (org.eclipse.jgit.api.AddCommand)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 File (java.io.File)4 PushCommand (org.eclipse.jgit.api.PushCommand)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 PushResult (org.eclipse.jgit.transport.PushResult)3 IOException (java.io.IOException)2 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 Repository (org.eclipse.jgit.lib.Repository)2 RefSpec (org.eclipse.jgit.transport.RefSpec)2 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)2 Context (android.content.Context)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Files (com.google.common.io.Files)1 JSch (com.jcraft.jsch.JSch)1