Repository: iterative/dvc

Issue:
install: support pre-commit util
So far looks like we only need `pre-commit` to add support for `post-checkout` hook. Authors are ok with implementing it https://github.com/pre-commit/pre-commit/issues/1120 and the implementation is pretty straightforward. Might consider contributing that to provide the best experience for the users (as our dvc hooks get into conflict with out pre-commit hooks already).

Discussion:
efiop: @andrewhare Looks really good! Thank you so much for the PR!

For the record: We've discussed during the meeting, that it might be worth creating those hook files somewhere (e.g. in .dvc/ or .dvc/tmp/) and triggering those from pre-commit config, instead of writing shell wrapper directly into them.
andrewhare: @efiop Thanks for the feedback! 

I like the idea of writing the hook files to disk (possibly reusing/refactoring `_install_hook` to write to the correct directory) and calling them there.
efiop: @pared Did you install the latest pre-commit version? As mentioned in the header, it requires 2.2.0
efiop: For the record: taking over this PR.
efiop: Currently you need to `dvc install --use-pre-commit-tool` on each clone, as `pre-commit` won't have .dvc/tmp/hook/* scripts to run without it. Looks like it would be better to run hooks directly through dvc. Looking into it.

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d27f67a26..041a99f7f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,17 +1,35 @@
 repos:
--   repo: https://github.com/ambv/black
-    rev: 19.10b0
-    hooks:
-    - id: black
-      language_version: python3
--   repo: https://gitlab.com/pycqa/flake8
-    rev: master
-    hooks:
-    - id: flake8
-      language_version: python3
--   repo: https://github.com/lovesegfault/beautysh
-    rev: master
-    hooks:
-    - id: beautysh
-      language_version: python3
-      args: [-i, '2']  # 2-space indentaion
+- hooks:
+  - id: black
+    language_version: python3
+  repo: https://github.com/ambv/black
+  rev: 19.10b0
+- hooks:
+  - id: flake8
+    language_version: python3
+  repo: https://gitlab.com/pycqa/flake8
+  rev: master
+- hooks:
+  - args:
+    - -i
+    - '2'
+    id: beautysh
+    language_version: python3
+  repo: https://github.com/lovesegfault/beautysh
+  rev: master
+- hooks:
+  - id: dvc-pre-commit
+    language_version: python3
+    stages:
+    - commit
+  - id: dvc-pre-push
+    language_version: python3
+    stages:
+    - push
+  - always_run: true
+    id: dvc-post-checkout
+    language_version: python3
+    stages:
+    - post-checkout
+  repo: https://github.com/andrewhare/dvc
+  rev: WIP-pre-commit-tool
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
new file mode 100644
index 000000000..788f02343
--- /dev/null
+++ b/.pre-commit-hooks.yaml
@@ -0,0 +1,32 @@
+- args:
+  - git-hook
+  - pre-commit
+  entry: dvc
+  id: dvc-pre-commit
+  language: python
+  language_version: python3
+  name: DVC pre-commit
+  stages:
+  - commit
+- args:
+  - git-hook
+  - pre-push
+  entry: dvc
+  id: dvc-pre-push
+  language: python
+  language_version: python3
+  name: DVC pre-push
+  stages:
+  - push
+- always_run: true
+  args:
+  - git-hook
+  - post-checkout
+  entry: dvc
+  id: dvc-post-checkout
+  language: python
+  language_version: python3
+  minimum_pre_commit_version: 2.2.0
+  name: DVC post-checkout
+  stages:
+  - post-checkout
diff --git a/dvc/cli.py b/dvc/cli.py
index 5ab81ad21..17d43a974 100644
--- a/dvc/cli.py
+++ b/dvc/cli.py
@@ -34,6 +34,7 @@ from .command import (
     unprotect,
     update,
     version,
+    git_hook,
 )
 from .command.base import fix_subparsers
 from .exceptions import DvcParserError
@@ -72,6 +73,7 @@ COMMANDS = [
     diff,
     version,
     update,
+    git_hook,
 ]
 
 
