def get_dataset_root(path):
    "Return the root of an existent dataset containing a given path\n\n    The root path is returned in the same absolute or relative form\n    as the input argument. If no associated dataset exists, or the\n    input path doesn't exist, None is returned.\n\n    If `path` is a symlink or something other than a directory, its\n    the root dataset containing its parent directory will be reported.\n    If none can be found, at a symlink at `path` is pointing to a\n    dataset, `path` itself will be reported as the root.\n\n    Parameters\n    ----------\n    path : Path-like\n\n    Returns\n    -------\n    str or None\n    "
    path = str(path)
    suffix = '.git'
    altered = None
    if (islink(path) or (not isdir(path))):
        altered = path
        path = dirname(path)
    apath = abspath(path)
    while split(apath)[1]:
        if exists(op.join(path, suffix)):
            return path
        path = normpath(op.join(path, os.pardir))
        apath = abspath(path)
    if (altered and exists(op.join(altered, suffix))):
        return altered
    return None
Return the root of an existent dataset containing a given path

The root path is returned in the same absolute or relative form
as the input argument. If no associated dataset exists, or the
input path doesn't exist, None is returned.

If `path` is a symlink or something other than a directory, its
the root dataset containing its parent directory will be reported.
If none can be found, at a symlink at `path` is pointing to a
dataset, `path` itself will be reported as the root.

Parameters
----------
path : Path-like

Returns
-------
str or None
def get_dataset_root(path):
    "Return the root of an existent dataset containing a given path\n\n    The root path is returned in the same absolute or relative form\n    as the input argument. If no associated dataset exists, or the\n    input path doesn't exist, None is returned.\n\n    If `path` is a symlink or something other than a directory, its\n    the root dataset containing its parent directory will be reported.\n    If none can be found, at a symlink at `path` is pointing to a\n    dataset, `path` itself will be reported as the root.\n\n    Parameters\n    ----------\n    path : Path-like\n\n    Returns\n    -------\n    str or None\n    "
    path = str(path)
    suffix = '.git'
    altered = None
    if (islink(path) or (not isdir(path))):
        altered = path
        path = dirname(path)
    apath = abspath(path)
    while split(apath)[1]:
        if exists(op.join(path, suffix)):
            return path
        path = normpath(op.join(path, os.pardir))
        apath = abspath(path)
    if (altered and exists(op.join(altered, suffix))):
        return altered
    return None