From c9cd4a8c510725755091ed1609fe822fab7c1c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Thu, 25 Nov 2021 11:23:31 +0545 Subject: [PATCH] scm: remove dvc specific message; add client kwarg This commit removes dvc specific message hardcoded in scm.detach_head. Now that we are decoupling scm, we are adding `client=` kwarg to be set by the caller. --- dvc/repo/experiments/__init__.py | 4 ++-- dvc/scm/git/__init__.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index 04d2013ad..1ef16c1a1 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -165,7 +165,7 @@ class Experiments: the human-readable name in the experiment branch ref. Has no effect of branch is specified. """ - with self.scm.detach_head() as orig_head: + with self.scm.detach_head(client="dvc") as orig_head: stash_head = orig_head if baseline_rev is None: baseline_rev = orig_head @@ -810,7 +810,7 @@ class Experiments: # `checkout --force` here will not lose any data (popping stash commit # will result in conflict between workspace params and stashed CLI # params, but we always want the stashed version). - with self.scm.detach_head(entry.rev, force=True): + with self.scm.detach_head(entry.rev, force=True, client="dvc"): rev = self.stash.pop() self.scm.set_ref(EXEC_BASELINE, entry.baseline_rev) if entry.branch: diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 0a567f36d..ccdc947ec 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -317,7 +317,12 @@ class Git(Base): commit = self.resolve_commit(parent) @contextmanager - def detach_head(self, rev: Optional[str] = None, force: bool = False): + def detach_head( + self, + rev: Optional[str] = None, + force: bool = False, + client: str = "scm", + ): """Context manager for performing detached HEAD SCM operations. Detaches and restores HEAD similar to interactive git rebase. @@ -346,7 +351,7 @@ class Git(Base): "HEAD", orig_head, symbolic=symbolic, - message=f"dvc: Restore HEAD to '{name}'", + message=f"{client}: Restore HEAD to '{name}'", ) logger.debug("Restore HEAD to '%s'", name) self.reset()