diff --git a/dvc/command/git_hook.py b/dvc/command/git_hook.py
new file mode 100644
index 000000000..6c64c582d
--- /dev/null
+++ b/dvc/command/git_hook.py
@@ -0,0 +1,112 @@
+import logging
+import os
+
+from dvc.command.base import CmdBaseNoRepo, fix_subparsers
+from dvc.exceptions import NotDvcRepoError
+
+logger = logging.getLogger(__name__)
+
+
+class CmdHookBase(CmdBaseNoRepo):
+    def run(self):
+        from dvc.repo import Repo
+
+        try:
+            repo = Repo()
+            repo.close()
+        except NotDvcRepoError:
+            return 0
+
+        return self._run()
+
+
+class CmdPreCommit(CmdHookBase):
+    def _run(self):
+        from dvc.main import main
+
+        return main(["status"])
+
+
+class CmdPostCheckout(CmdHookBase):
+    def run(self):
+        # when we are running from pre-commit tool, it doesn't provide CLI
+        # flags, but instead provides respective env vars that we could use.
+        flag = os.environ.get("PRE_COMMIT_CHECKOUT_TYPE")
+        if flag is None and len(self.args.args) >= 3:
+            # see https://git-scm.com/docs/githooks#_post_checkout
+            flag = self.args.args[2]
+
+        # checking out some reference and not specific file.
+        if flag != "1":
+            return 0
+
+        # make sure we are not in the middle of a rebase/merge, so we
+        # don't accidentally break it with an unsuccessful checkout.
+        # Note that git hooks are always running in repo root.
+        if os.path.isdir(os.path.join(".git", "rebase-merge")):
+            return 0
+
+        from dvc.main import main
+
+        return main(["checkout"])
+
+
+class CmdPrePush(CmdHookBase):
+    def run(self):
+        from dvc.main import main
+
+        return main(["push"])
+
+
+def add_parser(subparsers, parent_parser):
+    GIT_HOOK_HELP = "Run GIT hook."
+
+    git_hook_parser = subparsers.add_parser(
+        "git-hook",
+        parents=[parent_parser],
+        description=GIT_HOOK_HELP,
+        add_help=False,
+    )
+
+    git_hook_subparsers = git_hook_parser.add_subparsers(
+        dest="cmd",
+        help="Use `dvc daemon CMD --help` for command-specific help.",
+    )
+
+    fix_subparsers(git_hook_subparsers)
+
+    PRE_COMMIT_HELP = "Run pre-commit GIT hook."
+    pre_commit_parser = git_hook_subparsers.add_parser(
+        "pre-commit",
+        parents=[parent_parser],
+        description=PRE_COMMIT_HELP,
+        help=PRE_COMMIT_HELP,
+    )
+    pre_commit_parser.add_argument(
+        "args", nargs="*", help="Arguments passed by GIT or pre-commit tool.",
+    )
+    pre_commit_parser.set_defaults(func=CmdPreCommit)
+
+    POST_CHECKOUT_HELP = "Run post-checkout GIT hook."
+    post_checkout_parser = git_hook_subparsers.add_parser(
+        "post-checkout",
+        parents=[parent_parser],
+        description=POST_CHECKOUT_HELP,
+        help=POST_CHECKOUT_HELP,
+    )
+    post_checkout_parser.add_argument(
+        "args", nargs="*", help="Arguments passed by GIT or pre-commit tool.",
+    )
+    post_checkout_parser.set_defaults(func=CmdPostCheckout)
+
+    PRE_PUSH_HELP = "Run pre-push GIT hook."
+    pre_push_parser = git_hook_subparsers.add_parser(
+        "pre-push",
+        parents=[parent_parser],
+        description=PRE_PUSH_HELP,
+        help=PRE_PUSH_HELP,
+    )
+    pre_push_parser.add_argument(
+        "args", nargs="*", help="Arguments passed by GIT or pre-commit tool.",
+    )
+    pre_push_parser.set_defaults(func=CmdPrePush)
diff --git a/dvc/command/install.py b/dvc/command/install.py
index 1dea3fcb0..39c33802e 100644
--- a/dvc/command/install.py
+++ b/dvc/command/install.py
@@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
 class CmdInstall(CmdBase):
     def run(self):
         try:
