Better detection of git/non-git repository.

Fix #498