Repository: iterative/dvc

Issue:
Interactive mode and all patterns mode for dvc check-ignore command
Follow #3736

Two more modes: 
1. interactive mode `--stdin` which reads pathnames from the standard input.
2. all patterns mode `--all` which prints all pattern matches instead of only the last one.

Discussion:

Patch:
diff --git a/dvc/command/check_ignore.py b/dvc/command/check_ignore.py
index ef3f1250b..e28f4f19b 100644
--- a/dvc/command/check_ignore.py
+++ b/dvc/command/check_ignore.py
@@ -4,6 +4,7 @@ import logging
 from dvc.command import completion
 from dvc.command.base import CmdBase, append_doc_link
 from dvc.exceptions import DvcException
+from dvc.prompt import ask
 
 logger = logging.getLogger(__name__)
 
@@ -14,27 +15,71 @@ class CmdCheckIgnore(CmdBase):
         self.ignore_filter = self.repo.tree.dvcignore
 
     def _show_results(self, result):
-        if result.match or self.args.non_matching:
-            if self.args.details:
-                logger.info("{}\t{}".format(result.patterns[-1], result.file))
-            else:
-                logger.info(result.file)
+        if not result.match and not self.args.non_matching:
+            return
 
-    def run(self):
-        if self.args.non_matching and not self.args.details:
-            raise DvcException("--non-matching is only valid with --details")
+        if self.args.details:
+            patterns = result.patterns
+            if not self.args.all:
+                patterns = patterns[-1:]
 
-        if self.args.quiet and self.args.details:
-            raise DvcException("cannot both --details and --quiet")
+            for pattern in patterns:
+                logger.info("{}\t{}".format(pattern, result.file))
+        else:
+            logger.info(result.file)
+
+    def _check_one_file(self, target):
+        result = self.ignore_filter.check_ignore(target)
+        self._show_results(result)
+        if result.match:
+            return 0
+        return 1
 
+    def _interactive_mode(self):
+        ret = 1
+        while True:
+            target = ask("")
+            if target == "":
+                logger.info(
+                    "Empty string is not a valid pathspec. Please use . "
+                    "instead if you meant to match all paths."
+                )
+                break
+            if not self._check_one_file(target):
+                ret = 0
+        return ret
+
+    def _normal_mode(self):
         ret = 1
         for target in self.args.targets:
-            result = self.ignore_filter.check_ignore(target)
-            self._show_results(result)
-            if result.match:
+            if not self._check_one_file(target):
                 ret = 0
         return ret
 
+    def _check_args(self):
+        if not self.args.stdin and not self.args.targets:
+            raise DvcException("`targets` or `--stdin` needed")
+
+        if self.args.stdin and self.args.targets:
+            raise DvcException("cannot have both `targets` and `--stdin`")
+
+        if self.args.non_matching and not self.args.details:
+            raise DvcException(
+                "`--non-matching` is only valid with `--details`"
+            )
+
+        if self.args.all and not self.args.details:
+            raise DvcException("`--all` is only valid with `--details`")
+
+        if self.args.quiet and self.args.details:
+            raise DvcException("cannot use both `--details` and `--quiet`")
+
+    def run(self):
+        self._check_args()
+        if self.args.stdin:
+            return self._interactive_mode()
+        return self._normal_mode()
+
 
 def add_parser(subparsers, parent_parser):
     ADD_HELP = "Debug DVC ignore/exclude files"
@@ -61,9 +106,24 @@ def add_parser(subparsers, parent_parser):
         help="Show the target paths which don’t match any pattern. "
         "Only usable when `--details` is also employed",
     )
+    parser.add_argument(
+        "--stdin",
+        action="store_true",
+        default=False,
+        help="Read pathnames from the standard input, one per line, "
+        "instead of from the command-line.",
+    )
+    parser.add_argument(
+        "-a",
+        "--all",
+        action="store_true",
+        default=False,
+        help="Show all of the patterns match the target paths. "
+        "Only usable when `--details` is also employed",
+    )
     parser.add_argument(
         "targets",
-        nargs="+",
+        nargs="*",
         help="Exact or wildcard paths of files or directories to check "
         "ignore patterns.",
     ).complete = completion.FILE
diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py
index a8d591f4a..34fcab00f 100644
--- a/dvc/command/experiments.py
+++ b/dvc/command/experiments.py
@@ -59,7 +59,9 @@ def _collect_rows(
                 item = {fname: item}
             for name in names:
                 if name in item:
-                    row.append(str(_round(item[name])))
+                    value = item[name]
+                    text = str(_round(value)) if value is not None else "-"
+                    row.append(text)
                 else:
                     row.append("-")
 
@@ -88,9 +90,9 @@ def _show_experiments(all_experiments, console, precision=None):
     metric_names, param_names = _collect_names(all_experiments)
 
     table = Table()
-    table.add_column("Experiment")
+    table.add_column("Experiment", no_wrap=True)
     for name in metric_names:
-        table.add_column(name, justify="right")
+        table.add_column(name, justify="right", no_wrap=True)
     for name in param_names:
         table.add_column(name, justify="left")
 
@@ -125,15 +127,19 @@ class CmdExperimentsShow(CmdBase):
                 all_commits=self.args.all_commits,
             )
 
-            # Note: rich does not currently include a native way to force
-            # infinite width for use with a pager
-            console = Console(
-                file=io.StringIO(), force_terminal=True, width=9999
-            )
+            if self.args.no_pager:
+                console = Console()
+            else:
+                # Note: rich does not currently include a native way to force
+                # infinite width for use with a pager
+                console = Console(
+                    file=io.StringIO(), force_terminal=True, width=9999
+                )
 
             _show_experiments(all_experiments, console)
 
-            pager(console.file.getvalue())
+            if not self.args.no_pager:
+                pager(console.file.getvalue())
         except DvcException:
             logger.exception("failed to show experiments")
             return 1
@@ -146,9 +152,7 @@ class CmdExperimentsCheckout(CmdBase):
         if not self.repo.experiments:
             return 0
 
-        self.repo.experiments.checkout(
-            self.args.experiment, force=self.args.force
-        )
+        self.repo.experiments.checkout(self.args.experiment)
 
         return 0
 
@@ -275,6 +279,12 @@ def add_parser(subparsers, parent_parser):
         default=False,
         help="Show metrics for all commits.",
     )
+    experiments_show_parser.add_argument(
+        "--no-pager",
+        action="store_true",
+        default=False,
+        help="Do not pipe output into a pager.",
+    )
     experiments_show_parser.set_defaults(func=CmdExperimentsShow)
 
     EXPERIMENTS_CHECKOUT_HELP = "Checkout experiments."
@@ -287,14 +297,6 @@ def add_parser(subparsers, parent_parser):
         help=EXPERIMENTS_CHECKOUT_HELP,
         formatter_class=argparse.RawDescriptionHelpFormatter,
     )
-    experiments_checkout_parser.add_argument(
-        "-f",
-        "--force",
-        action="store_true",
-        default=False,
-        help="Overwrite your current workspace with changes from the "
-        "experiment.",
-    )
     experiments_checkout_parser.add_argument(
         "experiment", help="Checkout this experiment.",
     )
diff --git a/dvc/command/repro.py b/dvc/command/repro.py
index ecad1c4a2..6060fa8d4 100644
--- a/dvc/command/repro.py
+++ b/dvc/command/repro.py
@@ -44,6 +44,7 @@ class CmdRepro(CmdBase):
                     queue=self.args.queue,
                     run_all=self.args.run_all,
                     jobs=self.args.jobs,
+                    params=self.args.params,
                 )
 
                 if len(stages) == 0:
@@ -177,6 +178,13 @@ def add_parser(subparsers, parent_parser):
         default=False,
         help=argparse.SUPPRESS,
     )
+    repro_parser.add_argument(
+        "--params",
+        action="append",
+        default=[],
+        help="Declare parameter values for an experiment.",
+        metavar="[<filename>:]<params_list>",
+    )
     repro_parser.add_argument(
         "--queue", action="store_true", default=False, help=argparse.SUPPRESS
     )
diff --git a/dvc/config.py b/dvc/config.py
index 26181e4d6..6aa5908e5 100644
--- a/dvc/config.py
+++ b/dvc/config.py
@@ -324,11 +324,17 @@ class Config(dict):
         if not self["cache"].get("dir") and self.dvc_dir:
             self["cache"]["dir"] = os.path.join(self.dvc_dir, "cache")
 
+    def _get_tree(self, level):
+        # NOTE: this might be a GitTree, which doesn't see things outside of
+        # the repo.
+        return self.tree if level == "repo" else self.wtree
+
     def _load_config(self, level):
         filename = self.files[level]
