Skip to content

Commit

Permalink
Merge branch 'main' into chore/modernize-code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclotruc authored Dec 29, 2024
2 parents b034a91 + 75ee8f7 commit eb593e5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/gitingest/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CloneConfig:
branch: str | None = None



async def check_repo_exists(url: str) -> bool:
"""
Check if a repository exists at the given URL using an HTTP HEAD request.
Expand Down Expand Up @@ -44,6 +45,7 @@ async def check_repo_exists(url: str) -> bool:


async def run_git_command(*args: str) -> tuple[bytes, bytes]:

"""
Executes a git command asynchronously and captures its output.
Expand Down Expand Up @@ -109,6 +111,7 @@ async def clone_repo(config: CloneConfig) -> tuple[bytes, bytes]:
commit: str | None = config.commit
branch: str | None = config.branch


if not url:
raise ValueError("The 'url' parameter is required.")

Expand All @@ -131,6 +134,7 @@ async def clone_repo(config: CloneConfig) -> tuple[bytes, bytes]:
return await run_git_command(*checkout_cmd)

if branch and branch.lower() not in ("main", "master"):

# Scenario 2: Clone a specific branch with shallow depth
clone_cmd = ["git", "clone", "--depth=1", "--single-branch", "--branch", branch, url, local_path]
return await run_git_command(*clone_cmd)
Expand Down
3 changes: 2 additions & 1 deletion src/gitingest/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def ingest(
exclude_patterns: list[str] | str | None = None,
output: str | None = None,
) -> tuple[str, str, str]:

try:
query = parse_query(
source=source,
Expand All @@ -27,7 +28,7 @@ def ingest(

# Extract relevant fields for CloneConfig
clone_config = CloneConfig(
url=f"https://github.com/{query['slug']}.git",
url=query["url"],
local_path=query["local_path"],
commit=query.get("commit"),
branch=query.get("branch"),
Expand Down
2 changes: 1 addition & 1 deletion src/gitingest/parse_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse_url(url: str) -> dict[str, Any]:

# Handle branch names with slashes and special characters

# Find the index of the first type indicator ('tree' or 'blob'), if any
# Find the index of the first type indicator ("tree" or "blob"), if any
type_indicator_index = next((i for i, part in enumerate(remaining_parts) if part in ("tree", "blob")), None)

if type_indicator_index is None:
Expand Down
1 change: 1 addition & 0 deletions src/gitingest/tests/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async def test_clone_repo_with_commit() -> None:

with patch("gitingest.clone.check_repo_exists", return_value=True) as mock_check:
with patch("gitingest.clone.run_git_command", new_callable=AsyncMock) as mock_exec:

mock_process = AsyncMock()
mock_process.communicate.return_value = (b"output", b"error")
mock_exec.return_value = mock_process
Expand Down
2 changes: 1 addition & 1 deletion src/process_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def process_query(
ignore_patterns=exclude_patterns,
)
clone_config = CloneConfig(
url=f"https://github.com/{query['slug']}.git",
url=query["url"],
local_path=query["local_path"],
commit=query.get("commit"),
branch=query.get("branch"),
Expand Down

0 comments on commit eb593e5

Please sign in to comment.