From 38642eb12713a3d6f6bada8fb051cdb108e632ca Mon Sep 17 00:00:00 2001 From: pared Date: Mon, 17 Jun 2019 19:21:17 +0200 Subject: [PATCH] metrics: show: remove active branch from tags only show call --- dvc/repo/metrics/show.py | 3 +++ tests/func/test_metrics.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/dvc/repo/metrics/show.py b/dvc/repo/metrics/show.py index 6ce9f8e719..ef953a9969 100644 --- a/dvc/repo/metrics/show.py +++ b/dvc/repo/metrics/show.py @@ -269,6 +269,9 @@ def show( if metrics: res[branch] = metrics + if all_tags and not all_branches: + res.pop(repo.scm.active_branch()) + if not res: if path: raise BadMetricError(path) diff --git a/tests/func/test_metrics.py b/tests/func/test_metrics.py index 806afcca7d..01636ca741 100644 --- a/tests/func/test_metrics.py +++ b/tests/func/test_metrics.py @@ -829,3 +829,26 @@ def test(self, dvc_repo, caplog): in caplog.text ) assert 0 == ret + + +def test_should_not_display_current_branch_on_display_tag( + git, dvc_repo, repo_dir +): + def write_metric_code(metric_filename, metric_value): + return "with open('{}', 'w') as fobj:\n fobj.write('{}')".format( + metric_filename, metric_value + ) + + metric_filename = "metric" + metric_stage = metric_filename + Stage.STAGE_FILE_SUFFIX + code = write_metric_code(metric_filename, 0.5) + run_command = 'python -c "{}"' + + dvc_repo.run(cmd=run_command.format(code), metrics=[metric_filename]) + git.index.add([metric_filename, metric_stage]) + git.index.commit("first") + tag = "v1.0" + git.git.tag(tag) + + metrics = dvc_repo.metrics.show(all_tags=True) + assert set(metrics.keys()) == {tag}