@@ -53,7 +53,7 @@ def to_tuple(self):
5353
5454GitProjectRemoteDict = Dict [str , GitRemote ]
5555GitFullRemoteDict = Dict [str , GitRemoteDict ]
56- GitRemotesArgs = Union [None , GitFullRemoteDict , Dict [str , str ]]
56+ GitRemotesArgs = Union [None , GitFullRemoteDict , GitProjectRemoteDict , Dict [str , str ]]
5757
5858
5959@dataclasses .dataclass
@@ -123,6 +123,9 @@ def from_stdout(cls, value: str):
123123 re .VERBOSE | re .MULTILINE ,
124124 )
125125 matches = pattern .search (value )
126+
127+ if matches is None :
128+ raise Exception ("Could not find match" )
126129 return cls (** matches .groupdict ())
127130
128131
@@ -154,6 +157,7 @@ def convert_pip_url(pip_url: str) -> VCSLocation:
154157class GitProject (BaseProject ):
155158 bin_name = "git"
156159 schemes = ("git" , "git+http" , "git+https" , "git+ssh" , "git+git" , "git+file" )
160+ _remotes : GitProjectRemoteDict
157161
158162 def __init__ (
159163 self , * , url : str , dir : StrPath , remotes : GitRemotesArgs = None , ** kwargs
@@ -226,7 +230,11 @@ def __init__(
226230 )
227231 elif isinstance (remote_url , dict ):
228232 self ._remotes [remote_name ] = GitRemote (
229- ** {** remote_url , "name" : remote_name }
233+ ** {
234+ "fetch_url" : remote_url ["fetch_url" ],
235+ "push_url" : remote_url ["push_url" ],
236+ "name" : remote_name ,
237+ }
230238 )
231239 elif isinstance (remote_url , GitRemote ):
232240 self ._remotes [remote_name ] = remote_url
@@ -238,13 +246,15 @@ def __init__(
238246 push_url = url ,
239247 )
240248 super ().__init__ (url = url , dir = dir , ** kwargs )
241- self .url = self .chomp_protocol (
242- (
243- self ._remotes .get ("origin" )
244- if "origin" in self ._remotes
245- else next (iter (self ._remotes .items ()))[1 ]
246- ).fetch_url
249+
250+ origin = (
251+ self ._remotes .get ("origin" )
252+ if "origin" in self ._remotes
253+ else next (iter (self ._remotes .items ()))[1 ]
247254 )
255+ if origin is None :
256+ raise Exception ("Missing origin" )
257+ self .url = self .chomp_protocol (origin .fetch_url )
248258
249259 @classmethod
250260 def from_pip_url (cls , pip_url , ** kwargs ):
@@ -376,6 +386,8 @@ def update_repo(self, set_remotes: bool = False, *args, **kwargs):
376386 show_ref_output ,
377387 re .MULTILINE ,
378388 )
389+ if m is None :
390+ raise exc .CommandError ("Could not fetch remote names" )
379391 git_remote_name = m .group ("git_remote_name" )
380392 git_tag = m .group ("git_tag" )
381393 self .log .debug ("git_remote_name: %s" % git_remote_name )
@@ -497,15 +509,15 @@ def remotes(self, flat=False) -> Dict:
497509 remotes = {}
498510
499511 cmd = self .run (["remote" ])
500- ret = filter (None , cmd .split ("\n " ))
512+ ret : filter [ str ] = filter (None , cmd .split ("\n " ))
501513
502514 for remote_name in ret :
503- remotes [ remote_name ] = (
504- self . remote ( remote_name ) if flat else self . remote ( remote_name ). to_dict ()
505- )
515+ remote = self . remote ( remote_name )
516+ if remote is not None :
517+ remotes [ remote_name ] = remote if flat else remote . to_dict ( )
506518 return remotes
507519
508- def remote (self , name , ** kwargs ) -> GitRemote :
520+ def remote (self , name , ** kwargs ) -> Optional [ GitRemote ] :
509521 """Get the fetch and push URL for a specified remote name.
510522
511523 Parameters
0 commit comments