Skip to content
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: 3 additions & 3 deletions docs/api-reference/core/Codebase.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ Fetches a codebase from GitHub and returns a Codebase instance.
defaultValue="None"
/>
<Parameter
name="shallow"
name="full_history"
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> }
description="Whether to do a shallow clone. Defaults to True"
defaultValue=""
description="Whether to clone the full git history. Defaults to False"
defaultValue="False"
/>
<Parameter
name="language"
Expand Down
11 changes: 8 additions & 3 deletions src/codegen/git/repo_operator/repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/codegen/sdk/core/codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down
Loading