You are too fast for me :-) In order to explain what I wanted I was trying out the following lines here:

if (walk.isMergedInto(upstreamCommit, headCommit)) {
  return RebaseResult.UP_TO_DATE_RESULT;
} else if (walk.isMergedInto(headCommit, upstreamCommit)) {
  checkoutCommit(upstreamCommit);
  updatePreviousHead(headName, upstreamCommit);
  return new RebaseResult(RebaseResult.Status.FAST_FORWARD);
}

... just to see that your latest proposal is the nearly the same. I would only change your check for UP_TO_DATE_RESULT to mine. Imagine somebody invokes a rebase of HEAD to HEAD~3. That's also an up-to-date result