def is_git_dir(self, d):
        isdir = os.path.isdir
        join = os.path.join
        isfile = os.path.isfile
        islink = os.path.islink
        if isdir(d) and (isdir(join(d, 'objects')) and
                isdir(join(d, 'refs'))):
            headref = join(d, 'HEAD')
            return isfile(headref) or (
                     islink(headref) and
                     os.readlink(headref).startswith('refs'))
        return False
This is taken from the git setup.c:is_git_directory.
dataset/ETHPy150Open douban/sina/sina/ghttp.py/GHTTPServer.is_git_dir