Skip to content
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: ignore duplicated targets? #6286

Merged
merged 1 commit into from
Jul 12, 2021
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
9 changes: 8 additions & 1 deletion dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ def check_recursive_and_fname(args):


def transform_targets(args):
args.targets = ensure_list(args.targets)
from funcy import count_reps

counts = count_reps(ensure_list(args.targets))
dupes = [key for key, count in counts.items() if count > 1]
if dupes:
msg = ", ".join(f"[b]{key}[/]" for key in dupes)
ui.error_write(f"ignoring duplicated targets: {msg}", styled=True)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the capitalization of message (or, not) could be another topic for the UI discussion.

args.targets = list(counts)


def check_arg_combinations(args):
Expand Down
4 changes: 4 additions & 0 deletions dvc/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ def error_write(
style: str = None,
sep: str = None,
end: str = None,
styled: bool = True,
force: bool = True,
) -> None:
return self.write(
*objects,
style=style,
sep=sep,
end=end,
stderr=True,
force=force,
styled=styled,
)

def write(
Expand Down
9 changes: 9 additions & 0 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,3 +1229,12 @@ def test_add_does_not_remove_stage_file_on_failure(
assert str(exc_info.value) == exc_msg
assert (tmp_dir / "foo.dvc").exists()
assert (tmp_dir / stage.path).read_text() == dvcfile_contents


def test_add_ignore_duplicated_targets(tmp_dir, dvc, capsys):
tmp_dir.gen({"foo": "foo", "bar": "bar", "foobar": "foobar"})
stages = dvc.add(["foo", "bar", "foobar", "bar", "foo"])

_, err = capsys.readouterr()
assert len(stages) == 3
assert "ignoring duplicated targets: foo, bar" in err