1616 resolve_commit ,
1717 run_command ,
1818)
19+ from gitingest .utils .logging_config import get_logger
1920from gitingest .utils .os_utils import ensure_directory_exists_or_create
2021from gitingest .utils .timeout_wrapper import async_timeout
2122
2223if TYPE_CHECKING :
2324 from gitingest .schemas import CloneConfig
2425
26+ # Initialize logger for this module
27+ logger = get_logger (__name__ )
28+
2529
2630@async_timeout (DEFAULT_TIMEOUT )
2731async def clone_repo (config : CloneConfig , * , token : str | None = None ) -> None :
@@ -49,14 +53,35 @@ async def clone_repo(config: CloneConfig, *, token: str | None = None) -> None:
4953 local_path : str = config .local_path
5054 partial_clone : bool = config .subpath != "/"
5155
56+ logger .info (
57+ "Starting git clone operation" ,
58+ extra = {
59+ "url" : url ,
60+ "local_path" : local_path ,
61+ "partial_clone" : partial_clone ,
62+ "subpath" : config .subpath ,
63+ "branch" : config .branch ,
64+ "tag" : config .tag ,
65+ "commit" : config .commit ,
66+ "include_submodules" : config .include_submodules ,
67+ },
68+ )
69+
70+ logger .debug ("Ensuring git is installed" )
5271 await ensure_git_installed ()
72+
73+ logger .debug ("Creating local directory" , extra = {"parent_path" : str (Path (local_path ).parent )})
5374 await ensure_directory_exists_or_create (Path (local_path ).parent )
5475
76+ logger .debug ("Checking if repository exists" , extra = {"url" : url })
5577 if not await check_repo_exists (url , token = token ):
78+ logger .error ("Repository not found" , extra = {"url" : url })
5679 msg = "Repository not found. Make sure it is public or that you have provided a valid token."
5780 raise ValueError (msg )
5881
82+ logger .debug ("Resolving commit reference" )
5983 commit = await resolve_commit (config , token = token )
84+ logger .debug ("Resolved commit" , extra = {"commit" : commit })
6085
6186 clone_cmd = ["git" ]
6287 if token and is_github_host (url ):
@@ -69,20 +94,30 @@ async def clone_repo(config: CloneConfig, *, token: str | None = None) -> None:
6994 clone_cmd += [url , local_path ]
7095
7196 # Clone the repository
97+ logger .info ("Executing git clone command" , extra = {"command" : " " .join ([* clone_cmd [:- 1 ], "<url>" , local_path ])})
7298 await run_command (* clone_cmd )
99+ logger .info ("Git clone completed successfully" )
73100
74101 # Checkout the subpath if it is a partial clone
75102 if partial_clone :
103+ logger .info ("Setting up partial clone for subpath" , extra = {"subpath" : config .subpath })
76104 await checkout_partial_clone (config , token = token )
105+ logger .debug ("Partial clone setup completed" )
77106
78107 git = create_git_command (["git" ], local_path , url , token )
79108
80109 # Ensure the commit is locally available
110+ logger .debug ("Fetching specific commit" , extra = {"commit" : commit })
81111 await run_command (* git , "fetch" , "--depth=1" , "origin" , commit )
82112
83113 # Write the work-tree at that commit
114+ logger .info ("Checking out commit" , extra = {"commit" : commit })
84115 await run_command (* git , "checkout" , commit )
85116
86117 # Update submodules
87118 if config .include_submodules :
119+ logger .info ("Updating submodules" )
88120 await run_command (* git , "submodule" , "update" , "--init" , "--recursive" , "--depth=1" )
121+ logger .debug ("Submodules updated successfully" )
122+
123+ logger .info ("Git clone operation completed successfully" , extra = {"local_path" : local_path })
0 commit comments