diff --git a/backend/src/services/git_service.py b/backend/src/services/git_service.py index a5147ef9..85da63ae 100644 --- a/backend/src/services/git_service.py +++ b/backend/src/services/git_service.py @@ -319,12 +319,13 @@ class GitService: # @PARAM: remote_url (str) # @PARAM: pat (str) - Personal Access Token for authentication. # @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. # @POST: Repository is cloned or opened at the local path. # @RETURN: Repo - GitPython Repo object. # @RELATION: CALLS -> [GitService._get_repo_path] # @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"): self._ensure_base_path_exists() repo_path = self._get_repo_path(dashboard_id, repo_key=repo_key or str(dashboard_id)) @@ -354,7 +355,11 @@ class GitService: return repo 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) return repo # [/DEF:backend.src.services.git_service.GitService.init_repo:Function]