Search in sources :

Example 1 with AddCommand

use of org.eclipse.jgit.api.AddCommand in project che by eclipse.

the class JGitConnection method add.

@Override
public void add(AddParams params) throws GitException {
    AddCommand addCommand = getGit().add().setUpdate(params.isUpdate());
    List<String> filePatterns = params.getFilePattern();
    if (filePatterns.isEmpty()) {
        filePatterns = AddRequest.DEFAULT_PATTERN;
    }
    filePatterns.forEach(addCommand::addFilepattern);
    try {
        addCommand.call();
        addDeletedFilesToIndex(filePatterns);
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitException(org.eclipse.che.api.git.exception.GitException) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 2 with AddCommand

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

the class GitManager method addAndCommitPaths.

public GitManager addAndCommitPaths(final ChangeSummary summary, final Collection<String> paths) throws GitSubsystemException {
    lockAnd(me -> {
        if (!verifyChangesExist(paths)) {
            logger.info("No actual changes in:\n  {}\n\nSkipping commit.", join(paths, "\n  "));
            return this;
        }
        try {
            final AddCommand add = git.add();
            final CommitCommand commit = git.commit();
            for (final String filepath : paths) {
                add.addFilepattern(filepath);
            }
            logger.info("Adding:\n  " + join(paths, "\n  ") + "\n\nSummary: " + summary);
            add.call();
            commit.setMessage(buildMessage(summary, paths)).setAuthor(summary.getUser(), email).call();
        } catch (final NoFilepatternException e) {
            throw new GitSubsystemException("Cannot add to git: " + e.getMessage(), e);
        } catch (final GitAPIException e) {
            throw new GitSubsystemException("Cannot add to git: " + e.getMessage(), e);
        }
        return me;
    });
    return this;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoFilepatternException(org.eclipse.jgit.api.errors.NoFilepatternException) CommitCommand(org.eclipse.jgit.api.CommitCommand) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) AddCommand(org.eclipse.jgit.api.AddCommand)

Aggregations

AddCommand (org.eclipse.jgit.api.AddCommand)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)1 GitException (org.eclipse.che.api.git.exception.GitException)1 CommitCommand (org.eclipse.jgit.api.CommitCommand)1 NoFilepatternException (org.eclipse.jgit.api.errors.NoFilepatternException)1