Search in sources :

Example 11 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project indy by Commonjava.

the class GitManager method deleteAndCommitPaths.

public GitManager deleteAndCommitPaths(final ChangeSummary summary, final Collection<String> paths) throws GitSubsystemException {
    lockAnd(me -> {
        try {
            RmCommand rm = git.rm();
            CommitCommand commit = git.commit();
            for (final String path : paths) {
                rm = rm.addFilepattern(path);
                commit = commit.setOnly(path);
            }
            logger.info("Deleting:\n  " + join(paths, "\n  ") + "\n\nSummary: " + summary);
            rm.call();
            commit.setMessage(buildMessage(summary, paths)).setAuthor(summary.getUser(), email).call();
        } catch (final NoFilepatternException e) {
            throw new GitSubsystemException("Cannot remove from git: " + e.getMessage(), e);
        } catch (final JGitInternalException | GitAPIException e) {
            throw new GitSubsystemException("Cannot remove from git: " + e.getMessage(), e);
        }
        return me;
    });
    return this;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoFilepatternException(org.eclipse.jgit.api.errors.NoFilepatternException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) RmCommand(org.eclipse.jgit.api.RmCommand) CommitCommand(org.eclipse.jgit.api.CommitCommand) JoinString(org.commonjava.maven.atlas.ident.util.JoinString)

Example 12 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project MGit by maks.

the class CommitChangesTask method commit.

public static void commit(Repo repo, boolean stageAll, boolean isAmend, String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, GitAPIException, StopTaskException {
    Context context = SGitApplication.getContext();
    StoredConfig config = repo.getGit().getRepository().getConfig();
    String committerEmail = config.getString("user", null, "email");
    String committerName = config.getString("user", null, "name");
    if (committerName == null || committerName.equals("")) {
        committerName = Profile.getUsername(context);
    }
    if (committerEmail == null || committerEmail.equals("")) {
        committerEmail = Profile.getEmail(context);
    }
    if (committerName.isEmpty() || committerEmail.isEmpty()) {
        throw new Exception("Please set your name and email");
    }
    if (msg.isEmpty()) {
        throw new Exception("Please include a commit message");
    }
    CommitCommand cc = repo.getGit().commit().setCommitter(committerName, committerEmail).setAll(stageAll).setAmend(isAmend).setMessage(msg);
    if (authorName != null && authorEmail != null) {
        cc.setAuthor(authorName, authorEmail);
    }
    cc.call();
    repo.updateLatestCommitInfo();
}
Also used : Context(android.content.Context) StoredConfig(org.eclipse.jgit.lib.StoredConfig) CommitCommand(org.eclipse.jgit.api.CommitCommand) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) StopTaskException(me.sheimi.sgit.exception.StopTaskException) UnmergedPathsException(org.eclipse.jgit.api.errors.UnmergedPathsException) NoMessageException(org.eclipse.jgit.api.errors.NoMessageException)

Example 13 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepository method commitChanges.

@Override
public RevCommit commitChanges(String commitMessage, boolean amend) throws GitAPIException, IOException {
    try (Git git = Git.open(getLocalRepositoryFolder())) {
        Status status = git.status().call();
        // Nothing changed
        if (status.isClean()) {
            return null;
        }
        // Add modified files to index
        AddCommand addCommand = git.add();
        // $NON-NLS-1$
        addCommand.addFilepattern(".");
        addCommand.setUpdate(false);
        addCommand.call();
        // Add missing files to index
        for (String s : status.getMissing()) {
            git.rm().addFilepattern(s).call();
        }
        // Commit
        CommitCommand commitCommand = git.commit();
        PersonIdent userDetails = getUserDetails();
        commitCommand.setAuthor(userDetails);
        commitCommand.setMessage(commitMessage);
        commitCommand.setAmend(amend);
        return commitCommand.call();
    }
}
Also used : Status(org.eclipse.jgit.api.Status) BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus) Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) CommitCommand(org.eclipse.jgit.api.CommitCommand) AddCommand(org.eclipse.jgit.api.AddCommand) RemoteAddCommand(org.eclipse.jgit.api.RemoteAddCommand)

Example 14 with CommitCommand

use of org.eclipse.jgit.api.CommitCommand in project archi-modelrepository-plugin by archi-contribs.

the class MergeConflictHandler method mergeAndCommit.

public void mergeAndCommit(String commitMessage, boolean amend) throws IOException, GitAPIException {
    merge();
    try (Git git = Git.open(fArchiRepo.getLocalRepositoryFolder())) {
        // Add to index all files
        AddCommand addCommand = git.add();
        // $NON-NLS-1$
        addCommand.addFilepattern(".");
        addCommand.setUpdate(false);
        addCommand.call();
        // Commit
        CommitCommand commitCommand = git.commit();
        PersonIdent userDetails = fArchiRepo.getUserDetails();
        commitCommand.setAuthor(userDetails);
        commitCommand.setMessage(commitMessage);
        commitCommand.setAmend(amend);
        commitCommand.call();
    }
}
Also used : Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) CommitCommand(org.eclipse.jgit.api.CommitCommand) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 15 with CommitCommand

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

the class CommitOperation method commit.

private void commit() throws TeamException {
    try (Git git = new Git(repo)) {
        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);
    }
}
Also used : TeamException(org.eclipse.team.core.TeamException) Git(org.eclipse.jgit.api.Git) CommitCommand(org.eclipse.jgit.api.CommitCommand) CoreException(org.eclipse.core.runtime.CoreException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) TeamException(org.eclipse.team.core.TeamException)

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