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
5 changes: 4 additions & 1 deletion dvc/repo/metrics/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ 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])
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", {})

Expand Down
22 changes: 12 additions & 10 deletions dvc/repo/metrics/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def show(
revs=None,
all_commits=False,
onerror=None,
hide_workspace=True,
):
if onerror is None:
onerror = onerror_collect
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion dvc/repo/params/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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])
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", {})
Expand Down
22 changes: 12 additions & 10 deletions dvc/repo/params/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def show(
deps=False,
onerror: Callable = None,
stages=None,
hide_workspace=True,
):
if onerror is None:
onerror = onerror_collect
Expand All @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions tests/func/metrics/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()) == {}
8 changes: 8 additions & 0 deletions tests/func/params/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,11 @@ def test_diff_top_level_params(tmp_dir, dvc, scm, dvcfile, params_file):
"foo": {"diff": 2, "new": 5, "old": 3}
}
}


def test_diff_active_branch_no_changes(tmp_dir, scm, dvc):
tmp_dir.gen("params.yaml", "foo: bar")
dvc.run(cmd="echo params.yaml", params=["foo"], single_stage=True)
scm.add(["params.yaml", "Dvcfile"])
scm.commit("bar")
assert dvc.params.diff(a_rev=tmp_dir.scm.active_branch()) == {}