Search in sources :

Example 1 with ResetCommand

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

the class JGitConnection method reset.

@Override
public void reset(ResetParams params) throws GitException {
    try {
        ResetCommand resetCommand = getGit().reset();
        resetCommand.setRef(params.getCommit());
        List<String> patterns = params.getFilePattern();
        patterns.forEach(resetCommand::addPath);
        if (params.getType() != null && patterns.isEmpty()) {
            switch(params.getType()) {
                case HARD:
                    resetCommand.setMode(ResetType.HARD);
                    break;
                case KEEP:
                    resetCommand.setMode(ResetType.KEEP);
                    break;
                case MERGE:
                    resetCommand.setMode(ResetType.MERGE);
                    break;
                case MIXED:
                    resetCommand.setMode(ResetType.MIXED);
                    break;
                case SOFT:
                    resetCommand.setMode(ResetType.SOFT);
                    break;
            }
        }
        resetCommand.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) ResetCommand(org.eclipse.jgit.api.ResetCommand)

Aggregations

GitException (org.eclipse.che.api.git.exception.GitException)1 ResetCommand (org.eclipse.jgit.api.ResetCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1