Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ def ignore(self):

self.repo.scm.ignore(self.fspath)

def ignore_remove(self):
Comment thread
efiop marked this conversation as resolved.
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)
Expand Down Expand Up @@ -336,8 +342,8 @@ def remove(self, ignore_remove=False):
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:
Expand Down
5 changes: 5 additions & 0 deletions dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,17 @@ def unprotect_outs(self):
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)

Expand Down
9 changes: 8 additions & 1 deletion tests/func/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
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)
Expand All @@ -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):
Expand Down