-            self.repo.install()
+            self.repo.install(self.args.use_pre_commit_tool)
         except Exception:
             logger.exception("failed to install DVC Git hooks")
             return 1
@@ -27,4 +27,11 @@ def add_parser(subparsers, parent_parser):
         help=INSTALL_HELP,
         formatter_class=argparse.RawDescriptionHelpFormatter,
     )
+    install_parser.add_argument(
+        "--use-pre-commit-tool",
+        action="store_true",
+        default=False,
+        help="Install DVC hooks using pre-commit "
+        "(https://pre-commit.com) if it is installed.",
+    )
     install_parser.set_defaults(func=CmdInstall)
diff --git a/dvc/command/ls/__init__.py b/dvc/command/ls/__init__.py
index c00644453..fba2e287f 100644
--- a/dvc/command/ls/__init__.py
+++ b/dvc/command/ls/__init__.py
@@ -30,7 +30,7 @@ class CmdList(CmdBaseNoRepo):
         try:
             entries = Repo.ls(
                 self.args.url,
-                self.args.target,
+                self.args.path,
                 rev=self.args.rev,
                 recursive=self.args.recursive,
                 outs_only=self.args.outs_only,
@@ -45,7 +45,10 @@ class CmdList(CmdBaseNoRepo):
 
 
 def add_parser(subparsers, parent_parser):
-    LIST_HELP = "List files and DVC outputs in the repo."
+    LIST_HELP = (
+        "List repository contents, including files"
+        " and directories tracked by DVC and by Git."
+    )
     list_parser = subparsers.add_parser(
         "list",
         parents=[parent_parser],
@@ -53,16 +56,7 @@ def add_parser(subparsers, parent_parser):
         help=LIST_HELP,
         formatter_class=argparse.RawTextHelpFormatter,
     )
-    list_parser.add_argument(
-        "url",
-        help="Supported urls:\n"
-        "/path/to/file\n"
-        "/path/to/directory\n"
-        "C:\\\\path\\to\\file\n"
-        "C:\\\\path\\to\\directory\n"
-        "https://github.com/path/to/repo\n"
-        "git@github.com:path/to/repo.git\n",
-    )
+    list_parser.add_argument("url", help="Location of DVC repository to list")
     list_parser.add_argument(
         "-R",
         "--recursive",
@@ -76,7 +70,7 @@ def add_parser(subparsers, parent_parser):
         "--rev", nargs="?", help="Git revision (e.g. branch, tag, SHA)"
     )
     list_parser.add_argument(
-        "target",
+        "path",
         nargs="?",
         help="Path to directory within the repository to list outputs for",
     )
diff --git a/dvc/exceptions.py b/dvc/exceptions.py
index 2a1b1cc5d..72d215447 100644
--- a/dvc/exceptions.py
+++ b/dvc/exceptions.py
@@ -295,11 +295,11 @@ class HTTPError(DvcException):
 class PathMissingError(DvcException):
     default_msg = (
         "The path '{}' does not exist in the target repository '{}'"
-        " neither as an output nor a git-handled file."
+        " neither as a DVC output nor as a Git-tracked file."
     )
     default_msg_output_only = (
         "The path '{}' does not exist in the target repository '{}'"
-        " as an output."
+        " as an DVC output."
     )
 
     def __init__(self, path, repo, output_only=False):
@@ -325,3 +325,7 @@ class RemoteCacheRequiredError(DvcException):
                 format_link("https://man.dvc.org/config#cache"),
             )
         )
+
+
+class IsADirectoryError(DvcException):
+    """Raised when a file operation is requested on a directory."""
diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py
index 9fb3f5ee1..e7db95646 100644
--- a/dvc/repo/__init__.py
+++ b/dvc/repo/__init__.py
@@ -10,6 +10,7 @@ from funcy import cached_property, cat, first
 from dvc.config import Config
 from dvc.exceptions import (
     FileMissingError,
+    IsADirectoryError,
     NotDvcRepoError,
     OutputNotFoundError,
 )
@@ -476,7 +477,7 @@ class Repo(object):
 
     def _open_cached(self, out, remote=None, mode="r", encoding=None):
         if out.isdir():
