-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add: fix issue when adding already tracked symlinked files #4778
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a93a77
LocalOutput: paths symlinked outside of git can't be gitignored
pmrowla f8bdd2d
utils: contains_symlink_up_to should only check parent dirs on add
pmrowla e419a8e
tests: update test_add symlink cases
pmrowla d617a6e
add: forbid adding symlinked dirs or files inside symlinked dirs
pmrowla 9b77273
update tests
pmrowla c830aea
add troubleshooting link
pmrowla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import filecmp | ||
import logging | ||
import os | ||
import posixpath | ||
import shutil | ||
import time | ||
|
||
|
@@ -422,52 +421,6 @@ def test_should_collect_dir_cache_only_once(mocker, tmp_dir, dvc): | |
assert get_dir_hash_counter.mock.call_count == 1 | ||
|
||
|
||
class SymlinkAddTestBase(TestDvc): | ||
def _get_data_dir(self): | ||
raise NotImplementedError | ||
|
||
def _prepare_external_data(self): | ||
data_dir = self._get_data_dir() | ||
|
||
data_file_name = "data_file" | ||
external_data_path = os.path.join(data_dir, data_file_name) | ||
with open(external_data_path, "w+") as f: | ||
f.write("data") | ||
|
||
link_name = "data_link" | ||
System.symlink(data_dir, link_name) | ||
return data_file_name, link_name | ||
|
||
def _test(self): | ||
data_file_name, link_name = self._prepare_external_data() | ||
|
||
ret = main(["add", os.path.join(link_name, data_file_name)]) | ||
self.assertEqual(0, ret) | ||
|
||
stage_file = data_file_name + DVC_FILE_SUFFIX | ||
self.assertTrue(os.path.exists(stage_file)) | ||
|
||
d = load_yaml(stage_file) | ||
relative_data_path = posixpath.join(link_name, data_file_name) | ||
self.assertEqual(relative_data_path, d["outs"][0]["path"]) | ||
|
||
|
||
class TestShouldAddDataFromExternalSymlink(SymlinkAddTestBase): | ||
def _get_data_dir(self): | ||
return self.mkdtemp() | ||
|
||
def test(self): | ||
self._test() | ||
|
||
|
||
class TestShouldAddDataFromInternalSymlink(SymlinkAddTestBase): | ||
def _get_data_dir(self): | ||
return self.DATA_DIR | ||
|
||
def test(self): | ||
self._test() | ||
|
||
|
||
class TestShouldPlaceStageInDataDirIfRepositoryBelowSymlink(TestDvc): | ||
def test(self): | ||
def is_symlink_true_below_dvc_root(path): | ||
|
@@ -809,13 +762,15 @@ def test_add_pipeline_file(tmp_dir, dvc, run_copy): | |
dvc.add(PIPELINE_FILE) | ||
|
||
|
||
def test_add_symlink(tmp_dir, dvc): | ||
def test_add_symlink_file(tmp_dir, dvc): | ||
tmp_dir.gen({"dir": {"bar": "bar"}}) | ||
|
||
(tmp_dir / "dir" / "foo").symlink_to(os.path.join(".", "bar")) | ||
|
||
dvc.add(os.path.join("dir", "foo")) | ||
|
||
assert not (tmp_dir / "foo.dvc").exists() | ||
assert (tmp_dir / "dir" / "foo.dvc").exists() | ||
assert not (tmp_dir / "dir" / "foo").is_symlink() | ||
assert not (tmp_dir / "dir" / "bar").is_symlink() | ||
assert (tmp_dir / "dir" / "foo").read_text() == "bar" | ||
|
@@ -827,3 +782,41 @@ def test_add_symlink(tmp_dir, dvc): | |
assert not ( | ||
tmp_dir / ".dvc" / "cache" / "37" / "b51d194a7513e45b56f6524f2d51f2" | ||
).is_symlink() | ||
|
||
# Test that subsequent add succeeds | ||
# See https://github.com/iterative/dvc/issues/4654 | ||
dvc.add(os.path.join("dir", "foo")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
||
|
||
@pytest.mark.parametrize("external", [True, False]) | ||
def test_add_symlink_dir(make_tmp_dir, tmp_dir, dvc, external): | ||
if external: | ||
data_dir = make_tmp_dir("data") | ||
data_dir.gen({"foo": "foo"}) | ||
target = os.fspath(data_dir) | ||
else: | ||
tmp_dir.gen({"data": {"foo": "foo"}}) | ||
target = os.path.join(".", "data") | ||
|
||
tmp_dir.gen({"data": {"foo": "foo"}}) | ||
|
||
(tmp_dir / "dir").symlink_to(target) | ||
|
||
with pytest.raises(DvcException): | ||
dvc.add("dir") | ||
|
||
|
||
@pytest.mark.parametrize("external", [True, False]) | ||
def test_add_file_in_symlink_dir(make_tmp_dir, tmp_dir, dvc, external): | ||
if external: | ||
data_dir = make_tmp_dir("data") | ||
data_dir.gen({"dir": {"foo": "foo"}}) | ||
target = os.fspath(data_dir / "dir") | ||
else: | ||
tmp_dir.gen({"data": {"foo": "foo"}}) | ||
target = os.path.join(".", "data") | ||
|
||
(tmp_dir / "dir").symlink_to(target) | ||
|
||
with pytest.raises(DvcException): | ||
dvc.add(os.path.join("dir", "foo")) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These cases are covered by the new pytest based tests