remove: delete .gitignore file if empty (#5148)

* remove: delete .gitignore file if empty

modified behavior to unlink empty .gitignore files.
added corresponding unit & func test cases.
updated failing test cases.

Fixes #4962

* fix failing lint checks

* integrating feedback from the code review
This commit is contained in:
devramx
2020-12-23 23:04:19 +02:00
committed by GitHub
parent afe96974c3
commit 0bb3f40be8
4 changed files with 54 additions and 2 deletions
+27 -1
View File
@@ -29,7 +29,7 @@ def test_remove(tmp_dir, scm, dvc, run_copy, remove_outs):
else:
assert all(out_exists)
assert not any(out in get_gitignore_content() for out in stage.outs)
assert not (tmp_dir / ".gitignore").exists()
def test_remove_non_existent_file(tmp_dir, dvc):
@@ -69,3 +69,29 @@ def test_cmd_remove(tmp_dir, dvc):
assert main(["remove", stage.addressing, "--outs"]) == 0
assert not (tmp_dir / stage.relpath).exists()
assert not (tmp_dir / "foo").exists()
def test_cmd_remove_gitignore_single_stage(tmp_dir, scm, dvc, run_copy):
stage = dvc.run(
name="my", cmd='echo "hello" > out', deps=[], outs=["out"],
)
assert (tmp_dir / ".gitignore").exists()
assert main(["remove", stage.addressing]) == 0
assert not (tmp_dir / stage.relpath).exists()
assert not (stage.dvcfile._lockfile).exists()
assert not (tmp_dir / ".gitignore").exists()
def test_cmd_remove_gitignore_multistage(tmp_dir, scm, dvc, run_copy):
(stage,) = tmp_dir.dvc_gen("foo", "foo")
stage1 = run_copy("foo", "foo1", single_stage=True)
stage2 = run_copy("foo1", "foo2", name="copy-foo1-foo2")
assert (tmp_dir / ".gitignore").exists()
assert main(["remove", stage2.addressing]) == 0
assert main(["remove", stage1.addressing]) == 0
assert main(["remove", stage.addressing]) == 0
assert not (tmp_dir / ".gitignore").exists()