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);
}
}
Aggregations