Create a git command with authentication if needed. Parameters ---------- base_cmd : list[str] The base git command to start with. local_path : str The local path where the git command should be executed. url : str The repository URL to check if it's a Gi
(base_cmd: list[str], local_path: str, url: str, token: str | None = None)
| 254 | |
| 255 | |
| 256 | def create_git_command(base_cmd: list[str], local_path: str, url: str, token: str | None = None) -> list[str]: |
| 257 | """Create a git command with authentication if needed. |
| 258 | |
| 259 | Parameters |
| 260 | ---------- |
| 261 | base_cmd : list[str] |
| 262 | The base git command to start with. |
| 263 | local_path : str |
| 264 | The local path where the git command should be executed. |
| 265 | url : str |
| 266 | The repository URL to check if it's a GitHub repository. |
| 267 | token : str | None |
| 268 | GitHub personal access token (PAT) for accessing private repositories. |
| 269 | |
| 270 | Returns |
| 271 | ------- |
| 272 | list[str] |
| 273 | The git command with authentication if needed. |
| 274 | |
| 275 | """ |
| 276 | cmd = [*base_cmd, "-C", local_path] |
| 277 | if token and is_github_host(url): |
| 278 | cmd += ["-c", create_git_auth_header(token, url=url)] |
| 279 | return cmd |
| 280 | |
| 281 | |
| 282 | def create_git_auth_header(token: str, url: str = "https://github.com") -> str: |