fix: add default_branch parameter to GitService.init_repo()
Fixed error: GitService.init_repo() got an unexpected keyword argument 'default_branch' The init_repository route was passing default_branch to GitService.init_repo(), but the method signature didn't accept this parameter. Changes: - Added default_branch: Optional[str] = None parameter to init_repo() method - Updated clone operation to use specified default branch when provided - Updated method documentation to reflect the new parameter This allows repositories to be initialized with a specific default branch as configured in GitServerConfig, while maintaining backward compatibility.
This commit is contained in:
@@ -319,12 +319,13 @@ class GitService:
|
|||||||
# @PARAM: remote_url (str)
|
# @PARAM: remote_url (str)
|
||||||
# @PARAM: pat (str) - Personal Access Token for authentication.
|
# @PARAM: pat (str) - Personal Access Token for authentication.
|
||||||
# @PARAM: repo_key (Optional[str]) - Slug-like key for deterministic folder naming on first init.
|
# @PARAM: repo_key (Optional[str]) - Slug-like key for deterministic folder naming on first init.
|
||||||
|
# @PARAM: default_branch (Optional[str]) - Default branch name to use (defaults to 'main').
|
||||||
# @PRE: dashboard_id is int, remote_url is valid Git URL, pat is provided.
|
# @PRE: dashboard_id is int, remote_url is valid Git URL, pat is provided.
|
||||||
# @POST: Repository is cloned or opened at the local path.
|
# @POST: Repository is cloned or opened at the local path.
|
||||||
# @RETURN: Repo - GitPython Repo object.
|
# @RETURN: Repo - GitPython Repo object.
|
||||||
# @RELATION: CALLS -> [GitService._get_repo_path]
|
# @RELATION: CALLS -> [GitService._get_repo_path]
|
||||||
# @RELATION: CALLS -> [GitService._ensure_gitflow_branches]
|
# @RELATION: CALLS -> [GitService._ensure_gitflow_branches]
|
||||||
def init_repo(self, dashboard_id: int, remote_url: str, pat: str, repo_key: Optional[str] = None) -> Repo:
|
def init_repo(self, dashboard_id: int, remote_url: str, pat: str, repo_key: Optional[str] = None, default_branch: Optional[str] = None) -> Repo:
|
||||||
with belief_scope("GitService.init_repo"):
|
with belief_scope("GitService.init_repo"):
|
||||||
self._ensure_base_path_exists()
|
self._ensure_base_path_exists()
|
||||||
repo_path = self._get_repo_path(dashboard_id, repo_key=repo_key or str(dashboard_id))
|
repo_path = self._get_repo_path(dashboard_id, repo_key=repo_key or str(dashboard_id))
|
||||||
@@ -354,7 +355,11 @@ class GitService:
|
|||||||
return repo
|
return repo
|
||||||
|
|
||||||
logger.info(f"[init_repo][Action] Cloning {remote_url} to {repo_path}")
|
logger.info(f"[init_repo][Action] Cloning {remote_url} to {repo_path}")
|
||||||
repo = Repo.clone_from(auth_url, repo_path)
|
# Use default_branch if specified, otherwise let GitPython use the remote's default
|
||||||
|
clone_kwargs = {}
|
||||||
|
if default_branch:
|
||||||
|
clone_kwargs['branch'] = default_branch
|
||||||
|
repo = Repo.clone_from(auth_url, repo_path, **clone_kwargs)
|
||||||
self._ensure_gitflow_branches(repo, dashboard_id)
|
self._ensure_gitflow_branches(repo, dashboard_id)
|
||||||
return repo
|
return repo
|
||||||
# [/DEF:backend.src.services.git_service.GitService.init_repo:Function]
|
# [/DEF:backend.src.services.git_service.GitService.init_repo:Function]
|
||||||
|
|||||||
Reference in New Issue
Block a user