@@ -184,6 +184,9 @@ def get_project_git_scm_store(self):
184184 return GitStore (path )
185185
186186 def __init__ (self , path , check = True ):
187+ from ..gitea_api import Git
188+
189+ self ._git = Git (path )
187190 self .path = path
188191 self .abspath = os .path .abspath (self .path )
189192
@@ -225,7 +228,7 @@ def __init__(self, path, check=True):
225228 raise oscerr .NoWorkingCopy (msg )
226229
227230 # TODO: decide if we need explicit 'git lfs pull' or not
228- # self._run_git(["lfs", "pull"])
231+ # self._git. _run_git(["lfs", "pull"])
229232
230233 def assert_is_project (self ):
231234 if not self .is_project :
@@ -237,9 +240,6 @@ def assert_is_package(self):
237240 msg = f"Directory '{ self .path } ' is not a Git SCM working copy of a package"
238241 raise oscerr .NoWorkingCopy (msg )
239242
240- def _run_git (self , args ):
241- return subprocess .check_output (["git" ] + args , encoding = "utf-8" , cwd = self .abspath ).strip ()
242-
243243 @property
244244 def apiurl (self ):
245245 from ..obs_scm import Store
@@ -291,8 +291,8 @@ def project(self):
291291
292292 if not self ._project :
293293 # read project from Gitea (identical owner, repo: _ObsPrj, file: project.build)
294- origin = self ._run_git ([ "remote" , "get-url" , self . current_remote ] )
295- self ._project = self .get_build_project (origin )
294+ remote_url = self ._git . get_remote_url ( )
295+ self ._project = self .get_build_project (remote_url )
296296
297297 else :
298298 # handle _project in a project
@@ -317,8 +317,8 @@ def project(self, value):
317317 @property
318318 def package (self ):
319319 if self ._package is None :
320- origin = self ._run_git ([ "remote" , "get-url" , self . current_remote ] )
321- self ._package = Path (urllib .parse .urlsplit (origin ).path ).stem
320+ remote_url = self ._git . get_remote_url ( )
321+ self ._package = Path (urllib .parse .urlsplit (remote_url ).path ).stem
322322 return self ._package
323323
324324 @package .setter
@@ -327,7 +327,7 @@ def package(self, value):
327327
328328 def _get_option (self , name ):
329329 try :
330- result = self ._run_git (["config" , "--local" , "--get" , f"osc.{ name } " ])
330+ result = self ._git . _run_git (["config" , "--local" , "--get" , f"osc.{ name } " ])
331331 except subprocess .CalledProcessError :
332332 result = None
333333 return result
@@ -337,11 +337,11 @@ def _check_type(self, name, value, expected_type):
337337 raise TypeError (f"The option '{ name } ' should be { expected_type .__name__ } , not { type (value ).__name__ } " )
338338
339339 def _set_option (self , name , value ):
340- self ._run_git (["config" , "--local" , f"osc.{ name } " , value ])
340+ self ._git . _run_git (["config" , "--local" , f"osc.{ name } " , value ])
341341
342342 def _unset_option (self , name ):
343343 try :
344- self ._run_git (["config" , "--local" , "--unset" , f"osc.{ name } " ])
344+ self ._git . _run_git (["config" , "--local" , "--unset" , f"osc.{ name } " ])
345345 except subprocess .CalledProcessError :
346346 pass
347347
@@ -423,20 +423,6 @@ def build_repositories(self, value):
423423 @property
424424 def scmurl (self ):
425425 try :
426- return self ._run_git ([ "remote" , "get-url" , self . current_remote ] )
426+ return self ._git . get_remote_url ( )
427427 except subprocess .CalledProcessError :
428428 return None
429-
430- @property
431- def current_remote (self ):
432- result = None
433- try :
434- result = self ._run_git (["rev-parse" , "--abbrev-ref" , "@{u}" ])
435- if result :
436- result = result .split ("/" )[0 ]
437- except subprocess .CalledProcessError :
438- pass
439-
440- if result :
441- return result
442- return "origin"
0 commit comments