Skip to content
Snippets Groups Projects
Commit d1a3d91594a4 authored by Georges Racinet's avatar Georges Racinet
Browse files

Git: robustness with respect to bogus topic GitLab branches

We've just had a GitLab branch named `topic/something` (with
no named branch) on foss.heptapod.net, and it blocked all
pushes to the affected project.

We should probably just prune it, but I feel like not adding
any risk we can avoid these days.
parent 8344bcbd9667
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -30,6 +30,10 @@
pass
class InvalidRef(ValueError):
pass
def git_branch_ref(branch):
return 'refs/heads/' + branch
......@@ -58,6 +62,14 @@
>>> parse_git_branch_ref("refs/heads/branch/ze/branch")
('ze/branch', None)
>>> try:
... _ = parse_git_branch_ref("refs/heads/topic/invalid")
... except InvalidRef as exc:
... print(exc.args[0])
... else:
... print("Expected InvalidRef exception not raised")
refs/heads/topic/invalid
"""
git_ref_prefix = 'refs/heads/'
if not ref.startswith(git_ref_prefix):
......@@ -66,7 +78,10 @@
topic_prefix = 'topic/'
if git_branch.startswith(topic_prefix):
return tuple(git_branch.split('/', 1)[1].rsplit('/', 1))
res = tuple(git_branch.split('/', 1)[1].rsplit('/', 1))
if len(res) != 2:
raise InvalidRef(ref)
return res
named_branch_prefix = 'branch/'
if git_branch.startswith(named_branch_prefix):
......@@ -373,7 +388,13 @@
if ref.startswith('refs/heads/wild/'):
changes[ref] = GitRefChange(ref, before_git_sha, ZERO_SHA)
branch_topic = parse_git_branch_ref(ref)
try:
branch_topic = parse_git_branch_ref(ref)
except InvalidRef:
self.repo.ui.warn("Git mirror repo has a bogus branch ref %r "
"that's not among the exportable ones. "
"Ignoring it.")
continue
if branch_topic is not None and branch_topic[1]:
branch, topic = branch_topic
before_hg_sha = self.map_hg_get(before_git_sha)
......
......@@ -101,6 +101,16 @@
assert new_sha is None
def test_analyse_vanished_bogus_topic(tmpdir):
wrapper = LocalRepoWrapper.init(tmpdir.join('repo'))
handler = HeptapodGitHandler(wrapper.repo, wrapper.repo.ui)
assert handler.analyze_vanished_refs(
{'refs/heads/topic/missing-branch-name': 'ca1234fe',
'refs/heads/branch/default': 'will be completely ignored anyway'},
{'refs/heads/branch/default': 'will be completely ignored anyway'},
) == {}
def test_analyse_vanished_topic_draft_succ_unknown_reason(tmpdir):
wrapper = LocalRepoWrapper.init(tmpdir.join('repo'),
config=common_config())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment