metrics: don't show working tree if it is clean

This commit is contained in:
Alexander Schepanovski
2020-01-01 10:59:13 +07:00
parent 0a3a9bf58c
commit b8cb6d72a9
2 changed files with 28 additions and 2 deletions
+9
View File
@@ -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:
+19 -2
View File
@@ -83,6 +83,25 @@ class TestMetricsBase(TestDvcGit):
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)
@@ -708,7 +727,6 @@ class TestCachedMetrics(TestDvcGit):
"master": {"metrics.json": ["master"]},
"one": {"metrics.json": ["one"]},
"two": {"metrics.json": ["two"]},
"working tree": {"metrics.json": ["two"]},
},
)
@@ -722,7 +740,6 @@ class TestCachedMetrics(TestDvcGit):
"master": {"metrics.json": ["master"]},
"one": {"metrics.json": ["one"]},
"two": {"metrics.json": ["two"]},
"working tree": {"metrics.json": ["two"]},
},
)