1+ """ This module contains functions for cloning a Git repository to a local path. """
2+
13import asyncio
24from dataclasses import dataclass
35
4- from gitingest .exceptions import AsyncTimeoutError
56from gitingest .utils import async_timeout
67
78CLONE_TIMEOUT : int = 20
@@ -59,11 +60,7 @@ async def clone_repo(config: CloneConfig) -> tuple[bytes, bytes]:
5960 Raises
6061 ------
6162 ValueError
62- If the repository does not exist or if required query parameters are missing.
63- RuntimeError
64- If any git command fails during execution.
65- AsyncTimeoutError
66- If the cloning process exceeds the specified timeout.
63+ If the 'url' or 'local_path' parameters are missing, or if the repository is not found.
6764 """
6865 # Extract and validate query parameters
6966 url : str = config .url
@@ -81,29 +78,25 @@ async def clone_repo(config: CloneConfig) -> tuple[bytes, bytes]:
8178 if not await _check_repo_exists (url ):
8279 raise ValueError ("Repository not found, make sure it is public" )
8380
84- try :
85- if commit :
86- # Scenario 1: Clone and checkout a specific commit
87- # Clone the repository without depth to ensure full history for checkout
88- clone_cmd = ["git" , "clone" , "--single-branch" , url , local_path ]
89- await _run_git_command (* clone_cmd )
90-
91- # Checkout the specific commit
92- checkout_cmd = ["git" , "-C" , local_path , "checkout" , commit ]
93- return await _run_git_command (* checkout_cmd )
81+ if commit :
82+ # Scenario 1: Clone and checkout a specific commit
83+ # Clone the repository without depth to ensure full history for checkout
84+ clone_cmd = ["git" , "clone" , "--single-branch" , url , local_path ]
85+ await _run_git_command (* clone_cmd )
9486
95- if branch and branch .lower () not in ("main" , "master" ):
87+ # Checkout the specific commit
88+ checkout_cmd = ["git" , "-C" , local_path , "checkout" , commit ]
89+ return await _run_git_command (* checkout_cmd )
9690
97- # Scenario 2: Clone a specific branch with shallow depth
98- clone_cmd = ["git" , "clone" , "--depth=1" , "--single-branch" , "--branch" , branch , url , local_path ]
99- return await _run_git_command (* clone_cmd )
91+ if branch and branch .lower () not in ("main" , "master" ):
10092
101- # Scenario 3 : Clone the default branch with shallow depth
102- clone_cmd = ["git" , "clone" , "--depth=1" , "--single-branch" , url , local_path ]
93+ # Scenario 2 : Clone a specific branch with shallow depth
94+ clone_cmd = ["git" , "clone" , "--depth=1" , "--single-branch" , "--branch" , branch , url , local_path ]
10395 return await _run_git_command (* clone_cmd )
10496
105- except (RuntimeError , asyncio .TimeoutError , AsyncTimeoutError ):
106- raise # Re-raise the exception
97+ # Scenario 3: Clone the default branch with shallow depth
98+ clone_cmd = ["git" , "clone" , "--depth=1" , "--single-branch" , url , local_path ]
99+ return await _run_git_command (* clone_cmd )
107100
108101
109102async def _check_repo_exists (url : str ) -> bool :
0 commit comments