import re


def normalize_ssh_url(url):
    """Convert a SSH-like url to a RFC1738-compliant url

    >>> normalize_ssh_url('user@host.xz:/path/to/repo.git/') == 'ssh://user@host.xz/path/to/repo.git/'
    True
    >>> normalize_ssh_url('user@host.xz:path/to/repo.git/') == 'ssh://user@host.xz/path/to/repo.git/'
    True

    :param url:
    :return:
    """
    matcher = re.match(r"(?P<username>\w+@|)(?P<hostname>\w+\.[^:]+):(?P<path>.+)", url)
    if matcher:
        (username, hostname, path) = matcher.groups()
        if not path.startswith("/"):
            path = "/" + path
        return "ssh://%s%s%s" % (username, hostname, path)
    return url