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
9 changes: 9 additions & 0 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ def show(
if not res and not any(targets):
raise NoMetricsError()

# Hide working tree metrics if they are the same as in the active branch
try:
active_branch = repo.scm.active_branch()
except TypeError:
pass # Detached head
else:
if res.get("working tree") == res.get(active_branch):
res.pop("working tree", None)

missing = set(targets) - found

if missing:
Expand Down
21 changes: 19 additions & 2 deletions tests/func/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ def setUp(self):
self.dvc.scm.checkout("master")


def test_show_dirty(tmp_dir, scm, dvc):
tmp_dir.gen("metric", "master")
dvc.run(metrics_no_cache=["metric"], overwrite=True)
tmp_dir.scm_add(["metric", "metric.dvc"], commit="add metric")

tmp_dir.gen("metric", "dirty")

assert dvc.metrics.show(["metric"]) == {"": {"metric": "dirty"}}

assert dvc.metrics.show(["metric"], all_branches=True) == {
"working tree": {"metric": "dirty"},
"master": {"metric": "master"},
}

assert dvc.metrics.show(["metric"], all_tags=True) == {
"working tree": {"metric": "dirty"}
}


class TestMetrics(TestMetricsBase):
def test_show(self):
ret = self.dvc.metrics.show(["metric"], all_branches=True)
Expand Down Expand Up @@ -708,7 +727,6 @@ def _test_metrics(self, func):
"master": {"metrics.json": ["master"]},
"one": {"metrics.json": ["one"]},
"two": {"metrics.json": ["two"]},
"working tree": {"metrics.json": ["two"]},
},
)

Expand All @@ -722,7 +740,6 @@ def _test_metrics(self, func):
"master": {"metrics.json": ["master"]},
"one": {"metrics.json": ["one"]},
"two": {"metrics.json": ["two"]},
"working tree": {"metrics.json": ["two"]},
},
)

Expand Down