Search in sources :

Example 1 with Status

use of org.eclipse.jgit.api.CheckoutResult.Status in project egit by eclipse.

the class GitFlowOperation method mergeTo.

/**
 * @param monitor
 * @param branchName
 * @param targetBranchName
 * @param squash
 * @param fastForwardSingleCommit Has no effect if {@code squash} is true.
 * @return result of merging back to targetBranchName
 * @throws CoreException
 * @since 4.1
 */
@NonNull
protected MergeResult mergeTo(IProgressMonitor monitor, String branchName, String targetBranchName, boolean squash, boolean fastForwardSingleCommit) throws CoreException {
    try {
        if (!repository.hasBranch(targetBranchName)) {
            throw new RuntimeException(String.format(CoreText.GitFlowOperation_branchNotFound, targetBranchName));
        }
        SubMonitor progress = SubMonitor.convert(monitor, 2);
        boolean dontCloseProjects = false;
        BranchOperation branchOperation = new BranchOperation(repository.getRepository(), targetBranchName, dontCloseProjects);
        branchOperation.execute(progress.newChild(1));
        Status status = branchOperation.getResult().getStatus();
        if (!CheckoutResult.Status.OK.equals(status)) {
            throw new CoreException(error(format(CoreText.GitFlowOperation_unableToCheckout, branchName, status.toString())));
        }
        MergeOperation mergeOperation = new MergeOperation(repository.getRepository(), branchName);
        mergeOperation.setSquash(squash);
        if (squash) {
            mergeOperation.setCommit(true);
        }
        if (!squash && (!fastForwardSingleCommit || hasMultipleCommits(branchName))) {
            mergeOperation.setFastForwardMode(NO_FF);
        }
        mergeOperation.execute(progress.newChild(1));
        MergeResult result = mergeOperation.getResult();
        if (result == null) {
            throw new CoreException(error(format(CoreText.GitFlowOperation_unableToMerge, branchName, targetBranchName)));
        }
        return result;
    } catch (GitAPIException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Status(org.eclipse.jgit.api.CheckoutResult.Status) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) MergeOperation(org.eclipse.egit.core.op.MergeOperation) CoreException(org.eclipse.core.runtime.CoreException) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) DeleteBranchOperation(org.eclipse.egit.core.op.DeleteBranchOperation) BranchOperation(org.eclipse.egit.core.op.BranchOperation) SubMonitor(org.eclipse.core.runtime.SubMonitor) MergeResult(org.eclipse.jgit.api.MergeResult) IOException(java.io.IOException) NonNull(org.eclipse.jgit.annotations.NonNull)

Aggregations

IOException (java.io.IOException)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 BranchOperation (org.eclipse.egit.core.op.BranchOperation)1 CreateLocalBranchOperation (org.eclipse.egit.core.op.CreateLocalBranchOperation)1 DeleteBranchOperation (org.eclipse.egit.core.op.DeleteBranchOperation)1 MergeOperation (org.eclipse.egit.core.op.MergeOperation)1 NonNull (org.eclipse.jgit.annotations.NonNull)1 Status (org.eclipse.jgit.api.CheckoutResult.Status)1 MergeResult (org.eclipse.jgit.api.MergeResult)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1