A repository that shows up as plain files brings its own git configuration along, and that configuration decides which programs a git run starts. Before anyone types a command, an inspector has to answer one narrow question: which directory would git take its hooks from, and what is sitting in it. The interesting case is the one where that directory lies outside the checkout, and the answer there cannot be the answer the inspector gives to a .git file pointing out of the tree.
Two rules in the same tree
I wrote repo.Resolve in gitdisarm to read a checkout's pointer files as data: .git as a directory, as a symlink, or as a file carrying a gitdir: line taken relative to the directory holding it; the commondir pointer a linked worktree leaves in its git directory; the gitdir pointer that leads back to that worktree's own .git file. Every one of those paths has to stay inside the checkout. One that leaves it refuses the repository outright:
type EscapeError struct { // Pointer is the file that named the path.…