We know what we read head to above on line 391 with the parseCommit call.  If HEAD isn't that when the update occurs, we're screwed, as someone else has updated HEAD behind our backs.  Add in:

  refUpdate.setExpectedOldObjectId(head);

Also we have a RevWalk on hand, pass that to forceUpdate() so it doesn't need to allocate its own revision pool.