+        tree = self._get_tree(level)
 
-        if self.tree.exists(filename, use_dvcignore=False):
-            with self.tree.open(filename) as fobj:
+        if tree.exists(filename, use_dvcignore=False):
+            with tree.open(filename) as fobj:
                 conf_obj = configobj.ConfigObj(fobj)
         else:
             conf_obj = configobj.ConfigObj()
@@ -336,13 +342,14 @@ class Config(dict):
 
     def _save_config(self, level, conf_dict):
         filename = self.files[level]
+        tree = self._get_tree(level)
 
         logger.debug(f"Writing '{filename}'.")
 
-        self.tree.makedirs(os.path.dirname(filename))
+        tree.makedirs(os.path.dirname(filename))
 
         config = configobj.ConfigObj(_pack_remotes(conf_dict))
-        with self.tree.open(filename, "wb") as fobj:
+        with tree.open(filename, "wb") as fobj:
             config.write(fobj)
         config.filename = filename
 
diff --git a/dvc/exceptions.py b/dvc/exceptions.py
index 204c378fd..b49a71b00 100644
--- a/dvc/exceptions.py
+++ b/dvc/exceptions.py
@@ -194,6 +194,14 @@ class YAMLFileCorruptedError(DvcException):
         )
 
 
+class TOMLFileCorruptedError(DvcException):
+    def __init__(self, path):
+        path = relpath(path)
+        super().__init__(
+            f"unable to read: '{path}', TOML file structure is corrupted"
+        )
+
+
 class RecursiveAddingWhileUsingFilename(DvcException):
     def __init__(self):
         super().__init__(
diff --git a/dvc/prompt.py b/dvc/prompt.py
index 285f6f62d..cb12a73b9 100644
--- a/dvc/prompt.py
+++ b/dvc/prompt.py
@@ -7,7 +7,7 @@ from getpass import getpass
 logger = logging.getLogger(__name__)
 
 
-def _ask(prompt, limited_to=None):
+def ask(prompt, limited_to=None):
     if not sys.stdout.isatty():
         return None
 
@@ -39,7 +39,7 @@ def confirm(statement):
         bool: whether or not specified statement was confirmed.
     """
     prompt = f"{statement} [y/n]"
-    answer = _ask(prompt, limited_to=["yes", "no", "y", "n"])
+    answer = ask(prompt, limited_to=["yes", "no", "y", "n"])
     return answer and answer.startswith("y")
 
 
diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py
index fe899762d..20963e1fa 100644
--- a/dvc/repo/experiments/__init__.py
+++ b/dvc/repo/experiments/__init__.py
@@ -2,12 +2,16 @@ import logging
 import os
 import re
 import tempfile
+from collections import defaultdict
+from collections.abc import Mapping
 from concurrent.futures import ProcessPoolExecutor, as_completed
+from contextlib import contextmanager
 from typing import Iterable, Optional
 
 from funcy import cached_property
 
 from dvc.exceptions import DvcException
+from dvc.path_info import PathInfo
 from dvc.repo.experiments.executor import ExperimentExecutor, LocalExecutor
 from dvc.scm.git import Git
 from dvc.stage.serialize import to_lockfile
@@ -26,7 +30,15 @@ def hash_exp(stages):
 
 class UnchangedExperimentError(DvcException):
     def __init__(self, rev):
-        super().__init__("Experiment identical to baseline '{rev[:7]}'.")
+        super().__init__(f"Experiment identical to baseline '{rev[:7]}'.")
+        self.rev = rev
+
+
+class BaselineMismatchError(DvcException):
+    def __init__(self, rev):
+        super().__init__(
+            f"Experiment is not derived from current baseline '{rev[:7]}'."
+        )
         self.rev = rev
 
 
@@ -79,6 +91,13 @@ class Experiments:
 
         return Repo(self.exp_dvc_dir)
 
+    @contextmanager
+    def chdir(self):
+        cwd = os.getcwd()
+        os.chdir(self.exp_dvc.root_dir)
+        yield self.exp_dvc.root_dir
+        os.chdir(cwd)
+
     @cached_property
     def args_file(self):
         return os.path.join(self.exp_dvc.tmp_dir, self.PACKED_ARGS_FILE)
@@ -120,24 +139,42 @@ class Experiments:
             self.scm.repo.heads[0].checkout()
         if not Git.is_sha(rev) or not self.scm.has_rev(rev):
             self.scm.pull()
-        logger.debug("Checking out base experiment commit '%s'", rev)
+        logger.debug("Checking out experiment commit '%s'", rev)
         self.scm.checkout(rev)
 
-    def _stash_exp(self, *args, **kwargs):
+    def _stash_exp(self, *args, params: Optional[dict] = None, **kwargs):
         """Stash changes from the current (parent) workspace as an experiment.
+
+        Args:
+            params: Optional dictionary of parameter values to be used.
+                Values take priority over any parameters specified in the
+                user's workspace.
         """
         rev = self.scm.get_rev()
+
+        # patch user's workspace into experiments clone
         tmp = tempfile.NamedTemporaryFile(delete=False).name
         try:
             self.repo.scm.repo.git.diff(patch=True, output=tmp)
             if os.path.getsize(tmp):
                 logger.debug("Patching experiment workspace")
                 self.scm.repo.git.apply(tmp)
-            else:
+            elif not params:
+                # experiment matches original baseline
                 raise UnchangedExperimentError(rev)
         finally:
             remove(tmp)
+
+        # update experiment params from command line
+        if params:
+            self._update_params(params)
+
+        # save additional repro command line arguments
         self._pack_args(*args, **kwargs)
+
+        # save experiment as a stash commit w/message containing baseline rev
+        # (stash commits are merge commits and do not contain a parent commit
+        # SHA)
         msg = f"{self.STASH_MSG_PREFIX}{rev}"
         self.scm.repo.git.stash("push", "-m", msg)
         return self.scm.resolve_rev("stash@{0}")
@@ -150,6 +187,36 @@ class Experiments:
         args_file = os.path.join(self.exp_dvc.tmp_dir, self.PACKED_ARGS_FILE)
         return ExperimentExecutor.unpack_repro_args(args_file, tree=tree)
 
+    def _update_params(self, params: dict):
+        """Update experiment params files with the specified values."""
+        from dvc.utils.toml import dump_toml, parse_toml_for_update
+        from dvc.utils.yaml import dump_yaml, parse_yaml_for_update
+
+        logger.debug("Using experiment params '%s'", params)
+
+        # recursive dict update
+        def _update(dict_, other):
+            for key, value in other.items():
+                if isinstance(value, Mapping):
+                    dict_[key] = _update(dict_.get(key, {}), value)
+                else:
+                    dict_[key] = value
+            return dict_
+
+        loaders = defaultdict(lambda: parse_yaml_for_update)
+        loaders.update({".toml": parse_toml_for_update})
+        dumpers = defaultdict(lambda: dump_yaml)
+        dumpers.update({".toml": dump_toml})
+
+        for params_fname in params:
+            path = PathInfo(self.exp_dvc.root_dir) / params_fname
+            with self.exp_dvc.tree.open(path, "r") as fobj:
+                text = fobj.read()
+            suffix = path.suffix.lower()
+            data = loaders[suffix](text, path)
+            _update(data, params[params_fname])
+            dumpers[suffix](path, data)
+
     def _commit(self, exp_hash, check_exists=True, branch=True):
         """Commit stages as an experiment and return the commit SHA."""
         if not self.scm.is_dirty():
@@ -176,7 +243,7 @@ class Experiments:
             return [stash_rev]
         results = self.reproduce([stash_rev], keep_stash=False)
         for exp_rev in results:
-            self.checkout_exp(exp_rev, force=True)
+            self.checkout_exp(exp_rev)
         return results
 
     def reproduce_queued(self, **kwargs):
@@ -191,7 +258,7 @@ class Experiments:
             )
         return results
 
-    def new(self, *args, workspace=True, **kwargs):
+    def new(self, *args, **kwargs):
         """Create a new experiment.
 
         Experiment will be reproduced and checked out into the user's
@@ -199,15 +266,11 @@ class Experiments:
         """
         rev = self.repo.scm.get_rev()
         self._scm_checkout(rev)
-        if workspace:
-            try:
-                stash_rev = self._stash_exp(*args, **kwargs)
-            except UnchangedExperimentError as exc:
-                logger.info("Reproducing existing experiment '%s'.", rev[:7])
-                raise exc
-        else:
-            # configure params via command line here
-            pass
+        try:
+            stash_rev = self._stash_exp(*args, **kwargs)
+        except UnchangedExperimentError as exc:
+            logger.info("Reproducing existing experiment '%s'.", rev[:7])
+            raise exc
         logger.debug(
             "Stashed experiment '%s' for future execution.", stash_rev[:7]
         )
@@ -338,30 +401,56 @@ class Experiments:
             src = executor.path_info / relpath(fname, tree.tree_root)
             copyfile(src, fname)
 
-    def checkout_exp(self, rev, force=False):
+    def checkout_exp(self, rev):
         """Checkout an experiment to the user's workspace."""
         from git.exc import GitCommandError
         from dvc.repo.checkout import _checkout as dvc_checkout
 
-        if force:
-            self.repo.scm.repo.git.reset(hard=True)
+        self._check_baseline(rev)
         self._scm_checkout(rev)
 
         tmp = tempfile.NamedTemporaryFile(delete=False).name
         self.scm.repo.head.commit.diff("HEAD~1", patch=True, output=tmp)
+
+        dirty = self.repo.scm.is_dirty()
+        if dirty:
+            logger.debug("Stashing workspace changes.")
+            self.repo.scm.repo.git.stash("push")
+
         try:
             if os.path.getsize(tmp):
                 logger.debug("Patching local workspace")
                 self.repo.scm.repo.git.apply(tmp, reverse=True)
-            dvc_checkout(self.repo)
+                need_checkout = True
+            else:
+                need_checkout = False
         except GitCommandError:
-            raise DvcException(
-                "Checkout failed, experiment contains changes which "
-                "conflict with your current workspace. To overwrite "
-                "your workspace, use `dvc experiments checkout --force`."
-            )
+            raise DvcException("failed to apply experiment changes.")
         finally:
             remove(tmp)
+            if dirty:
+                self._unstash_workspace()
+
+        if need_checkout:
+            dvc_checkout(self.repo)
+
+    def _check_baseline(self, exp_rev):
+        baseline_sha = self.repo.scm.get_rev()
+        exp_commit = self.scm.repo.rev_parse(exp_rev)
+        for parent in exp_commit.parents:
+            if parent.hexsha == baseline_sha:
+                return
+        raise BaselineMismatchError(baseline_sha)
+
+    def _unstash_workspace(self):
+        # Essentially we want `git stash pop` with `-X ours` merge strategy
+        # to prefer the applied experiment changes over stashed workspace
+        # changes. git stash doesn't support merge strategy parameters, but we
+        # can do it ourselves with checkout/reset.
+        logger.debug("Unstashing workspace changes.")
+        self.repo.scm.repo.git.checkout("--ours", "stash@{0}", "--", ".")
+        self.repo.scm.repo.git.reset("HEAD")
+        self.repo.scm.repo.git.stash("drop", "stash@{0}")
 
     def checkout(self, *args, **kwargs):
         from dvc.repo.experiments.checkout import checkout
diff --git a/dvc/repo/reproduce.py b/dvc/repo/reproduce.py
index f94f9dd89..1f60117b4 100644
--- a/dvc/repo/reproduce.py
+++ b/dvc/repo/reproduce.py
@@ -60,7 +60,7 @@ def reproduce(
     recursive=False,
     pipeline=False,
     all_pipelines=False,
-    **kwargs
+    **kwargs,
 ):
     from dvc.utils import parse_target
 
@@ -71,6 +71,7 @@ def reproduce(
         )
 
     experiment = kwargs.pop("experiment", False)
+    params = _parse_params(kwargs.pop("params", []))
     queue = kwargs.pop("queue", False)
     run_all = kwargs.pop("run_all", False)
     jobs = kwargs.pop("jobs", 1)
@@ -81,6 +82,7 @@ def reproduce(
                 target=target,
                 recursive=recursive,
                 all_pipelines=all_pipelines,
+                params=params,
                 queue=queue,
                 run_all=run_all,
                 jobs=jobs,
@@ -116,6 +118,31 @@ def reproduce(
     return _reproduce_stages(active_graph, targets, **kwargs)
 
 
+def _parse_params(path_params):
+    from flatten_json import unflatten
+    from yaml import safe_load, YAMLError
+    from dvc.dependency.param import ParamsDependency
+
+    ret = {}
+    for path_param in path_params:
+        path, _, params_str = path_param.rpartition(":")
+        # remove empty strings from params, on condition such as `-p "file1:"`
+        params = {}
+        for param_str in filter(bool, params_str.split(",")):
+            try:
+                # interpret value strings using YAML rules
+                key, value = param_str.split("=")
+                params[key] = safe_load(value)
+            except (ValueError, YAMLError):
+                raise InvalidArgumentError(
+                    f"Invalid param/value pair '{param_str}'"
+                )
+        if not path:
+            path = ParamsDependency.DEFAULT_PARAMS_FILE
+        ret[path] = unflatten(params, ".")
+    return ret
+
+
 def _reproduce_experiments(repo, run_all=False, jobs=1, **kwargs):
     if run_all:
         return repo.experiments.reproduce_queued(jobs=jobs)
diff --git a/dvc/stage/__init__.py b/dvc/stage/__init__.py
index 0048c94fb..61f9c1191 100644
--- a/dvc/stage/__init__.py
+++ b/dvc/stage/__init__.py
@@ -306,7 +306,12 @@ class Stage(params.StageParams):
     @rwlocked(read=["deps"], write=["outs"])
     def reproduce(self, interactive=False, **kwargs):
         if not (kwargs.get("force", False) or self.changed()):
-            logger.info("Stage '%s' didn't change, skipping", self.addressing)
+            if not isinstance(self, PipelineStage) and self.is_data_source:
+                logger.info("'%s' didn't change, skipping", self.addressing)
+            else:
+                logger.info(
+                    "Stage '%s' didn't change, skipping", self.addressing
+                )
             return None
 
         msg = (
diff --git a/dvc/updater.py b/dvc/updater.py
index 4230a2951..b2fb79b6a 100644
--- a/dvc/updater.py
+++ b/dvc/updater.py
@@ -34,7 +34,7 @@ class Updater:  # pragma: no cover
         ctime = os.path.getmtime(self.updater_file)
         outdated = time.time() - ctime >= self.TIMEOUT
         if outdated:
-            logger.debug(f"'{self.updater_file}' is outdated(")
+            logger.debug(f"'{self.updater_file}' is outdated")
         return outdated
 
     def _with_lock(self, func, action):
diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py
index 95e127876..8fece228f 100644
--- a/dvc/utils/__init__.py
+++ b/dvc/utils/__init__.py
@@ -363,19 +363,22 @@ def resolve_output(inp, out):
 
 
 def resolve_paths(repo, out):
+    from urllib.parse import urlparse
     from ..dvcfile import DVC_FILE_SUFFIX
     from ..path_info import PathInfo
     from .fs import contains_symlink_up_to
 
-    abspath = os.path.abspath(out)
+    abspath = PathInfo(os.path.abspath(out))
     dirname = os.path.dirname(abspath)
     base = os.path.basename(os.path.normpath(out))
 
-    # NOTE: `out` might not exist yet, so using `dirname`(aka `wdir`) to check
-    # if it is a local path.
+    scheme = urlparse(out).scheme
+    if os.name == "nt" and scheme == abspath.drive[0].lower():
+        # urlparse interprets windows drive letters as URL scheme
+        scheme = ""
     if (
-        os.path.exists(dirname)  # out might not exist yet, so
-        and PathInfo(abspath).isin_or_eq(repo.root_dir)
+        not scheme
+        and abspath.isin_or_eq(repo.root_dir)
         and not contains_symlink_up_to(abspath, repo.root_dir)
     ):
         wdir = dirname
diff --git a/dvc/utils/toml.py b/dvc/utils/toml.py
new file mode 100644
index 000000000..74aa59da3
--- /dev/null
+++ b/dvc/utils/toml.py
@@ -0,0 +1,21 @@
+import toml
+
+from dvc.exceptions import TOMLFileCorruptedError
+
+
+def parse_toml_for_update(text, path):
+    """Parses text into Python structure.
+
+    NOTE: Python toml package does not currently use ordered dicts, so
+    keys may be re-ordered between load/dump, but this function will at
+    least preserve comments.
+    """
+    try:
+        return toml.loads(text, decoder=toml.TomlPreserveCommentDecoder())
+    except toml.TomlDecodeError as exc:
+        raise TOMLFileCorruptedError(path) from exc
+
+
+def dump_toml(path, data):
+    with open(path, "w", encoding="utf-8") as fobj:
+        toml.dump(data, fobj, encoder=toml.TomlPreserveCommentEncoder())
diff --git a/setup.py b/setup.py
index b90e9b05a..06d6cbab0 100644
--- a/setup.py
+++ b/setup.py
@@ -79,7 +79,7 @@ install_requires = [
     "tabulate>=0.8.7",
     "pygtrie==2.3.2",
     "dpath>=2.0.1,<3",
-    "shtab>=1.1.0,<2",
+    "shtab>=1.3.0,<2",
     "rich>=3.0.5",
 ]
 


Test patch:
diff --git a/tests/func/test_check_ignore.py b/tests/func/test_check_ignore.py
index b53f72f53..eba86bc98 100644
--- a/tests/func/test_check_ignore.py
+++ b/tests/func/test_check_ignore.py
@@ -7,13 +7,13 @@ from dvc.main import main
 
 
 @pytest.mark.parametrize(
-    "file,ret,output", [("ignored", 0, "ignored\n"), ("not_ignored", 1, "")]
+    "file,ret,output", [("ignored", 0, True), ("not_ignored", 1, False)]
 )
 def test_check_ignore(tmp_dir, dvc, file, ret, output, caplog):
     tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "ignored")
 
     assert main(["check-ignore", file]) == ret
-    assert output in caplog.text
+    assert (file in caplog.text) is output
 
 
 @pytest.mark.parametrize(
@@ -39,26 +39,29 @@ def test_check_ignore_details(tmp_dir, dvc, file, ret, output, caplog):
     assert output in caplog.text
 
 
-@pytest.mark.parametrize(
-    "non_matching,output", [(["-n"], "::\tfile\n"), ([], "")]
-)
-def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, output, caplog):
-    tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
-
-    assert main(["check-ignore", "-d"] + non_matching + ["file"]) == 1
-    assert output in caplog.text
-
-
-def test_check_ignore_non_matching_without_details(tmp_dir, dvc):
+@pytest.mark.parametrize("non_matching", [True, False])
+def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, caplog):
     tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
+    if non_matching:
+        assert main(["check-ignore", "-d", "-n", "file"]) == 1
+    else:
+        assert main(["check-ignore", "-d", "file"]) == 1
 
-    assert main(["check-ignore", "-n", "file"]) == 255
-
+    assert ("::\tfile\n" in caplog.text) is non_matching
 
-def test_check_ignore_details_with_quiet(tmp_dir, dvc):
-    tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "other")
 
-    assert main(["check-ignore", "-d", "-q", "file"]) == 255
+@pytest.mark.parametrize(
+    "args",
+    [
+        ["-n", "file"],
+        ["-a", "file"],
+        ["-q", "-d", "file"],
+        ["--stdin", "file"],
+        [],
+    ],
+)
+def test_check_ignore_error_args_cases(tmp_dir, dvc, args):
+    assert main(["check-ignore"] + args) == 255
 
 
 @pytest.mark.parametrize("path,ret", [({"dir": {}}, 0), ({"dir": "files"}, 1)])
@@ -107,3 +110,26 @@ def test_check_sub_dir_ignore_file(tmp_dir, dvc, caplog):
     with sub_dir.chdir():
         assert main(["check-ignore", "-d", "foo"]) == 0
         assert ".dvcignore:2:foo\tfoo" in caplog.text
+
+
+def test_check_ignore_details_all(tmp_dir, dvc, caplog):
+    tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "f*\n!foo")
+
+    assert main(["check-ignore", "-d", "-a", "foo"]) == 0
+    assert "{}:1:f*\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in caplog.text
+    assert "{}:2:!foo\tfoo\n".format(DvcIgnore.DVCIGNORE_FILE) in caplog.text
+
+
+@pytest.mark.parametrize(
+    "file,ret,output", [("ignored", 0, True), ("not_ignored", 1, False)]
+)
+def test_check_ignore_stdin_mode(
+    tmp_dir, dvc, file, ret, output, caplog, mocker
+):
+    tmp_dir.gen(DvcIgnore.DVCIGNORE_FILE, "ignored")
+    mocker.patch("builtins.input", side_effect=[file, ""])
+    stdout_mock = mocker.patch("sys.stdout")
+    stdout_mock.isatty.return_value = True
+
+    assert main(["check-ignore", "--stdin"]) == ret
+    assert (file in caplog.text) is output
diff --git a/tests/func/test_import.py b/tests/func/test_import.py
index 4e38f70d8..5af224775 100644
--- a/tests/func/test_import.py
+++ b/tests/func/test_import.py
@@ -9,6 +9,7 @@ from dvc.cache import Cache
 from dvc.config import NoRemoteError
 from dvc.dvcfile import Dvcfile
 from dvc.exceptions import DownloadError, PathMissingError
+from dvc.stage.exceptions import StagePathNotFoundError
 from dvc.system import System
 from dvc.utils.fs import makedirs, remove
 
@@ -132,6 +133,28 @@ def test_import_file_from_dir(tmp_dir, scm, dvc, erepo_dir):
     assert (tmp_dir / "X.dvc").exists()
 
 
+def test_import_file_from_dir_to_dir(tmp_dir, scm, dvc, erepo_dir):
+    with erepo_dir.chdir():
+        erepo_dir.dvc_gen({"dir": {"foo": "foo"}}, commit="create dir")
+
+    with pytest.raises(StagePathNotFoundError):
+        dvc.imp(
+            os.fspath(erepo_dir),
+            os.path.join("dir", "foo"),
+            out=os.path.join("dir", "foo"),
+        )
+
+    tmp_dir.gen({"dir": {}})
+    dvc.imp(
+        os.fspath(erepo_dir),
+        os.path.join("dir", "foo"),
+        out=os.path.join("dir", "foo"),
+    )
+    assert not (tmp_dir / "foo.dvc").exists()
+    assert (tmp_dir / "dir" / "foo").read_text() == "foo"
+    assert (tmp_dir / "dir" / "foo.dvc").exists()
+
+
 def test_import_non_cached(erepo_dir, tmp_dir, dvc, scm):
     src = "non_cached_output"
     dst = src + "_imported"
