Skip to content

Commit f31669f

Browse files
authored
Merge pull request openSUSE#1848 from openSUSE/git_store_custom_origin
Fix non-default origin
2 parents 8ff667d + 7c3a089 commit f31669f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

behave/features/git-repo-clone.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ Scenario: Clone a git repo
2727
"""
2828

2929

30+
@destructive
31+
Scenario: Clone and build with non-default origin
32+
When I execute git-obs with args "repo clone pool/test-GitPkgA --no-ssh-strict-host-key-checking"
33+
Then the exit code is 0
34+
When I set working directory to "{context.osc.temp}/test-GitPkgA"
35+
And I execute "git remote rename origin myorigin"
36+
And I execute osc with args "build --just-print-buildroot --alternative-project test:factory"
37+
Then the exit code is 0
38+
39+
3040
@destructive
3141
Scenario: Clone a git repo via http
3242
Given I execute git-obs with args "api -X PATCH /repos/pool/test-GitPkgA/ --data '{{"private": true}}'"

osc/git_scm/store.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def project(self):
235235

236236
if not self._project:
237237
# read project from Gitea (identical owner, repo: _ObsPrj, file: project.build)
238-
origin = self._run_git(["remote", "get-url", "origin"])
238+
origin = self._run_git(["remote", "get-url", self.current_remote])
239239
self._project = self.get_build_project(origin)
240240

241241
else:
@@ -261,7 +261,7 @@ def project(self, value):
261261
@property
262262
def package(self):
263263
if self._package is None:
264-
origin = self._run_git(["remote", "get-url", "origin"])
264+
origin = self._run_git(["remote", "get-url", self.current_remote])
265265
self._package = Path(urllib.parse.urlsplit(origin).path).stem
266266
return self._package
267267

@@ -328,6 +328,20 @@ def last_buildroot(self, value):
328328
@property
329329
def scmurl(self):
330330
try:
331-
return self._run_git(["remote", "get-url", "origin"])
331+
return self._run_git(["remote", "get-url", self.current_remote])
332332
except subprocess.CalledProcessError:
333333
return None
334+
335+
@property
336+
def current_remote(self):
337+
result = None
338+
try:
339+
result = self._run_git(["rev-parse", "--abbrev-ref", "@{u}"])
340+
if result:
341+
result = result.split("/")[0]
342+
except subprocess.CalledProcessError:
343+
pass
344+
345+
if result:
346+
return result
347+
return "origin"

0 commit comments

Comments
 (0)