Earlier quoted context omitted.
If you add an echo "$file" inside the while loop, what do you see? I deliberately set the .git directory to be ignored (using @ ) to avoid tons of repeating when the index.lock file is repeatedly recreated. Maybe that's what's going on here.
index.lock CREATE index.lock DELETE alternating very fast.
I must have fumbled a key after pasting, as there was a dot missing; @/.git should read @./.git.
I'll add a note to the ancestor comment if I still can. Thanks and sorry!