Example usage for org.eclipse.jgit.api RebaseCommand setOperation

List of usage examples for org.eclipse.jgit.api RebaseCommand setOperation

Introduction

In this page you can find the example usage for org.eclipse.jgit.api RebaseCommand setOperation.

Prototype

public RebaseCommand setOperation(Operation operation) 

Source Link

Document

Set the operation to execute during rebase

Usage

From source file:com.sap.dirigible.ide.jgit.connector.JGitConnector.java

License:Open Source License

/**
 * //from   ww  w .j a  v a  2s.co  m
 * Tries to rebase the selected branch on top of the current one.
 * 
 * @param name
 *            the branch to rebase
 * @throws NoHeadException
 * @throws WrongRepositoryStateException
 * @throws GitAPIException
 */
public void rebase(String name) throws NoHeadException, WrongRepositoryStateException, GitAPIException {
    RebaseCommand rebaseCommand = git.rebase();
    rebaseCommand.setOperation(Operation.BEGIN);
    rebaseCommand.setUpstream(name);
    rebaseCommand.call();
}

From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java

License:Open Source License

private void setRebaseOperation(RebaseCommand rebaseCommand, RebaseRequest request) {
    RebaseCommand.Operation op = RebaseCommand.Operation.BEGIN;

    // If other operation other than 'BEGIN' was specified, set it
    if (request.getOperation() != null) {
        switch (request.getOperation()) {
        case REBASE_OPERATION_ABORT:
            op = RebaseCommand.Operation.ABORT;
            break;
        case REBASE_OPERATION_CONTINUE:
            op = RebaseCommand.Operation.CONTINUE;
            break;
        case REBASE_OPERATION_SKIP:
            op = RebaseCommand.Operation.SKIP;
            break;
        default:/* w  w  w  . jav  a  2s.  c  o m*/
            op = RebaseCommand.Operation.BEGIN;
            break;
        }
    }
    rebaseCommand.setOperation(op);
}

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

License:Open Source License

public void execute(IProgressMonitor m) throws CoreException {
    if (result != null)
        throw new CoreException(
                new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
    IProgressMonitor monitor;//from   w  w  w  . ja  v  a2s  .  c  om
    if (m == null)
        monitor = new NullProgressMonitor();
    else
        monitor = m;

    IWorkspaceRunnable action = new IWorkspaceRunnable() {
        public void run(IProgressMonitor actMonitor) throws CoreException {
            RebaseCommand cmd = new Git(repository).rebase()
                    .setProgressMonitor(new EclipseGitProgressTransformer(actMonitor));
            try {
                if (operation == Operation.BEGIN)
                    result = cmd.setUpstream(ref.getName()).call();
                else
                    result = cmd.setOperation(operation).call();

            } catch (NoHeadException e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            } catch (RefNotFoundException e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            } catch (JGitInternalException e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            } catch (GitAPIException e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, monitor);
}

From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java

License:Open Source License

private boolean rebase(HttpServletRequest request, HttpServletResponse response, Repository db,
        String commitToRebase, String rebaseOperation)
        throws ServletException, JSONException, AmbiguousObjectException, IOException {
    JSONObject result = new JSONObject();
    try {/*from ww w.  ja  v a  2 s. co m*/
        Git git = new Git(db);
        RebaseCommand rebase = git.rebase();
        Operation operation;
        if (rebaseOperation != null) {
            operation = Operation.valueOf(rebaseOperation);
        } else {
            operation = Operation.BEGIN;
        }
        if (commitToRebase != null && !commitToRebase.isEmpty()) {
            ObjectId objectId = db.resolve(commitToRebase);
            rebase.setUpstream(objectId);
        } else if (operation.equals(Operation.BEGIN)) {
            return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                    HttpServletResponse.SC_BAD_REQUEST, "Missing commit refId.", null));
        }
        rebase.setOperation(operation);
        RebaseResult rebaseResult = rebase.call();
        result.put(GitConstants.KEY_RESULT, rebaseResult.getStatus().name());
    } catch (UnmergedPathsException e) {
        // this error should be handled by client, so return a proper status
        result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_UNMERGED_PATHS.name());
    } catch (WrongRepositoryStateException e) {
        // this error should be handled by client, so return a proper status
        result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_WRONG_REPOSITORY_STATE.name());
    } catch (IllegalArgumentException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                HttpServletResponse.SC_BAD_REQUEST, "Invalid rebase operation.", e));
    } catch (GitAPIException e) {
        return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e));
    } catch (JGitInternalException e) {
        // get cause and try to handle 
        if (e.getCause() instanceof org.eclipse.jgit.errors.CheckoutConflictException) {
            // this error should be handled by client, so return a proper status
            result.put(GitConstants.KEY_RESULT, AdditionalRebaseStatus.FAILED_PENDING_CHANGES.name());
        } else {
            return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR,
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when rebasing.", e));
        }
    }
    OrionServlet.writeJSONResponse(request, response, result);
    return true;
}