-            raise ValueError("Can't open a dir")
+            raise IsADirectoryError("Can't open a dir")
 
         cache_file = self.cache.local.checksum_to_path_info(out.checksum)
         cache_file = fspath_py35(cache_file)
diff --git a/dvc/repo/install.py b/dvc/repo/install.py
index cff23a15f..38612d608 100644
--- a/dvc/repo/install.py
+++ b/dvc/repo/install.py
@@ -1,2 +1,2 @@
-def install(self):
-    self.scm.install()
+def install(self, use_pre_commit_tool):
+    self.scm.install(use_pre_commit_tool)
diff --git a/dvc/repo/ls.py b/dvc/repo/ls.py
index 78f1cb0d1..8f40e8cf8 100644
--- a/dvc/repo/ls.py
+++ b/dvc/repo/ls.py
@@ -6,13 +6,13 @@ from dvc.exceptions import PathMissingError, OutputNotFoundError
 
 @staticmethod
 def ls(
-    url, target=None, rev=None, recursive=None, outs_only=False,
+    url, path=None, rev=None, recursive=None, outs_only=False,
 ):
     """Methods for getting files and outputs for the repo.
 
     Args:
         url (str): the repo url
-        target (str, optional): relative path into the repo
+        path (str, optional): relative path into the repo
         rev (str, optional): SHA commit, branch or tag name
         recursive (bool, optional): recursively walk the repo
         outs_only (bool, optional): show only DVC-artifacts
@@ -34,25 +34,25 @@ def ls(
     from dvc.utils import relpath
 
     with external_repo(url, rev) as repo:
-        target_path_info = _get_target_path_info(repo, target)
+        path_info = _get_path_info(repo, path)
         fs_nodes = []
         if isinstance(repo, Repo):
-            fs_nodes.extend(_ls_outs_repo(repo, target_path_info, recursive))
+            fs_nodes.extend(_ls_outs_repo(repo, path_info, recursive))
 
         if not outs_only:
-            fs_nodes.extend(_ls_files_repo(target_path_info, recursive))
+            fs_nodes.extend(_ls_files_repo(path_info, recursive))
 
-        if target and not fs_nodes:
-            raise PathMissingError(target, repo, output_only=outs_only)
+        if path and not fs_nodes:
+            raise PathMissingError(path, repo, output_only=outs_only)
 
         fs_nodes = {n["path_info"]: n for n in fs_nodes}.values()
 
         def get_entry(fs_node):
-            path_info = fs_node["path_info"]
+            node_path_info = fs_node["path_info"]
             path = (
-                path_info.name
-                if path_info == target_path_info
-                else relpath(path_info, target_path_info)
+                node_path_info.name
+                if node_path_info == path_info
+                else relpath(node_path_info, path_info)
             )
             return {
                 "path": path,
@@ -123,12 +123,12 @@ def _ls_outs_repo(repo, path_info, recursive=None):
     ]
 
 
-def _get_target_path_info(repo, target=None):
+def _get_path_info(repo, path=None):
     from dvc.path_info import PathInfo
 
-    if not target:
+    if not path:
         return PathInfo(repo.root_dir)
-    return PathInfo(repo.root_dir, target)
+    return PathInfo(repo.root_dir, path)
 
 
 def _get_fs_node(path_info, out=None):
diff --git a/dvc/repo/reproduce.py b/dvc/repo/reproduce.py
index e8c7d417c..f0c3b96ec 100644
--- a/dvc/repo/reproduce.py
+++ b/dvc/repo/reproduce.py
@@ -1,6 +1,6 @@
 import logging
 
-from dvc.exceptions import ReproductionError
+from dvc.exceptions import ReproductionError, InvalidArgumentError
 from dvc.repo.scm_context import scm_context
 from . import locked
 from .graph import get_pipeline, get_pipelines
@@ -61,7 +61,9 @@ def reproduce(
     from dvc.stage import Stage
 
     if not target and not all_pipelines:
-        raise ValueError()
+        raise InvalidArgumentError(
+            "Neither target nor all_pipelines are specified."
+        )
 
     interactive = kwargs.get("interactive", False)
     if not interactive:
diff --git a/dvc/scm/base.py b/dvc/scm/base.py
index 779b1009f..0806b25e1 100644
--- a/dvc/scm/base.py
+++ b/dvc/scm/base.py
@@ -114,8 +114,13 @@ class Base(object):
         """Returns a list of commits in the repo."""
         return []
 
-    def install(self):
-        """Adds dvc commands to SCM hooks for the repo."""
+    def install(self, use_pre_commit_tool=False):
+        """
+        Adds dvc commands to SCM hooks for the repo.
+
+        If use_pre_commit_tool is set and pre-commit is
+        installed it will be used to install the hooks.
+        """
 
     def cleanup_ignores(self):
         """
diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py
index efcf5b5aa..80553b3a2 100644
--- a/dvc/scm/git/__init__.py
+++ b/dvc/scm/git/__init__.py
@@ -2,6 +2,7 @@
 
 import logging
 import os
+import yaml
 
 from funcy import cached_property
 from pathspec.patterns import GitWildMatchPattern
@@ -253,43 +254,57 @@ class Git(Base):
     def list_all_commits(self):
         return [c.hexsha for c in self.repo.iter_commits("--all")]
 
-    def _install_hook(self, name, preconditions, cmd):
-        # only run in dvc repo
-        in_dvc_repo = '[ -n "$(git ls-files --full-name .dvc)" ]'
-
-        command = "if {}; then exec dvc {}; fi".format(
-            " && ".join([in_dvc_repo] + preconditions), cmd
-        )
-
+    def _install_hook(self, name):
         hook = self._hook_path(name)
-
-        if os.path.isfile(hook):
-            with open(hook, "r+") as fobj:
-                if command not in fobj.read():
-                    fobj.write("{command}\n".format(command=command))
-        else:
-            with open(hook, "w+") as fobj:
-                fobj.write("#!/bin/sh\n" "{command}\n".format(command=command))
+        with open(hook, "w+") as fobj:
+            fobj.write("#!/bin/sh\nexec dvc git-hook {} $@\n".format(name))
 
         os.chmod(hook, 0o777)
 
