Patch Set 3: I would prefer that you didn't submit this

The invalid file mode bug has been fixed.  Unstaging however seems completely broken.  When I unstage a change the index is updated to a blob which matches the working tree instead of HEAD so 'git status' doesn't see any change but the change is there in the working tree.  I'm quite confused by this behaviour and have tried a few variations of the implementation but can't find the bug.