mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
remove: clean gitignore content (#4074)
* remove: clean gitignore content * remove: refactor: using ignore_remove in remove * Update dvc/output/base.py Co-authored-by: Ruslan Kuprieiev <[email protected]> Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
co-authored by
Ruslan Kuprieiev
parent
02b147b6f4
commit
5d97f92bdd
+8
-2
@@ -239,6 +239,12 @@ class BaseOutput:
|
||||
|
||||
self.repo.scm.ignore(self.fspath)
|
||||
|
||||
def ignore_remove(self):
|
||||
if not self.use_scm_ignore:
|
||||
return
|
||||
|
||||
self.repo.scm.ignore_remove(self.fspath)
|
||||
|
||||
def save(self):
|
||||
if not self.exists:
|
||||
raise self.DoesNotExistError(self)
|
||||
@@ -336,8 +342,8 @@ class BaseOutput:
|
||||
if self.scheme != "local":
|
||||
return
|
||||
|
||||
if ignore_remove and self.use_scm_ignore:
|
||||
self.repo.scm.ignore_remove(self.fspath)
|
||||
if ignore_remove:
|
||||
self.ignore_remove()
|
||||
|
||||
def move(self, out):
|
||||
if self.scheme == "local" and self.use_scm_ignore:
|
||||
|
||||
@@ -286,12 +286,17 @@ class Stage(params.StageParams):
|
||||
for out in self.outs:
|
||||
out.unprotect()
|
||||
|
||||
def ignore_remove_outs(self):
|
||||
for out in self.outs:
|
||||
out.ignore_remove()
|
||||
|
||||
@rwlocked(write=["outs"])
|
||||
def remove(self, force=False, remove_outs=True, purge=True):
|
||||
if remove_outs:
|
||||
self.remove_outs(ignore_remove=True, force=force)
|
||||
else:
|
||||
self.unprotect_outs()
|
||||
self.ignore_remove_outs()
|
||||
if purge:
|
||||
self.dvcfile.remove_stage(self)
|
||||
|
||||
|
||||
@@ -7,14 +7,19 @@ from dvc.main import main
|
||||
from dvc.stage.exceptions import StageFileDoesNotExistError
|
||||
from dvc.system import System
|
||||
from dvc.utils.fs import remove
|
||||
from tests.utils import get_gitignore_content
|
||||
|
||||
|
||||
@pytest.mark.parametrize("remove_outs", [True, False])
|
||||
def test_remove(tmp_dir, dvc, run_copy, remove_outs):
|
||||
def test_remove(tmp_dir, scm, dvc, run_copy, remove_outs):
|
||||
(stage1,) = tmp_dir.dvc_gen("foo", "foo")
|
||||
stage2 = run_copy("foo", "bar", single_stage=True)
|
||||
stage3 = run_copy("bar", "foobar", name="copy-bar-foobar")
|
||||
|
||||
assert "/foo" in get_gitignore_content()
|
||||
assert "/bar" in get_gitignore_content()
|
||||
assert "/foobar" in get_gitignore_content()
|
||||
|
||||
for stage in [stage1, stage2, stage3]:
|
||||
dvc.remove(stage.addressing, outs=remove_outs)
|
||||
out_exists = (out.exists for out in stage.outs)
|
||||
@@ -24,6 +29,8 @@ def test_remove(tmp_dir, dvc, run_copy, remove_outs):
|
||||
else:
|
||||
assert all(out_exists)
|
||||
|
||||
assert not any(out in get_gitignore_content() for out in stage.outs)
|
||||
|
||||
|
||||
def test_remove_non_existent_file(tmp_dir, dvc):
|
||||
with pytest.raises(StageFileDoesNotExistError):
|
||||
|
||||
Reference in New Issue
Block a user