-    def install(self):
-        self._verify_dvc_hooks()
-
-        self._install_hook(
-            "post-checkout",
-            [
-                # checking out some reference and not specific file.
-                '[ "$3" = "1" ]',
-                # make sure we are not in the middle of a rebase/merge, so we
-                # don't accidentally break it with an unsuccessful checkout.
-                # Note that git hooks are always running in repo root.
-                "[ ! -d .git/rebase-merge ]",
+    def install(self, use_pre_commit_tool=False):
+        if not use_pre_commit_tool:
+            self._verify_dvc_hooks()
+            self._install_hook("post-checkout")
+            self._install_hook("pre-commit")
+            self._install_hook("pre-push")
+            return
+
+        config_path = os.path.join(self.root_dir, ".pre-commit-config.yaml")
+
+        config = {}
+        if os.path.exists(config_path):
+            with open(config_path, "r") as fobj:
+                config = yaml.safe_load(fobj)
+
+        entry = {
+            "repo": "https://github.com/andrewhare/dvc",  # FIXME
+            "rev": "WIP-pre-commit-tool",
+            "hooks": [
+                {
+                    "id": "dvc-pre-commit",
+                    "language_version": "python3",
+                    "stages": ["commit"],
+                },
+                {
+                    "id": "dvc-pre-push",
+                    "language_version": "python3",
+                    "stages": ["push"],
+                },
+                {
+                    "id": "dvc-post-checkout",
+                    "language_version": "python3",
+                    "stages": ["post-checkout"],
+                    "always_run": True,
+                },
             ],
-            "checkout",
-        )
-        self._install_hook("pre-commit", [], "status")
-        self._install_hook("pre-push", [], "push")
+        }
+
+        if entry in config["repos"]:
+            return
+
+        config["repos"].append(entry)
+        with open(config_path, "w+") as fobj:
+            yaml.dump(config, fobj)
 
     def cleanup_ignores(self):
         for path in self.ignored_paths:
diff --git a/scripts/completion/dvc.zsh b/scripts/completion/dvc.zsh
index 49c9ecf22..bed55a42d 100644
--- a/scripts/completion/dvc.zsh
+++ b/scripts/completion/dvc.zsh
@@ -27,7 +27,7 @@ _dvc_commands() {
     "import:Download data from DVC repository and take it under DVC control."
     "init:Initialize DVC in the current directory."
     "install:Install DVC git hooks into the repository."
-    "list:List files."
+    "list:List repository contents, including files and directories tracked by DVC and by Git."
     "lock:Lock DVC-file."
     "metrics:Commands to add, manage, collect and display metrics."
     "move:Rename or move a DVC controlled data file or a directory."
@@ -168,7 +168,7 @@ _dvc_list=(
   {-R,--recursive}"[Recursively add each file under the directory.]"
   "--outs-only[Only outputs DVC-outs.]"
   "1:URL:"
-  "2:Target:"
+  "2:Path:"
 )
 
 _dvc_metrics=(
diff --git a/setup.py b/setup.py
index 5930136a7..16a301aa5 100644
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,10 @@ from setuptools.command.build_py import build_py as _build_py
 # Prevents pkg_resources import in entry point script,
 # see https://github.com/ninjaaron/fast-entry_points.
 # This saves about 200 ms on startup time for non-wheel installs.
-import fastentrypoints  # noqa: F401
+try:
+    import fastentrypoints  # noqa: F401
+except ImportError:
+    pass  # not able to import when installing through pre-commit
 
 
 # Read package meta-data from version.py


Test patch:
diff --git a/tests/func/test_install.py b/tests/func/test_install.py
index aedd3ddda..f2ed61ab9 100644
--- a/tests/func/test_install.py
+++ b/tests/func/test_install.py
@@ -19,9 +19,9 @@ class TestInstall(object):
         scm.install()
 
         hooks_with_commands = [
-            ("post-checkout", "exec dvc checkout"),
-            ("pre-commit", "exec dvc status"),
-            ("pre-push", "exec dvc push"),
+            ("post-checkout", "exec dvc git-hook post-checkout"),
+            ("pre-commit", "exec dvc git-hook pre-commit"),
+            ("pre-push", "exec dvc git-hook pre-push"),
         ]
 
         for fname, command in hooks_with_commands:
diff --git a/tests/func/test_ls.py b/tests/func/test_ls.py
index 3246212e5..73acf7021 100644
--- a/tests/func/test_ls.py
+++ b/tests/func/test_ls.py
@@ -138,11 +138,11 @@ def test_ls_repo_outs_only_recursive(tmp_dir, dvc, scm):
     )
 
 
-def test_ls_repo_with_target_dir(tmp_dir, dvc, scm):
+def test_ls_repo_with_path_dir(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
-    files = Repo.ls(fspath(tmp_dir), target="model")
+    files = Repo.ls(fspath(tmp_dir), path="model")
     match_files(
         files,
         (
@@ -155,21 +155,21 @@ def test_ls_repo_with_target_dir(tmp_dir, dvc, scm):
     )
 
 
-def test_ls_repo_with_target_dir_outs_only_empty(tmp_dir, dvc, scm):
+def test_ls_repo_with_path_dir_outs_only_empty(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
     tmp_dir.scm_gen({"folder/.keep": "content"}, commit="add .keep")
 
     with pytest.raises(PathMissingError):
-        Repo.ls(fspath(tmp_dir), target="folder", outs_only=True)
+        Repo.ls(fspath(tmp_dir), path="folder", outs_only=True)
 
 
-def test_ls_repo_with_target_subdir(tmp_dir, dvc, scm):
+def test_ls_repo_with_path_subdir(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
-    target = os.path.join("data", "subcontent")
-    files = Repo.ls(fspath(tmp_dir), target)
+    path = os.path.join("data", "subcontent")
+    files = Repo.ls(fspath(tmp_dir), path)
     match_files(
         files,
         (
@@ -181,61 +181,61 @@ def test_ls_repo_with_target_subdir(tmp_dir, dvc, scm):
     )
 
 
-def test_ls_repo_with_target_subdir_outs_only(tmp_dir, dvc, scm):
+def test_ls_repo_with_path_subdir_outs_only(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
-    target = os.path.join("data", "subcontent")
-    files = Repo.ls(fspath(tmp_dir), target, outs_only=True)
+    path = os.path.join("data", "subcontent")
+    files = Repo.ls(fspath(tmp_dir), path, outs_only=True)
     match_files(files, ((("data.xml",), True), (("statistics",), False),))
 
 
-def test_ls_repo_with_target_subdir_outs_only_recursive(tmp_dir, dvc, scm):
+def test_ls_repo_with_path_subdir_outs_only_recursive(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
-    target = os.path.join("data", "subcontent")
-    files = Repo.ls(fspath(tmp_dir), target, outs_only=True, recursive=True)
+    path = os.path.join("data", "subcontent")
+    files = Repo.ls(fspath(tmp_dir), path, outs_only=True, recursive=True)
     match_files(
         files, ((("data.xml",), True), (("statistics", "data.csv"), True),)
     )
 
 
-def test_ls_repo_with_target_file_out(tmp_dir, dvc, scm):
+def test_ls_repo_with_path_file_out(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
-    target = os.path.join("data", "subcontent", "data.xml")
-    files = Repo.ls(fspath(tmp_dir), target)
+    path = os.path.join("data", "subcontent", "data.xml")
+    files = Repo.ls(fspath(tmp_dir), path)
     match_files(files, ((("data.xml",), True),))
 
 
-def test_ls_repo_with_file_target_fs(tmp_dir, dvc, scm):
+def test_ls_repo_with_file_path_fs(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
-    target = "README.md"
-    files = Repo.ls(fspath(tmp_dir), target, recursive=True)
+    path = "README.md"
+    files = Repo.ls(fspath(tmp_dir), path, recursive=True)
     match_files(files, ((("README.md",), False),))
 
 
-def test_ls_repo_with_missed_target(tmp_dir, dvc, scm):
+def test_ls_repo_with_missed_path(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
     with pytest.raises(PathMissingError) as exc_info:
-        Repo.ls(fspath(tmp_dir), target="missed_target")
+        Repo.ls(fspath(tmp_dir), path="missed_path")
     assert not exc_info.value.output_only
 
 
-def test_ls_repo_with_missed_target_outs_only(tmp_dir, dvc, scm):
+def test_ls_repo_with_missed_path_outs_only(tmp_dir, dvc, scm):
     tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
     tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
     with pytest.raises(PathMissingError) as exc_info:
         Repo.ls(
             fspath(tmp_dir),
-            target="missed_target",
+            path="missed_path",
             recursive=True,
             outs_only=True,
         )
@@ -276,19 +276,19 @@ def test_ls_repo_with_removed_dvc_dir_recursive(tmp_dir, dvc, scm):
     )
 
 
-def test_ls_repo_with_removed_dvc_dir_with_target_dir(tmp_dir, dvc, scm):
+def test_ls_repo_with_removed_dvc_dir_with_path_dir(tmp_dir, dvc, scm):
     create_dvc_pipeline(tmp_dir, dvc)
 
-    target = "out"
-    files = Repo.ls(fspath(tmp_dir), target)
+    path = "out"
+    files = Repo.ls(fspath(tmp_dir), path)
     match_files(files, ((("file",), True),))
 
 
-def test_ls_repo_with_removed_dvc_dir_with_target_file(tmp_dir, dvc, scm):
+def test_ls_repo_with_removed_dvc_dir_with_path_file(tmp_dir, dvc, scm):
     create_dvc_pipeline(tmp_dir, dvc)
 
-    target = os.path.join("out", "file")
-    files = Repo.ls(fspath(tmp_dir), target)
+    path = os.path.join("out", "file")
+    files = Repo.ls(fspath(tmp_dir), path)
     match_files(files, ((("file",), True),))
 
 
@@ -358,14 +358,14 @@ def test_ls_remote_git_only_repo_recursive(git_dir):
     )
 
 
-def test_ls_remote_repo_with_target_dir(erepo_dir):
+def test_ls_remote_repo_with_path_dir(erepo_dir):
     with erepo_dir.chdir():
         erepo_dir.scm_gen(FS_STRUCTURE, commit="init")
         erepo_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
 
     url = "file://{}".format(erepo_dir)
-    target = "model"
-    files = Repo.ls(url, target)
+    path = "model"
+    files = Repo.ls(url, path)
     match_files(
         files,
         (