Skip to content
Closed
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
3 changes: 3 additions & 0 deletions dvc/scm/git/backend/dulwich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def set_ref(
raise SCMError(f"Failed to set '{name}'")

def get_ref(self, name, follow: bool = True) -> Optional[str]:
from dulwich.objects import Tag
from dulwich.refs import parse_symref_value

name_b = os.fsencode(name)
Expand All @@ -342,6 +343,8 @@ def get_ref(self, name, follow: bool = True) -> Optional[str]:
except ValueError:
pass
if ref:
if isinstance(self.repo[ref], Tag):
ref = self.repo.get_peeled(name_b)
Comment on lines +346 to +347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the case where name is a symbolic reference and follow = False, like when HEAD points to refs/heads/master. (see the current test failures)

Basically we need to catch KeyError when we do the self.repo[ref] check, and pass as long as follow is also False

return os.fsdecode(ref)
return None

Expand Down
32 changes: 32 additions & 0 deletions tests/func/experiments/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,38 @@ def test_show_multiple_commits(tmp_dir, scm, dvc, exp_stage):
assert set(results.keys()) == expected


def test_show_tags(tmp_dir, scm, dvc):
tmp_dir.scm_gen("file", "1", "commit")
scm.tag("light")
rev = scm.get_rev()

show = dvc.experiments.show(all_tags=True)
assert show[rev]["baseline"]["data"]["name"] == "light"

tmp_dir.scm_gen("file", "2", "commit")
scm.tag(["-a", "annot", "-m", ""])
rev = scm.get_rev()

show = dvc.experiments.show(all_tags=True)
assert show[rev]["baseline"]["data"]["name"] == "annot"

tmp_dir.scm_gen("file", "3", "commit")
scm.tag(["-a", "annotated", "-m", ""])
scm.tag(["-a", "pointer", "-m", "", "annotated"])
rev = scm.get_rev()

show = dvc.experiments.show(all_tags=True)
assert show[rev]["baseline"]["data"]["name"] == "pointer"

tmp_dir.scm_gen("file", "3", "commit")
scm.tag(["-a", "foo", "-m", ""])
scm.tag(["-a", "stacked", "-m", ""])
rev = scm.get_rev()

show = dvc.experiments.show(all_tags=True)
assert show[rev]["baseline"]["data"]["name"] == "foo"


def test_show_sort(tmp_dir, scm, dvc, exp_stage, caplog):
with caplog.at_level(logging.ERROR):
assert main(["exp", "show", "--no-pager", "--sort-by=bar"]) != 0
Expand Down