This code will sometimes produce a conflict if Head and Merge commit are the same. You decide on throwing a conflict without looking at the Head commit and this cannot be true. Try this:

 git init
 echo 1>a
 git add a
 git commit -m initial
 echo 2>b
 git add b
 git commit -m second
 git checkout -b side HEAD~
 echo 3>a
 chmod a+x a
 git add a
 git checkout master

Native git allows the checkout without a conflict although index and working are dirty by all means (content and mode).

What we want to achieve is that during a checkout when we touch a file in the filesystem we should not silently overwrite the files mode. You failed to detect correctly when we touch a file in the filesystem.