import re


def basename(url):
    """
    Return the name of the folder that you'd get if you cloned 'url' into the
    current working directory.
    """
    # It's easy to accidentally have whitespace on the beginning or end of the
    # url.
    url = url.strip()

    url, _sep, _fragment = url.partition('#')
    # Remove trailing slash from url if present
    if url.endswith('/'):
        url = url[:-1]
    # Also strip .git from url if it ends in that.
    return re.sub(r'\.git$', '', url.split('/')[-1])