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

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

Introduction

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

Prototype

@Override
public CherryPickResult call() throws GitAPIException, NoMessageException, UnmergedPathsException,
        ConcurrentRefUpdateException, WrongRepositoryStateException, NoHeadException 

Source Link

Document

Executes the Cherry-Pick command with all the options and parameters collected by the setter methods (e.g.

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 ww  . j a v a2 s. c o 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);
        }
    }

}

From source file:org.eclipse.egit.core.op.CherryPickOperation.java

License:Open Source License

public void execute(IProgressMonitor m) throws CoreException {
    IProgressMonitor monitor = m != null ? m : new NullProgressMonitor();
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        public void run(IProgressMonitor pm) throws CoreException {
            pm.beginTask("", 2); //$NON-NLS-1$

            pm.subTask(MessageFormat.format(CoreText.CherryPickOperation_cherryPicking, commit.name()));
            CherryPickCommand command = new Git(repo).cherryPick().include(commit.getId());
            try {
                result = command.call();
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            }//from   w ww  .j a  v  a 2 s. co m
            pm.worked(1);

            ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(repo),
                    new SubProgressMonitor(pm, 1));

            pm.done();
        }
    };
    ResourcesPlugin.getWorkspace().run(action, monitor);
}

From source file:org.eclipse.egit.ui.internal.history.command.CherryPickHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    RevCommit commit = (RevCommit) getSelection(getPage()).getFirstElement();
    RevCommit newHead;//from ww  w .  ja  va 2  s. co m
    Repository repo = getRepository(event);

    CherryPickCommand cherryPick;
    Git git = new Git(repo);
    try {
        cherryPick = git.cherryPick().include(commit.getId());
        newHead = cherryPick.call();
    } catch (Exception e) {
        throw new ExecutionException(CoreText.CherryPickOperation_InternalError, e);
    }
    if (newHead == null)
        throw new ExecutionException(CoreText.CherryPickOperation_Failed);
    return null;
}