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
2 changes: 1 addition & 1 deletion dvc/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def run(self):
show_hash = self.args.show_hash
hide_missing = self.args.b_rev or self.args.hide_missing
if hide_missing:
del diff["not in cache"]
diff.pop("not in cache", None)

for key, entries in diff.items():
entries = sorted(
Expand Down
29 changes: 20 additions & 9 deletions tests/unit/command/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,31 @@ def test_diff_show_markdown_and_hash(mocker, show_hash):
mock_show_markdown.assert_called_once_with(diff, show_hash, False)


def test_no_changes(mocker, capsys):
args = parse_args(["diff", "--json"])
@pytest.mark.parametrize(
"opts",
(
[],
["a_rev", "b_rev"],
["--targets", "."],
["--hide-missing"],
),
)
@pytest.mark.parametrize(
"show, expected",
(
([], ""),
(["--json"], "{}"),
(["--md"], "| Status | Path |\n|----------|--------|"),
),
)
def test_no_changes(mocker, capsys, opts, show, expected):
args = parse_args(["diff", *opts, *show])
cmd = args.func(args)
mocker.patch("dvc.repo.Repo.diff", return_value={})

assert 0 == cmd.run()
out, _ = capsys.readouterr()
assert "{}" in out

args = parse_args(["diff"])
cmd = args.func(args)
assert 0 == cmd.run()
out, _ = capsys.readouterr()
assert not out
assert expected == out.strip()


def test_show_markdown(capsys):
Expand Down