switch (operation) {
case ABORT:
try {
return abort(RebaseResult.ABORTED_RESULT);
} catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe);
}
case SKIP:
// fall through
case CONTINUE:
String upstreamCommitName = readFile(rebaseDir, ONTO);
this.upstreamCommit = walk.parseCommit(repo
.resolve(upstreamCommitName));
break;
case BEGIN:
RebaseResult res = initFilesAndRewind();
if (res != null)
return res;
}
if (monitor.isCancelled())
return abort(RebaseResult.ABORTED_RESULT);
if (operation == Operation.CONTINUE)
newHead = continueRebase();
if (operation == Operation.SKIP)
newHead = checkoutCurrentHead();
ObjectReader or = repo.newObjectReader();
List<Step> steps = loadSteps();
for (Step step : steps) {
popSteps(1);
Collection<ObjectId> ids = or.resolve(step.commit);
if (ids.size() != 1)
throw new JGitInternalException(
"Could not resolve uniquely the abbreviated object ID");
RevCommit commitToPick = walk
.parseCommit(ids.iterator().next());
if (monitor.isCancelled())
return new RebaseResult(commitToPick);
try {
monitor.beginTask(MessageFormat.format(
JGitText.get().applyingCommit,
commitToPick.getShortMessage()),
ProgressMonitor.UNKNOWN);
// if the first parent of commitToPick is the current HEAD,
// we do a fast-forward instead of cherry-pick to avoid
// unnecessary object rewriting
newHead = tryFastForward(commitToPick);
lastStepWasForward = newHead != null;
if (!lastStepWasForward) {
// TODO if the content of this commit is already merged
// here we should skip this step in order to avoid
// confusing pseudo-changed
CherryPickResult cherryPickResult = new Git(repo)
.cherryPick().include(commitToPick).call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(new RebaseResult(
cherryPickResult.getFailingPaths()));
else
return stop(commitToPick);
case CONFLICTING:
return stop(commitToPick);
case OK:
newHead = cherryPickResult.getNewHead();
}
}
} finally {
monitor.endTask();
}
}
if (newHead != null) {
String headName = readFile(rebaseDir, HEAD_NAME);
updateHead(headName, newHead);
FileUtils.delete(rebaseDir, FileUtils.RECURSIVE);
if (lastStepWasForward)
return RebaseResult.FAST_FORWARD_RESULT;
return RebaseResult.OK_RESULT;
}
return RebaseResult.FAST_FORWARD_RESULT;
} catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe);
}
}