IsValidGitDir UNC path performance bug fix (resolves #2250)

At the moment, when executing `IsValidGitDir` on the UNC path `\\server\share\dir`, it tests the following paths: 
- `\\server\share\dir\.git` and `\\server\share\dir\info`
- `\\server\share\.git` and `\\server\share\info`
- `\\server\.git` and `\\server\info`, 
- `\\.git` and `\\info`

The last 2 paths cause the performance issue because the OS tries to reach the servers `.git` and `info`.

This PR fixes #2250.

This PR contains a second bug fix: Fixed undetected working directory in root directory (the additional `dir.rfind` in the while condition stopped the loop when e.g. `C:` has been reached).

As I'm not a C++ hacker please review this PR carefully.