mirror of
https://github.com/openSUSE/osc.git
synced 2025-10-25 09:42:15 +02:00
Migrate git_scm.Store over to gitea_api.Git
This commit is contained in:
@@ -136,12 +136,34 @@ class Git:
|
||||
|
||||
# REMOTES
|
||||
|
||||
def get_remote_url(self, name: str = "origin") -> str:
|
||||
def get_remote_url(self, name: Optional[str] = None) -> str:
|
||||
if not name:
|
||||
name = self.get_current_remote()
|
||||
return self._run_git(["remote", "get-url", name])
|
||||
|
||||
def add_remote(self, name: str, url: str):
|
||||
self._run_git(["remote", "add", name, url])
|
||||
|
||||
def get_current_remote(self, fallback_to_origin: bool = True) -> Optional[str]:
|
||||
result = None
|
||||
try:
|
||||
result = self._run_git(["rev-parse", "--abbrev-ref", "@{u}"], mute_stderr=True)
|
||||
if result:
|
||||
result = result.split("/")[0]
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
# the tracking information isn't sometimes set
|
||||
# let's fall back to 'origin' if available
|
||||
if not result and fallback_to_origin:
|
||||
try:
|
||||
self._run_git(["remote", "get-url", "origin"], mute_stderr=True)
|
||||
result = "origin"
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
return result
|
||||
|
||||
def fetch(self, name: Optional[str] = None):
|
||||
if name:
|
||||
cmd = ["fetch", name]
|
||||
|
||||
Reference in New Issue
Block a user