Repository: iterative/dvc

Issue:
exp show: prefer exp names for experiments
From https://github.com/iterative/vscode-dvc/issues/1574

If `exp branch` is used to create a branch, `exp show` will show the existing experiment in the table but will use the branch name instead of the exp name when displaying it. When displaying the experiment we should still use the exp name instead.

The issue is that in `scm.describe` precedence is given by tag > branch > exp, but for `exp show` exp should take precedence for experiments (but not for top level/baseline git commits)

This means that users cannot use commands like exp push/pull/remove with the name displayed in the table (since the name is a branch name and not an exp name)

```
❯ dvc exp list                      ⏎
refs/tags/11-random-forest-experiments:
        foo

example-get-started git:master ✩  py:dvc ❯ dvc exp show --no-pager
 ───────────────────────────────────────────────────────────────────────────
  Experiment                  Cr…   St…   avg_prec   …   pre…   …   da…   …
 ───────────────────────────────────────────────────────────────────────────
  workspace                   -     -      0.60405   …   0.2    …   a3…   …
  random-forest-experiments   May   -      0.60405   …   0.2    …   a3…   …
                              29,
                              20…
  ├── cdad5ff [foo]           Mar   -      0.57727   …   0.2    …   a3…   …
                              22,
                              20…
  └── 13a140c                 Mar   Qu…          -   -   0.2    …   a3…   …
                              25,
                              20…
 ───────────────────────────────────────────────────────────────────────────

example-get-started git:master ✩  py:dvc ❯ dvc exp branch foo some-branch
Git branch 'some-branch' has been created from experiment 'foo'.
To switch to the new branch run:

        git checkout some-branch

example-get-started git:master ✩  py:dvc ❯ dvc exp list
refs/tags/11-random-forest-experiments:
        foo

example-get-started git:master ✩  py:dvc ❯ dvc exp show --no-pager
 ───────────────────────────────────────────────────────────────────────────
  Experiment                  Cr…   St…   avg_prec   …   pre…   …   da…   …
 ───────────────────────────────────────────────────────────────────────────
  workspace                   -     -      0.60405   …   0.2    …   a3…   …
  random-forest-experiments   May   -      0.60405   …   0.2    …   a3…   …
                              29,
                              20…
  ├── cdad5ff [some-branch]   Mar   -      0.57727   …   0.2    …   a3…   …
                              22,
                              20…
  └── 13a140c                 Mar   Qu…          -   -   0.2    …   a3…   …
                              25,
                              20…
 ───────────────────────────────────────────────────────────────────────────
```

the final `exp show` here should still be displaying `cdad5ff [foo]` rather than `cdad5ff [some-branch]`


Discussion:

Resolving patch:
diff --git a/dvc/repo/experiments/show.py b/dvc/repo/experiments/show.py
--- a/dvc/repo/experiments/show.py
+++ b/dvc/repo/experiments/show.py
@@ -22,6 +22,7 @@ def _collect_experiment_commit(
     param_deps=False,
     running=None,
     onerror: Optional[Callable] = None,
+    is_baseline: bool = False,
 ):
     from dvc.dependency import ParamsDependency, RepoDependency
 
@@ -75,10 +76,12 @@ def _collect_experiment_commit(
             res["metrics"] = vals
 
         if not sha_only and rev != "workspace":
-            for refspec in ["refs/tags", "refs/heads"]:
-                name = repo.scm.describe(rev, base=refspec)
-                if name:
-                    break
+            name: Optional[str] = None
+            if is_baseline:
+                for refspec in ["refs/tags", "refs/heads"]:
+                    name = repo.scm.describe(rev, base=refspec)
+                    if name:
+                        break
             if not name:
                 name = repo.experiments.get_exact_name(rev)
             if name:
@@ -159,6 +162,7 @@ def show(
             param_deps=param_deps,
             running=running,
             onerror=onerror,
+            is_baseline=True,
         )
 
         if rev == "workspace":


Test patch: