Example usage for org.eclipse.jgit.api CherryPickCommand include

List of usage examples for org.eclipse.jgit.api CherryPickCommand include

Introduction

In this page you can find the example usage for org.eclipse.jgit.api CherryPickCommand include.

Prototype

public CherryPickCommand include(AnyObjectId commit) 

Source Link

Document

Include a commit

Usage

From source file:org.craftercms.studio.impl.v1.repository.git.GitContentRepository.java

License:Open Source License

@Override
public void publish(String site, List<String> commitIds, String environment, String author, String comment) {
    Repository repo = helper.getRepository(site, GitRepositories.PUBLISHED);

    synchronized (helper.getRepository(site, GitRepositories.PUBLISHED)) {
        try (Git git = new Git(repo)) {
            // fetch "origin/master"
            FetchResult fetchResult = git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call();

            // checkout environment branch
            Ref checkoutResult = git.checkout().setCreateBranch(true).setName(environment).call();

            // cherry pick all commit ids
            CherryPickCommand cherryPickCommand = git.cherryPick().setStrategy(MergeStrategy.THEIRS);
            for (String commitId : commitIds) {
                ObjectId objectId = ObjectId.fromString(commitId);
                cherryPickCommand.include(objectId);
            }//from  w  w w  .ja  v  a 2s.  co m
            CherryPickResult cherryPickResult = cherryPickCommand.call();

            // tag
            PersonIdent authorIdent = helper.getAuthorIdent(author);
            Ref tagResult = git.tag().setTagger(authorIdent).setMessage(comment).call();
        } catch (GitAPIException e) {
            logger.error("Error when publishing site " + site + " to environment " + environment, e);
        }
    }

}