common: properly locate .hg or .git directories