Skip to content

Commit

Permalink
GitSCM: set Git user on local clone
Browse files Browse the repository at this point in the history
  • Loading branch information
shtrom committed Jan 9, 2025
1 parent 2d3451f commit aea01be
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lando/main/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit aea01be

Please sign in to comment.