diff --git a/dvc/repo/metrics/diff.py b/dvc/repo/metrics/diff.py index f6b8c1516..abede5c8a 100644 --- a/dvc/repo/metrics/diff.py +++ b/dvc/repo/metrics/diff.py @@ -11,14 +11,9 @@ def diff(repo, *args, a_rev=None, b_rev=None, **kwargs): a_rev = a_rev or "HEAD" b_rev = b_rev or "workspace" - metrics = repo.metrics.show(*args, **kwargs, revs=[a_rev, b_rev]) - - # workspace may have been replaced by active branch - workspace_rev = (a_rev == "workspace") or (b_rev == "workspace") - if workspace_rev and "workspace" not in metrics: - active_branch = repo.scm.active_branch() - if active_branch in metrics: - metrics["workspace"] = metrics[active_branch] + metrics = repo.metrics.show( + *args, **kwargs, revs=[a_rev, b_rev], hide_workspace=False + ) old = metrics.get(a_rev, {}).get("data", {}) new = metrics.get(b_rev, {}).get("data", {}) diff --git a/dvc/repo/metrics/show.py b/dvc/repo/metrics/show.py index 82ca5cfa4..d482b2db0 100644 --- a/dvc/repo/metrics/show.py +++ b/dvc/repo/metrics/show.py @@ -124,6 +124,7 @@ def show( revs=None, all_commits=False, onerror=None, + hide_workspace=True, ): if onerror is None: onerror = onerror_collect @@ -142,16 +143,17 @@ def show( repo, targets, rev, recursive, onerror=onerror ) - # Hide workspace metrics if they are the same as in the active branch - try: - active_branch = repo.scm.active_branch() - except (SCMError, NoSCMError): - # SCMError - detached head - # NoSCMError - no repo case - pass - else: - if res.get("workspace") == res.get(active_branch): - res.pop("workspace", None) + if hide_workspace: + # Hide workspace metrics if they are the same as in the active branch + try: + active_branch = repo.scm.active_branch() + except (SCMError, NoSCMError): + # SCMError - detached head + # NoSCMError - no repo case + pass + else: + if res.get("workspace") == res.get(active_branch): + res.pop("workspace", None) errored = errored_revisions(res) if errored: diff --git a/dvc/repo/params/diff.py b/dvc/repo/params/diff.py index 8f87966ae..79c68b1e4 100644 --- a/dvc/repo/params/diff.py +++ b/dvc/repo/params/diff.py @@ -11,14 +11,9 @@ def diff(repo, *args, a_rev=None, b_rev=None, **kwargs): a_rev = a_rev or "HEAD" b_rev = b_rev or "workspace" - params = repo.params.show(*args, **kwargs, revs=[a_rev, b_rev]) - - # workspace may have been replaced by active branch - workspace_rev = (a_rev == "workspace") or (b_rev == "workspace") - if workspace_rev and "workspace" not in params: - active_branch = repo.scm.active_branch() - if active_branch in params: - params["workspace"] = params[active_branch] + params = repo.params.show( + *args, **kwargs, revs=[a_rev, b_rev], hide_workspace=False + ) old = params.get(a_rev, {}).get("data", {}) new = params.get(b_rev, {}).get("data", {}) diff --git a/dvc/repo/params/show.py b/dvc/repo/params/show.py index f4a9b48c3..c432f89d8 100644 --- a/dvc/repo/params/show.py +++ b/dvc/repo/params/show.py @@ -144,6 +144,7 @@ def show( deps=False, onerror: Callable = None, stages=None, + hide_workspace=True, ): if onerror is None: onerror = onerror_collect @@ -165,16 +166,17 @@ def show( if params: res[branch] = params - # Hide workspace params if they are the same as in the active branch - try: - active_branch = repo.scm.active_branch() - except (SCMError, NoSCMError): - # SCMError - detached head - # NoSCMError - no repo case - pass - else: - if res.get("workspace") == res.get(active_branch): - res.pop("workspace", None) + if hide_workspace: + # Hide workspace params if they are the same as in the active branch + try: + active_branch = repo.scm.active_branch() + except (SCMError, NoSCMError): + # SCMError - detached head + # NoSCMError - no repo case + pass + else: + if res.get("workspace") == res.get(active_branch): + res.pop("workspace", None) errored = errored_revisions(res) if errored: