This will prevent half-written content on disk in case the write is interrupted.
Lock files are *not* used as the assumption is that a lock is held centrally.
This also rewrites some other checks in preference of opening the git directory
in isolation. Doing so is very fast, and the only way to know for certain if a
repository is bare.
In future, once the repository is more separated from the worktree (in terms of mindset)
it should be possible to handle bare repos with worktrees as well.