From aea01be750c8d7cca2d1f14481144e2711446c69 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 9 Jan 2025 17:27:19 +1100 Subject: [PATCH] GitSCM: set Git user on local clone --- src/lando/main/scm/git.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lando/main/scm/git.py b/src/lando/main/scm/git.py index 07573584..bab9315b 100644 --- a/src/lando/main/scm/git.py +++ b/src/lando/main/scm/git.py @@ -9,6 +9,7 @@ from lando.main.scm.consts import SCM_TYPE_GIT from lando.main.scm.exceptions import SCMException +from lando.settings import LANDO_USER_EMAIL, LANDO_USER_NAME from .abstract_scm import AbstractSCM @@ -47,6 +48,12 @@ def clone(self, source: str): """Clone a repository from a source.""" # When cloning, self.path doesn't exist yet, so we need to use another CWD. self._git_run("clone", source, self.path, cwd="/") + self._git_setup_user() + + def _git_setup_user(self): + """Configure the git user locally to repo_dir so as not to mess with the real user's configuration.""" + self._git_run("config", "user.name", LANDO_USER_NAME, cwd=self.path) + self._git_run("config", "user.email", LANDO_USER_EMAIL, cwd=self.path) def push( self, @@ -158,7 +165,13 @@ def format_stack_amend(self) -> Optional[list[str]]: def format_stack_tip(self, commit_message: str) -> Optional[list[str]]: """Add an autoformat commit to the top of the patch stack.""" - self._git_run("commit", "--all", "--message", commit_message, cwd=self.path) + try: + self._git_run("commit", "--all", "--message", commit_message, cwd=self.path) + except SCMException as exc: + if "nothing to commit, working tree clean" in exc.out: + return [] + else: + raise exc return [self.get_current_node()] def get_current_node(self) -> str: