def hg_repo(repo):
    """
    Tests if a repo URL is a hg repo, then returns the repo url.
    """
    if repo.startswith('https://bitbucket.org/') and not repo.endswith('.git'):
        return repo

    if repo.startswith('http://hg.'):
        return repo

    # not hg
    return None