Skip to content

Commit

Permalink
repo: pass default_branch to SCM if set (bug 1951843) (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
shtrom authored Mar 5, 2025
1 parent 4220b9a commit ff0dbd3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/lando/main/models/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ def scm(self) -> AbstractSCM:
"""Return the SCM implementation associated with this Repository"""
if not self._scm:
if impl := SCM_IMPLEMENTATIONS.get(self.scm_type):
self._scm = impl(self.path)
kwargs = {}
if self.default_branch:
kwargs["default_branch"] = self.default_branch

self._scm = impl(self.path, **kwargs)
else:
raise Exception(f"Repository type not supported: {self.scm_type}")
return self._scm
Expand Down
2 changes: 1 addition & 1 deletion src/lando/main/scm/abstract_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AbstractSCM:
# The path to the repository.
path: str

def __init__(self, path: str):
def __init__(self, path: str, **kwargs):
self.path = path

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/lando/main/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GitSCM(AbstractSCM):

default_branch: str

def __init__(self, path: str, default_branch: str = "main"):
def __init__(self, path: str, default_branch: str = "main", **kwargs):
self.default_branch = default_branch
super().__init__(path)

Expand Down
2 changes: 1 addition & 1 deletion src/lando/main/scm/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class HgSCM(AbstractSCM):

hg_repo: hglib.client.hgclient

def __init__(self, path: str, config: Optional[dict] = None):
def __init__(self, path: str, config: Optional[dict] = None, **kwargs):
self.config = copy.copy(self.DEFAULT_CONFIGS)

# Somewhere to store patch headers for testing.
Expand Down
11 changes: 11 additions & 0 deletions src/lando/main/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,14 @@ def test__models__Revision__metadata():
assert r.commit_message == commit_message
assert r.timestamp == timestamp
assert r.diff == DIFF_ONLY


@pytest.mark.parametrize(
"branch,expected_branch", [(None, "main"), ("non-default", "non-default")]
)
def test_repo_default_branch_to_scm(branch: str, expected_branch: str):
repo_path = "some_repo"
repo = Repo(pull_path=repo_path, scm_type=SCM_TYPE_GIT, default_branch=branch)

# repo.scm here is a GitSCM
assert repo.scm.default_branch == expected_branch

0 comments on commit ff0dbd3

Please sign in to comment.