From source file:org.jabylon.team.git.GitTeamProvider.java

License:Open Source License

@Override
public Collection<PropertyFileDiff> update(ProjectVersion project, IProgressMonitor monitor)
        throws TeamProviderException {

    SubMonitor subMon = SubMonitor.convert(monitor, 100);
    List<PropertyFileDiff> updatedFiles = new ArrayList<PropertyFileDiff>();
    try {//from  w ww.j  ava2s. co m
        Repository repository = createRepository(project);
        Git git = Git.wrap(repository);
        FetchCommand fetchCommand = git.fetch();
        URI uri = project.getParent().getRepositoryURI();
        if (uri != null)
            fetchCommand.setRemote(stripUserInfo(uri).toString());
        String refspecString = "refs/heads/{0}:refs/remotes/origin/{0}";
        refspecString = MessageFormat.format(refspecString, project.getName());
        RefSpec spec = new RefSpec(refspecString);
        fetchCommand.setRefSpecs(spec);
        subMon.subTask("Fetching from remote");
        if (!"https".equals(uri.scheme()) && !"http".equals(uri.scheme()))
            fetchCommand.setTransportConfigCallback(createTransportConfigCallback(project.getParent()));
        fetchCommand.setCredentialsProvider(createCredentialsProvider(project.getParent()));
        fetchCommand.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(80)));
        fetchCommand.call();
        ObjectId remoteHead = repository.resolve("refs/remotes/origin/" + project.getName() + "^{tree}");

        DiffCommand diff = git.diff();
        subMon.subTask("Caculating Diff");
        diff.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(20)));
        diff.setOldTree(new FileTreeIterator(repository));
        CanonicalTreeParser p = new CanonicalTreeParser();
        ObjectReader reader = repository.newObjectReader();
        try {
            p.reset(reader, remoteHead);
        } finally {
            reader.release();
        }
        diff.setNewTree(p);
        checkCanceled(subMon);
        List<DiffEntry> diffs = diff.call();
        for (DiffEntry diffEntry : diffs) {
            checkCanceled(subMon);
            updatedFiles.add(convertDiffEntry(diffEntry));
            LOGGER.trace(diffEntry.toString());
        }
        if (!updatedFiles.isEmpty()) {
            checkCanceled(subMon);
            //no more cancel after this point
            ObjectId lastCommitID = repository
                    .resolve("refs/remotes/origin/" + project.getName() + "^{commit}");
            LOGGER.info("Merging remote commit {} to {}/{}",
                    new Object[] { lastCommitID, project.getName(), project.getParent().getName() });
            //TODO: use rebase here?
            if (isRebase(project)) {
                RebaseCommand rebase = git.rebase();
                rebase.setUpstream("refs/remotes/origin/" + project.getName());
                RebaseResult result = rebase.call();
                if (result.getStatus().isSuccessful()) {
                    LOGGER.info("Rebase finished: {}", result.getStatus());
                } else {
                    LOGGER.error("Rebase of {} failed. Attempting abort", project.relativePath());
                    rebase = git.rebase();
                    rebase.setOperation(Operation.ABORT);
                    result = rebase.call();
                    LOGGER.error("Abort finished with {}", result.getStatus());
                }
            } else {
                MergeCommand merge = git.merge();
                merge.include(lastCommitID);
                MergeResult mergeResult = merge.call();

                LOGGER.info("Merge finished: {}", mergeResult.getMergeStatus());
            }
        } else
            LOGGER.info("Update finished successfully. Nothing to merge, already up to date");
    } catch (JGitInternalException e) {
        throw new TeamProviderException(e);
    } catch (InvalidRemoteException e) {
        throw new TeamProviderException(e);
    } catch (GitAPIException e) {
        throw new TeamProviderException(e);
    } catch (AmbiguousObjectException e) {
        throw new TeamProviderException(e);
    } catch (IOException e) {
        throw new TeamProviderException(e);
    } finally {
        monitor.done();
    }
    return updatedFiles;
}