helpers.git.get_upstream_remote: default to origin (MR 1940)
Do not crash in pmaports.git CI for merge requests where a different repository was cloned as "origin". Fixes: "ERROR: pmaports: could not find remote name for URL 'https://gitlab.com/postmarketOS/pmaports.git' in git repository: /builds/plata-gl/pmaports"
This commit is contained in:
parent
7f60a6d782
commit
1f80472dda
|
@ -97,8 +97,11 @@ def get_upstream_remote(args, name_repo):
|
|||
for line in output.split("\n"):
|
||||
if url in line:
|
||||
return line.split("\t", 1)[0]
|
||||
raise RuntimeError("{}: could not find remote name for URL '{}' in git"
|
||||
" repository: {}".format(name_repo, url, path))
|
||||
|
||||
# Fallback (e.g. when pmaports CI clones a different URL as origin)
|
||||
logging.verbose(f"{name_repo}: could not find remote name for URL '{url}',"
|
||||
f" assuming 'origin'")
|
||||
return "origin"
|
||||
|
||||
|
||||
def parse_channels_cfg(args):
|
||||
|
|
|
@ -101,10 +101,8 @@ def test_get_upstream_remote(args, monkeypatch, tmpdir):
|
|||
run_git(["init", "."])
|
||||
run_git(["commit", "--allow-empty", "-m", "commit on master"])
|
||||
|
||||
# No upstream remote
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
func(args, name_repo)
|
||||
assert "could not find remote name for URL" in str(e.value)
|
||||
# Missing upstream remote, fall back to "origin"
|
||||
assert func(args, name_repo) == "origin"
|
||||
|
||||
run_git(["remote", "add", "hello", url])
|
||||
assert func(args, name_repo) == "hello"
|
||||
|
|
Loading…
Reference in New Issue