diff --git a/dvc/repo/brancher.py b/dvc/repo/brancher.py index 9cb8a770b..9062901c2 100644 --- a/dvc/repo/brancher.py +++ b/dvc/repo/brancher.py @@ -4,7 +4,12 @@ from dvc.tree.local import LocalTree def brancher( # noqa: E302 - self, revs=None, all_branches=False, all_tags=False, all_commits=False + self, + revs=None, + all_branches=False, + all_tags=False, + all_commits=False, + sha_only=False, ): """Generator that iterates over specified revisions. @@ -13,6 +18,7 @@ def brancher( # noqa: E302 all_branches (bool): iterate over all available branches. all_commits (bool): iterate over all commits. all_tags (bool): iterate over all available tags. + sha_only (bool): only return git SHA for a revision. Yields: str: the display name for the currently selected tree, it could be: @@ -53,6 +59,9 @@ def brancher( # noqa: E302 # ignore revs that don't contain repo root # (i.e. revs from before a subdir=True repo was init'ed) if self.tree.exists(self.root_dir): - yield ", ".join(names) + if sha_only: + yield sha + else: + yield ", ".join(names) finally: self.tree = saved_tree diff --git a/dvc/repo/experiments/show.py b/dvc/repo/experiments/show.py index 1175d4570..54f448e8d 100644 --- a/dvc/repo/experiments/show.py +++ b/dvc/repo/experiments/show.py @@ -17,7 +17,7 @@ def _collect_experiment(repo, branch, stash=False, sha_only=True): if rev == "workspace": res["timestamp"] = None else: - commit = repo.scm.repo.rev_parse(rev) + commit = _resolve_commit(repo, rev) res["timestamp"] = datetime.fromtimestamp(commit.committed_date) configs = _collect_configs(repo) @@ -44,6 +44,15 @@ def _collect_experiment(repo, branch, stash=False, sha_only=True): return res +def _resolve_commit(repo, rev): + from git.objects.tag import TagObject + + commit = repo.scm.repo.rev_parse(rev) + if isinstance(commit, TagObject): + commit = commit.object + return commit + + @locked def show( repo, @@ -65,6 +74,7 @@ def show( all_branches=all_branches, all_tags=all_tags, all_commits=all_commits, + sha_only=True, ) )