mirror of
https://github.com/openSUSE/osc.git
synced 2025-12-23 17:29:24 +01:00
gitea/git: handle local branch when fetching remote
If the current branch tracks a local branch that in turn is tracking a remote branch, recurse to find out the remote, instead of simply returning the local branch. Signed-off-by: Danish Prakash <contact@danishpraka.sh>
This commit is contained in:
@@ -278,9 +278,29 @@ class Git:
|
|||||||
def get_current_remote(self, fallback_to_origin: bool = True) -> Optional[str]:
|
def get_current_remote(self, fallback_to_origin: bool = True) -> Optional[str]:
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
result = self._run_git(["rev-parse", "--abbrev-ref", "@{u}"], mute_stderr=True)
|
# get the upstream branch that the current branch is tracking:
|
||||||
if result:
|
# case 1: upstream is a remote-tracking branch origin/main
|
||||||
result = result.split("/")[0]
|
# case 2: upstream is a local branch slfo-main
|
||||||
|
upstream = self._run_git(
|
||||||
|
["rev-parse", "--abbrev-ref", "@{u}"], mute_stderr=True
|
||||||
|
)
|
||||||
|
if "/" in upstream:
|
||||||
|
result = upstream.split("/")[0]
|
||||||
|
try:
|
||||||
|
self._run_git(["remote", "get-url", result], mute_stderr=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
result = None
|
||||||
|
else:
|
||||||
|
# case 2: upstream is a local branch
|
||||||
|
# look up the remote that the local branch tracks
|
||||||
|
try:
|
||||||
|
remote_ref = self._run_git(
|
||||||
|
["config", f"branch.{upstream}.remote"], mute_stderr=True
|
||||||
|
)
|
||||||
|
if remote_ref:
|
||||||
|
result = remote_ref
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
pass
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user