

def find_git_dir(d):
    if is_git_dir(d):
        return d
    try:
        with open(d) as fp:
            content = fp.read().rstrip()
    except (IOError, OSError):
        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)
    return None

dataset/ETHPy150Open gitpython-developers/GitPython/git/repo/fun.py find_git_dir/original