Skip to content

Commit ef1dba8

Browse files
authored
From repo with full history (#790)
Add optional full_history argument to from_repo to get all commit history.
1 parent a652487 commit ef1dba8

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

docs/api-reference/core/Codebase.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ Fetches a codebase from GitHub and returns a Codebase instance.
328328
defaultValue="None"
329329
/>
330330
<Parameter
331-
name="shallow"
331+
name="full_history"
332332
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> }
333-
description="Whether to do a shallow clone. Defaults to True"
334-
defaultValue=""
333+
description="Whether to clone the full git history. Defaults to False"
334+
defaultValue="False"
335335
/>
336336
<Parameter
337337
name="language"

src/codegen/git/repo_operator/repo_operator.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,14 @@ def create_from_commit(cls, repo_path: str, commit: str, url: str, access_token:
850850
return op
851851

852852
@classmethod
853-
def create_from_repo(cls, repo_path: str, url: str, access_token: str | None = None) -> Self | None:
853+
def create_from_repo(cls, repo_path: str, url: str, access_token: str | None = None, full_history: bool = False) -> Self | None:
854854
"""Create a fresh clone of a repository or use existing one if up to date.
855855
856856
Args:
857857
repo_path (str): Path where the repo should be cloned
858858
url (str): Git URL of the repository
859859
access_token (str | None): Optional GitHub API key for operations that need GitHub access
860+
full_history (bool): If True, clones the complete repository history. If False, performs a shallow clone. Defaults to False.
860861
"""
861862
access_token = access_token or SecretsConfig().github_token
862863
if access_token:
@@ -886,9 +887,13 @@ def create_from_repo(cls, repo_path: str, url: str, access_token: str | None = N
886887
import shutil
887888

888889
shutil.rmtree(repo_path)
890+
889891
try:
890-
# Clone the repository
891-
GitCLI.clone_from(url=url, to_path=repo_path, depth=1)
892+
# Clone the repository with or without full history
893+
if full_history:
894+
GitCLI.clone_from(url=url, to_path=repo_path)
895+
else:
896+
GitCLI.clone_from(url=url, to_path=repo_path, depth=1)
892897

893898
# Initialize with the cloned repo
894899
git_cli = GitCLI(repo_path)

src/codegen/sdk/core/codebase.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ def from_repo(
13131313
config: CodebaseConfig | None = None,
13141314
secrets: SecretsConfig | None = None,
13151315
setup_option: SetupOption | None = None,
1316+
full_history: bool = False,
13161317
) -> "Codebase":
13171318
"""Fetches a codebase from GitHub and returns a Codebase instance.
13181319
@@ -1352,7 +1353,7 @@ def from_repo(
13521353
if commit is None:
13531354
repo_config = RepoConfig.from_repo_path(repo_path)
13541355
repo_config.full_name = repo_full_name
1355-
repo_operator = RepoOperator(repo_config=repo_config, access_token=access_token, setup_option=setup_option)
1356+
repo_operator = RepoOperator.create_from_repo(repo_config=repo_config, access_token=access_token, setup_option=setup_option, full_history=full_history)
13561357
else:
13571358
# Ensure the operator can handle remote operations
13581359
repo_operator = RepoOperator.create_from_commit(repo_path=repo_path, commit=commit, url=repo_url, full_name=repo_full_name, access_token=access_token)

0 commit comments

Comments
 (0)