44from pathlib import Path
55from typing import ClassVar , Self
66
7- from ..constants import GITLOGGER_NAME
7+ from ..constants import GIT_CONFIG_FILENAME , GITLOGGER_NAME
88from ..models .repo import Repo
99from ..utils .shell import execute_git_command
1010
@@ -17,18 +17,24 @@ class ManagedGitRepo:
1717 #: Class variable to indicate the update state of a repo
1818 _is_updated : ClassVar [dict [Repo , bool ]] = {}
1919
20- def __init__ (self : Self , remote_url : str , permanent_root : Path ) -> None :
20+ def __init__ (self : Self ,
21+ remote_url : str ,
22+ permanent_root : Path ,
23+ gitconfig : Path | None = None ) -> None :
2124 """Initialize the managed repository.
2225
2326 :param remote_url: The remote URL of the repository.
2427 :param permanent_root: The root directory for storing permanent bare clones.
28+ :param gitconfig: The path to a separate Git configuration file
29+ (=None, use the default config from etc/gitconfig)
2530 """
2631 self ._repo_model = Repo (remote_url )
2732 self ._permanent_root = permanent_root
2833 # The Repo model handles the "sluggification" of the URL
2934 self .bare_repo_path = self ._permanent_root / self ._repo_model .slug
3035 # Initialize attribute for output:
3136 self .stdout = self .stderr = None
37+ self ._gitconfig = gitconfig
3238 # Add repo into class variable
3339 type (self )._is_updated .setdefault (self ._repo_model , False )
3440
@@ -71,6 +77,7 @@ async def _initial_clone(self: Self) -> bool:
7177 str (url ),
7278 str (self .bare_repo_path ),
7379 cwd = self ._permanent_root ,
80+ gitconfig = self ._gitconfig ,
7481 )
7582 log .info ("Cloned '%s' successfully" , url )
7683 return True
@@ -133,7 +140,8 @@ async def create_worktree(
133140 clone_args .extend ([str (self .bare_repo_path ), str (target_dir )])
134141
135142 self .stdout , self .stderr = await execute_git_command (
136- * clone_args , cwd = target_dir .parent
143+ * clone_args , cwd = target_dir .parent ,
144+ gitconfig = self ._gitconfig ,
137145 )
138146
139147 async def fetch_updates (self : Self ) -> bool :
@@ -151,7 +159,9 @@ async def fetch_updates(self: Self) -> bool:
151159 log .info ("Fetching updates for '%s'" , self .slug )
152160 try :
153161 self .stdout , self .stderr = await execute_git_command (
154- 'fetch' , '--all' , cwd = self .bare_repo_path
162+ 'fetch' , '--all' ,
163+ cwd = self .bare_repo_path ,
164+ gitconfig = self ._gitconfig
155165 )
156166 log .info ("Successfully fetched updates for '%s'" , self .slug )
157167 return True
0 commit comments