def find_git_dir(d):
    if is_git_dir(d):
        return d

    try:
        with open(d) as fp:
            content = fp.read().rstrip()
    except (IOError, __HOLE__):
        # it's probably not a file
        pass
    else:
        if content.startswith('gitdir: '):
            path = content[8:]
            if not os.path.isabs(path):
                path = join(dirname(d), path)
            return find_git_dir(path)
    # end handle exception
    return None
dataset/ETHPy150Open gitpython-developers/GitPython/git/repo/fun.py/find_git_dir