Skip to content

Commit a4ac06c

Browse files
committed
fix: clean up staging ODB after dvc add --out transfer
1 parent e40e378 commit a4ac06c

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

dvc/output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ def transfer(
10591059
callback=cb,
10601060
)
10611061

1062+
staging.clear()
1063+
10621064
self.hash_info = obj.hash_info
10631065
self.files = None
10641066
return obj

tests/func/test_add.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,18 @@ def test_add_with_out(tmp_dir, scm, dvc):
893893
assert "/out_foo" in gitignore_content
894894

895895

896+
def test_add_with_out_cleans_up_staging(tmp_dir, dvc, mocker):
897+
"""Test that 'dvc add --out' cleans up the staging ODB after transfer."""
898+
from dvc_objects.db import ObjectDB
899+
900+
tmp_dir.gen({"foo": "foo"})
901+
clear_spy = mocker.spy(ObjectDB, "clear")
902+
dvc.add("foo", out="out_foo")
903+
904+
assert (tmp_dir / "out_foo").read_text() == "foo"
905+
assert clear_spy.call_count >= 1
906+
907+
896908
def test_add_to_cache_different_name(tmp_dir, dvc, local_cloud):
897909
local_cloud.gen({"data": {"foo": "foo", "bar": "bar"}})
898910

0 commit comments

Comments
 (0)