Skip to content
Snippets Groups Projects
Commit 29456f16 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

git: escape invalid Git refs that are still valid topic names

parent 9699ccac
No related branches found
No related tags found
1 merge request!41git: escape invalid Git refs that are still valid topic names
Pipeline #13815 passed
Pipeline: hgitaly

#13816

    ......@@ -55,6 +55,8 @@
    from . import obsutil
    from .branch import set_default_gitlab_branch
    DOT_BYTE = ord(b'.')
    class MultipleDescendants(LookupError):
    pass
    ......@@ -921,6 +923,12 @@
    topbranch = topbranch.replace(b' ', b'_')
    if b':' in topbranch:
    branch, topic = topbranch.split(b':', 1)
    topic = topic.replace(b'.lock', b'_lock')
    if topic[0] == DOT_BYTE:
    topic = b'_' + topic[1:]
    if topic[-1] == DOT_BYTE:
    topic = topic[:-1] + b'_'
    if b'/' in topic:
    msg = b"Invalid character '/' in topic name %r. " % topic
    if self.ui.configbool(b'experimental',
    ......
    ......@@ -803,6 +803,26 @@
    ('post-receive', (prune_reasons, changes))]
    def test_topic_git_escape(tmpdir, monkeypatch):
    notifs = []
    patch_gitlab_hooks(monkeypatch, notifs)
    wrapper, _ = make_main_repo(tmpdir.join('repo.hg'))
    del notifs[:]
    # Only test names that are possible with topics in the first place
    invalid_git_ref_names = [
    ".starts-with-dot",
    "..",
    "ends-with.lock",
    "ends-with-dot.",
    ]
    for name in invalid_git_ref_names:
    wrapper.write_commit('zz', message='in topic', topic=name)
    # This fails if topic names that are invalid in Git are not escaped
    wrapper.command('gitlab-mirror')
    def test_topic_add_rebase_publish(tmpdir, monkeypatch):
    notifs = []
    patch_gitlab_hooks(monkeypatch, notifs)
    ......
    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