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.
Merge pull request #325 from kballard/git_detect_fix

Detect git better