From 0ae91300523e25e060e1313d0adb8b2eb45c4cce Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Wed, 13 Oct 2021 12:50:25 -0700 Subject: [PATCH] dvc: add 'repos' list to pre-commit config if it does not exist (#6795) --- dvc/scm/git/__init__.py | 3 +++ tests/func/test_install.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 41eef55a6..f852d0713 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -265,6 +265,9 @@ class Git(Base): ], } + if "repos" not in config: + config["repos"] = [] + if entry not in config["repos"]: config["repos"].append(entry) diff --git a/tests/func/test_install.py b/tests/func/test_install.py index 345183dec..5f0517523 100644 --- a/tests/func/test_install.py +++ b/tests/func/test_install.py @@ -30,6 +30,12 @@ class TestInstall: assert hook_path.is_file() assert command in hook_path.read_text() + def test_install_pre_commit_tool(self, scm): + scm.install(use_pre_commit_tool=True) + + precommit_path = pathlib.Path(".") / ".pre-commit-config.yaml" + assert precommit_path.is_file() + def test_fail_if_hook_exists(self, scm): self._hook("post-checkout").write_text("hook content")