Like with the 2-tree form of processEntry, I think you want actually a 4th tree here, the WorkingTreeIterator.

Yea, its ugly.  You are trying to do a merge across 4 things:

 * HEAD
 * index
 * working directory
 * target tree

And the rules are about how working directory needs to match index and/or HEAD in order for an edit from target to be applied.