mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
metrics: fix diff bt active branch and workspace
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
1d5de9c5ba
commit
c6b602a167
@@ -12,6 +12,13 @@ def diff(repo, *args, a_rev=None, b_rev=None, **kwargs):
|
||||
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()
|
||||
metrics["workspace"] = metrics[active_branch]
|
||||
|
||||
old = metrics.get(a_rev, {}).get("data", {})
|
||||
new = metrics.get(b_rev, {}).get("data", {})
|
||||
|
||||
|
||||
@@ -235,3 +235,20 @@ def test_diff_top_level_metrics(tmp_dir, dvc, scm, dvcfile, metrics_file):
|
||||
"foo": {"diff": 2, "new": 5, "old": 3}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_metrics_diff_active_branch_unchanged(
|
||||
tmp_dir, scm, dvc, run_copy_metrics
|
||||
):
|
||||
def _gen(val):
|
||||
metrics = {"a": {"b": {"c": val, "d": 1, "e": str(val)}}}
|
||||
(tmp_dir / "m_temp.yaml").dump(metrics)
|
||||
run_copy_metrics(
|
||||
"m_temp.yaml", "m.yaml", metrics=["m.yaml"], commit=str(val)
|
||||
)
|
||||
|
||||
_gen(1)
|
||||
_gen(2)
|
||||
_gen(1)
|
||||
|
||||
assert dvc.metrics.diff(a_rev=tmp_dir.scm.active_branch()) == {}
|
||||
|
||||
Reference in New Issue
Block a user