diff --git a/tests/func/test_version.py b/tests/func/test_version.py
index 753d53e6e..4c2ad5caa 100644
--- a/tests/func/test_version.py
+++ b/tests/func/test_version.py
@@ -17,7 +17,7 @@ def test_info_in_repo(scm_init, tmp_dir, caplog):
     assert main(["version"]) == 0
 
     assert re.search(r"DVC version: \d+\.\d+\.\d+.*", caplog.text)
-    assert re.search(r"Platform: Python \d\.\d\.\d on .*", caplog.text)
+    assert re.search(r"Platform: Python \d\.\d+\.\d+ on .*", caplog.text)
     assert re.search(r"Supports: .*", caplog.text)
     assert re.search(r"Cache types: .*", caplog.text)
 
@@ -61,7 +61,7 @@ def test_info_outside_of_repo(tmp_dir, caplog):
     assert main(["version"]) == 0
 
     assert re.search(r"DVC version: \d+\.\d+\.\d+.*", caplog.text)
-    assert re.search(r"Platform: Python \d\.\d\.\d on .*", caplog.text)
+    assert re.search(r"Platform: Python \d\.\d+\.\d+ on .*", caplog.text)
     assert re.search(r"Supports: .*", caplog.text)
     assert not re.search(r"Cache types: .*", caplog.text)
     assert "Repo:" not in caplog.text
diff --git a/tests/unit/command/test_repro.py b/tests/unit/command/test_repro.py
index 0b2302ef7..ef86a7549 100644
--- a/tests/unit/command/test_repro.py
+++ b/tests/unit/command/test_repro.py
@@ -15,6 +15,7 @@ default_arguments = {
     "recursive": False,
     "force_downstream": False,
     "experiment": False,
+    "params": [],
     "queue": False,
     "run_all": False,
     "jobs": None,
diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py
index e5d970c27..8ddba3546 100644
--- a/tests/unit/test_config.py
+++ b/tests/unit/test_config.py
@@ -3,6 +3,7 @@ import os
 import pytest
 
 from dvc.config import Config
+from dvc.tree.local import LocalTree
 
 
 @pytest.mark.parametrize(
@@ -16,3 +17,19 @@ from dvc.config import Config
 )
 def test_to_relpath(path, expected):
     assert Config._to_relpath(os.path.join(".", "config"), path) == expected
+
+
+def test_get_tree(tmp_dir, scm):
+    tmp_dir.scm_gen("foo", "foo", commit="add foo")
+
+    tree = scm.get_tree("master")
+    config = Config(tree=tree)
+
+    assert config.tree == tree
+    assert config.wtree != tree
+    assert isinstance(config.wtree, LocalTree)
+
+    assert config._get_tree("repo") == tree
+    assert config._get_tree("local") == config.wtree
+    assert config._get_tree("global") == config.wtree
+    assert config._get_tree("system") == config.wtree