Search in sources :

Example 1 with RmCommand

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

the class JGitConnection method addDeletedFilesToIndex.

/** To add deleted files in index it is required to perform git rm on them */
private void addDeletedFilesToIndex(List<String> filePatterns) throws GitAPIException {
    Set<String> deletedFiles = getGit().status().call().getMissing();
    if (!deletedFiles.isEmpty()) {
        RmCommand rmCommand = getGit().rm();
        if (filePatterns.contains(".")) {
            deletedFiles.forEach(rmCommand::addFilepattern);
        } else {
            filePatterns.forEach(filePattern -> deletedFiles.stream().filter(deletedFile -> deletedFile.startsWith(filePattern)).forEach(rmCommand::addFilepattern));
        }
        rmCommand.call();
    }
}
Also used : RmCommand(org.eclipse.jgit.api.RmCommand)

Example 2 with RmCommand

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

the class JGitConnection method rm.

@Override
public void rm(RmParams params) throws GitException {
    List<String> files = params.getItems();
    RmCommand rmCommand = getGit().rm();
    rmCommand.setCached(params.isCached());
    if (files != null) {
        files.forEach(rmCommand::addFilepattern);
    }
    try {
        rmCommand.call();
    } 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) RmCommand(org.eclipse.jgit.api.RmCommand)

Example 3 with RmCommand

use of org.eclipse.jgit.api.RmCommand 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)

Aggregations

RmCommand (org.eclipse.jgit.api.RmCommand)3 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 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)1 NoFilepatternException (org.eclipse.jgit.api.errors.NoFilepatternException)1