Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repo: pass default_branch to SCM if set (bug 1951843) #229

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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