private boolean rebase(HttpServletRequest request, HttpServletResponse response, Repository db, String commitToRebase, String rebaseOperation)
throws ServletException, JSONException, AmbiguousObjectException, IOException {
JSONObject result = new JSONObject();
try {
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) {