From c71a4082e6db2dfb753c77d878454f475ddfdf53 Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Mon, 10 Apr 2023 18:07:07 +0900 Subject: [PATCH] testing: expose force=... in scm_add --- dvc/testing/tmp_dir.py | 15 +++++++++------ tests/func/experiments/test_experiments.py | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dvc/testing/tmp_dir.py b/dvc/testing/tmp_dir.py index 38ef70d0c..126145d0d 100644 --- a/dvc/testing/tmp_dir.py +++ b/dvc/testing/tmp_dir.py @@ -149,11 +149,11 @@ class TmpDir(pathlib.Path): paths = self.gen(struct, text) return self.dvc_add(paths, commit=commit) - def scm_gen(self, struct, text="", commit=None): + def scm_gen(self, struct, text="", commit=None, force=False): paths = self.gen(struct, text) - return self.scm_add(paths, commit=commit) + return self.scm_add(paths, commit=commit, force=force) - def commit(self, output_paths, msg): + def commit(self, output_paths, msg, force=False): def to_gitignore(stage_path): from dvc.scm import Git @@ -162,7 +162,7 @@ class TmpDir(pathlib.Path): gitignores = [ to_gitignore(s) for s in output_paths if os.path.exists(to_gitignore(s)) ] - return self.scm_add(output_paths + gitignores, commit=msg) + return self.scm_add(output_paths + gitignores, commit=msg, force=force) def dvc_add(self, filenames, commit=None): self._require("dvc") @@ -173,10 +173,13 @@ class TmpDir(pathlib.Path): self.commit([s.path for s in stages], msg=commit) return stages - def scm_add(self, filenames, commit=None): + def scm_add(self, filenames, commit=None, force=False): + from dvc.scm import Git + self._require("scm") filenames = _coerce_filenames(filenames) - self.scm.add(filenames) + assert isinstance(self.scm, Git) + self.scm.add(filenames, force=force) if commit: self.scm.commit(commit) diff --git a/tests/func/experiments/test_experiments.py b/tests/func/experiments/test_experiments.py index 2031772c4..b4c063c3e 100644 --- a/tests/func/experiments/test_experiments.py +++ b/tests/func/experiments/test_experiments.py @@ -330,6 +330,7 @@ def test_packed_args_exists(tmp_dir, scm, dvc, exp_stage, caplog): tmp_dir / ".dvc" / "tmp" / BaseExecutor.PACKED_ARGS_FILE, "", commit="commit args file", + force=True, ) with caplog.at_level(logging.WARNING):