From 3374a7134ec775b30f986107dd3403b6f64de3a9 Mon Sep 17 00:00:00 2001 From: Vishal Shenoy Date: Mon, 10 Mar 2025 15:03:30 -0700 Subject: [PATCH 1/2] from repo --- src/codegen/git/repo_operator/repo_operator.py | 11 ++++++++--- src/codegen/sdk/core/codebase.py | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/codegen/git/repo_operator/repo_operator.py b/src/codegen/git/repo_operator/repo_operator.py index b5febfe14..c68ce1157 100644 --- a/src/codegen/git/repo_operator/repo_operator.py +++ b/src/codegen/git/repo_operator/repo_operator.py @@ -850,13 +850,14 @@ def create_from_commit(cls, repo_path: str, commit: str, url: str, access_token: return op @classmethod - def create_from_repo(cls, repo_path: str, url: str, access_token: str | None = None) -> Self | None: + def create_from_repo(cls, repo_path: str, url: str, access_token: str | None = None, full_history: bool = False) -> Self | None: """Create a fresh clone of a repository or use existing one if up to date. Args: repo_path (str): Path where the repo should be cloned url (str): Git URL of the repository access_token (str | None): Optional GitHub API key for operations that need GitHub access + full_history (bool): If True, clones the complete repository history. If False, performs a shallow clone. Defaults to False. """ access_token = access_token or SecretsConfig().github_token if access_token: @@ -886,9 +887,13 @@ def create_from_repo(cls, repo_path: str, url: str, access_token: str | None = N import shutil shutil.rmtree(repo_path) + try: - # Clone the repository - GitCLI.clone_from(url=url, to_path=repo_path, depth=1) + # Clone the repository with or without full history + if full_history: + GitCLI.clone_from(url=url, to_path=repo_path) + else: + GitCLI.clone_from(url=url, to_path=repo_path, depth=1) # Initialize with the cloned repo git_cli = GitCLI(repo_path) diff --git a/src/codegen/sdk/core/codebase.py b/src/codegen/sdk/core/codebase.py index 2c641e655..d9a6e6960 100644 --- a/src/codegen/sdk/core/codebase.py +++ b/src/codegen/sdk/core/codebase.py @@ -1313,6 +1313,7 @@ def from_repo( config: CodebaseConfig | None = None, secrets: SecretsConfig | None = None, setup_option: SetupOption | None = None, + full_history: bool = False, ) -> "Codebase": """Fetches a codebase from GitHub and returns a Codebase instance. @@ -1352,7 +1353,7 @@ def from_repo( if commit is None: repo_config = RepoConfig.from_repo_path(repo_path) repo_config.full_name = repo_full_name - repo_operator = RepoOperator(repo_config=repo_config, access_token=access_token, setup_option=setup_option) + repo_operator = RepoOperator.create_from_repo(repo_config=repo_config, access_token=access_token, setup_option=setup_option, full_history=full_history) else: # Ensure the operator can handle remote operations repo_operator = RepoOperator.create_from_commit(repo_path=repo_path, commit=commit, url=repo_url, full_name=repo_full_name, access_token=access_token) From 3be714ad87bd63df76e8ce8f659269ede35b3f06 Mon Sep 17 00:00:00 2001 From: Vishal Shenoy Date: Mon, 10 Mar 2025 15:53:26 -0700 Subject: [PATCH 2/2] docs --- docs/api-reference/core/Codebase.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api-reference/core/Codebase.mdx b/docs/api-reference/core/Codebase.mdx index bcfbc0c38..529d9eb13 100644 --- a/docs/api-reference/core/Codebase.mdx +++ b/docs/api-reference/core/Codebase.mdx @@ -328,10 +328,10 @@ Fetches a codebase from GitHub and returns a Codebase instance. defaultValue="None" /> bool } - description="Whether to do a shallow clone. Defaults to True" - defaultValue="" + description="Whether to clone the full git history. Defaults to False" + defaultValue="False" />