diff --git a/dvc/repo/experiments/show.py b/dvc/repo/experiments/show.py index 600bc18f99..8cdf8b3537 100644 --- a/dvc/repo/experiments/show.py +++ b/dvc/repo/experiments/show.py @@ -100,11 +100,10 @@ def _collect_experiment_commit( for refspec in ["refs/tags", "refs/heads"]: name = repo.scm.describe(rev, base=refspec) if name: + name = name.replace(f"{refspec}/", "") break - if not name: - name = repo.experiments.get_exact_name(rev) + name = name or repo.experiments.get_exact_name(rev) if name: - name = name.rsplit("/")[-1] res["name"] = name return res @@ -117,7 +116,7 @@ def _collect_experiment_branch( baseline, onerror: Optional[Callable] = None, running=None, - **kwargs + **kwargs, ): from dvc.scm import resolve_rev @@ -132,7 +131,7 @@ def _collect_experiment_branch( onerror=onerror, status=status, running=running, - **kwargs + **kwargs, ) if len(revs) > 1: exp = {"checkpoint_tip": exp_rev} diff --git a/tests/func/experiments/test_show.py b/tests/func/experiments/test_show.py index d4e70846be..546cad341b 100644 --- a/tests/func/experiments/test_show.py +++ b/tests/func/experiments/test_show.py @@ -48,6 +48,21 @@ def test_show_no_commits(tmp_dir): assert Repo.init().experiments.show() == {} +@pytest.mark.vscode +def test_show_branch_and_tag_name(tmp_dir, scm, dvc, exp_stage): + with tmp_dir.branch("new/branch", new=True): + tmp_dir.scm_gen("branch", "branch", "commit") + branch_rev = scm.get_rev() + + result = dvc.experiments.show(all_branches=True) + assert result[branch_rev]["baseline"]["data"]["name"] == "new/branch" + + scm.tag("new/tag") + tag_rev = scm.get_rev() + result = dvc.experiments.show(all_tags=True) + assert result[tag_rev]["baseline"]["data"]["name"] == "new/tag" + + @pytest.mark.vscode def test_show_simple(tmp_dir, scm, dvc, exp_stage): assert dvc.experiments.show()["workspace"] == {