Detect git better

.git can be a file with a special format, not just a directory. This is
commonly used for submodules.

Also verify that the layout of the .git dir includes the 3 required
children that git itself uses to decide if the directory is a valid git
directory.

Note: I wrote the path functions such that they should work on Windows, but I have no way to actually test Windows support.