in org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java [248:364]
public RebaseResult call() throws GitAPIException, NoHeadException,
RefNotFoundException, WrongRepositoryStateException {
newHead = null;
lastStepWasForward = false;
checkCallable();
checkParameters();
commitConfig = repo.getConfig().get(CommitConfig.KEY);
try {
switch (operation) {
case ABORT:
try {
return abort(RebaseResult.ABORTED_RESULT);
} catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe);
}
case PROCESS_STEPS:
case SKIP:
case CONTINUE:
String upstreamCommitId = rebaseState.readFile(ONTO);
try {
upstreamCommitName = rebaseState.readFile(ONTO_NAME);
} catch (FileNotFoundException e) {
// Fall back to commit ID if file doesn't exist (e.g. rebase
// was started by C Git)
upstreamCommitName = upstreamCommitId;
}
this.upstreamCommit = walk.parseCommit(repo
.resolve(upstreamCommitId));
preserveMerges = rebaseState.getRewrittenDir().isDirectory();
break;
case BEGIN:
autoStash();
if (stopAfterInitialization
|| !walk.isMergedInto(
walk.parseCommit(repo.resolve(Constants.HEAD)),
upstreamCommit)) {
org.eclipse.jgit.api.Status status = Git.wrap(repo)
.status().setIgnoreSubmodules(IgnoreSubmoduleMode.ALL).call();
if (status.hasUncommittedChanges()) {
List<String> list = new ArrayList<>();
list.addAll(status.getUncommittedChanges());
return RebaseResult.uncommittedChanges(list);
}
}
RebaseResult res = initFilesAndRewind();
if (stopAfterInitialization)
return RebaseResult.INTERACTIVE_PREPARED_RESULT;
if (res != null) {
autoStashApply();
if (rebaseState.getDir().exists())
FileUtils.delete(rebaseState.getDir(),
FileUtils.RECURSIVE);
return res;
}
}
if (monitor.isCancelled())
return abort(RebaseResult.ABORTED_RESULT);
if (operation == Operation.CONTINUE) {
newHead = continueRebase();
List<RebaseTodoLine> doneLines = repo.readRebaseTodo(
rebaseState.getPath(DONE), true);
RebaseTodoLine step = doneLines.get(doneLines.size() - 1);
if (newHead != null
&& step.getAction() != Action.PICK) {
RebaseTodoLine newStep = new RebaseTodoLine(
step.getAction(),
AbbreviatedObjectId.fromObjectId(newHead),
step.getShortMessage());
RebaseResult result = processStep(newStep, false);
if (result != null)
return result;
}
File amendFile = rebaseState.getFile(AMEND);
boolean amendExists = amendFile.exists();
if (amendExists) {
FileUtils.delete(amendFile);
}
if (newHead == null && !amendExists) {
// continueRebase() returns null only if no commit was
// neccessary. This means that no changes where left over
// after resolving all conflicts. In this case, cgit stops
// and displays a nice message to the user, telling him to
// either do changes or skip the commit instead of continue.
return RebaseResult.NOTHING_TO_COMMIT_RESULT;
}
}
if (operation == Operation.SKIP)
newHead = checkoutCurrentHead();
List<RebaseTodoLine> steps = repo.readRebaseTodo(
rebaseState.getPath(GIT_REBASE_TODO), false);
if (steps.isEmpty()) {
return finishRebase(walk.parseCommit(repo.resolve(Constants.HEAD)), false);
}
if (isInteractive()) {
interactiveHandler.prepareSteps(steps);
repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO),
steps, false);
}
checkSteps(steps);
for (RebaseTodoLine step : steps) {
popSteps(1);
RebaseResult result = processStep(step, true);
if (result != null) {
return result;
}
}
return finishRebase(newHead, lastStepWasForward);
} catch (CheckoutConflictException cce) {
return RebaseResult.conflicts(cce.getConflictingPaths());
} catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe);
}
}