Skip to content

Commit 5200480

Browse files
adrianschroeterdmach
authored andcommitted
Fix tracking the right branch
We use to follow always the default branch, but we have meanwhile the trackingbranch in the scmsync url to select the right one.
1 parent 2b10d20 commit 5200480

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

osc/commands/fork.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ def run(self, args):
104104

105105
# parse gitea url, owner, repo and branch from the scmsync url
106106
if is_package:
107-
parsed_scmsync_url = urllib.parse.urlparse(pkg.scmsync, scheme="https")
107+
url_scmsync = pkg.scmsync
108108
else:
109-
parsed_scmsync_url = urllib.parse.urlparse(project.scmsync, scheme="https")
109+
url_scmsync = project.scmsync
110+
parsed_scmsync_url = urllib.parse.urlparse(url_scmsync, scheme="https")
110111
url = urllib.parse.urlunparse((parsed_scmsync_url.scheme, parsed_scmsync_url.netloc, "", "", "", ""))
111112
owner, repo = parsed_scmsync_url.path.strip("/").split("/")
112113

@@ -120,6 +121,9 @@ def run(self, args):
120121
# parse the right branch instead from .gitmodules
121122
#branch = parsed_scmsync_url.fragment or None
122123
branch = None
124+
parsed_scmsync_url_query = urllib.parse.parse_qs(parsed_scmsync_url.query)
125+
if "trackingbranch" in parsed_scmsync_url_query:
126+
branch = parsed_scmsync_url_query["trackingbranch"][0]
123127

124128
# find a credentials entry for url and OBS user (there can be multiple users configured for a single URL in the config file)
125129
gitea_conf = gitea_api.Config(args.gitea_config)
@@ -135,12 +139,10 @@ def run(self, args):
135139
print(f"Forking git repo {owner}/{repo} ...", file=sys.stderr)
136140

137141
# the branch was not specified, fetch the default branch from the repo
138-
if branch:
139-
fork_branch = branch
140-
else:
142+
if not branch:
141143
repo_obj = gitea_api.Repo.get(gitea_conn, owner, repo)
142144
branch = repo_obj.default_branch
143-
fork_branch = branch
145+
fork_branch = branch
144146

145147
# check if the scmsync branch exists in the source repo
146148
parent_branch_obj = gitea_api.Branch.get(gitea_conn, owner, repo, fork_branch)

0 commit comments

Comments
 (0)