Search in sources :

Example 1 with CherryPickResult

use of org.eclipse.jgit.api.CherryPickResult in project camel by apache.

the class GitProducer method doCherryPick.

protected void doCherryPick(Exchange exchange, String operation) throws Exception {
    CherryPickResult result = null;
    String commitId = null;
    try {
        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(GitConstants.GIT_COMMIT_ID))) {
            commitId = exchange.getIn().getHeader(GitConstants.GIT_COMMIT_ID, String.class);
        } else {
            throw new IllegalArgumentException("Commit id must be specified to execute " + operation);
        }
        RevWalk walk = new RevWalk(repo);
        ObjectId id = repo.resolve(commitId);
        RevCommit commit = walk.parseCommit(id);
        walk.dispose();
        if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
            git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
        }
        result = git.cherryPick().include(commit).call();
    } catch (Exception e) {
        LOG.error("There was an error in Git " + operation + " operation");
        throw e;
    }
    updateExchange(exchange, result);
}
Also used : CherryPickResult(org.eclipse.jgit.api.CherryPickResult) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

IOException (java.io.IOException)1 CherryPickResult (org.eclipse.jgit.api.CherryPickResult)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1