def guess_worktree(cwd=None, raises=False):
    """Look for parent directories until a .qi dir is found somewhere."""
    if cwd is None:
        try:
            cwd = os.getcwd()
        except __HOLE__ as e:
            raise qisys.error.Error("Working directory is not an existing directory")
    cwd = qisys.sh.to_native_path(cwd)
    head = cwd
    _tail = True
    while _tail:
        if is_worktree(head):
            return head
        (head, _tail) = os.path.split(head)
    if raises:
        raise NotInWorkTree()
    else:
        return None
dataset/ETHPy150Open aldebaran/qibuild/python/qisys/worktree.py/guess_worktree