.. versionadded:: 2015.8.0

    Return the remote refs for the specified URL by running ``git ls-remote``.

    url
        URL of the remote repository

    filter
        Optionally provide a ref name to ``git ls-remote``. This can be useful
        to make this function run faster on repositories with many
        branches/tags.

        .. versionadded:: 2019.2.0

    heads : False
        Restrict output to heads. Can be combined with ``tags``.

    tags : False
        Restrict output to tags. Can be combined with ``heads``.

    user
        User under which to run the git command. By default, the command is run
        by the user under which the minion is running.

    password
        Windows only. Required when specifying ``user``. This parameter will be
        ignored on non-Windows platforms.

      .. versionadded:: 2016.3.4

    identity
        Path to a private key to use for ssh URLs

        .. warning::

            Unless Salt is invoked from the minion using ``salt-call``, the
            key(s) must be passphraseless. For greater security with
            passphraseless private keys, see the `sshd(8)`_ manpage for
            information on securing the keypair from the remote side in the
            ``authorized_keys`` file.

            .. _`sshd(8)`: http://www.man7.org/linux/man-pages/man8/sshd.8.html#AUTHORIZED_KEYS_FILE_FORMAT

        .. versionchanged:: 2015.8.7

            Salt will no longer attempt to use passphrase-protected keys unless
            invoked from the minion using ``salt-call``, to prevent blocking
            waiting for user input.

        Key can also be specified as a SaltStack file server URL, eg. salt://location/identity_file

        .. versionchanged:: 2016.3.0

    https_user
        Set HTTP Basic Auth username. Only accepted for HTTPS URLs.

    https_pass
        Set HTTP Basic Auth password. Only accepted for HTTPS URLs.

    ignore_retcode : False
        If ``True``, do not log an error to the minion log if the git command
        returns a nonzero exit status.

    saltenv
        The default salt environment to pull sls files from

        .. versionadded:: 2016.3.1

    output_encoding
        Use this option to specify which encoding to use to decode the output
        from any git commands which are run. This should not be needed in most
        cases.

        .. note::
            This should only be needed if the files in the repository were
            created with filenames using an encoding other than UTF-8 to handle
            Unicode characters.

        .. versionadded:: 2018.3.1

    CLI Example:

    .. code-block:: bash

        salt myminion git.remote_refs https://github.com/saltstack/salt.git
        salt myminion git.remote_refs https://github.com/saltstack/salt.git filter=develop

def remote_refs(url,
                heads=False,
                tags=False,
                user=None,
                password=None,
                identity=None,
                https_user=None,
                https_pass=None,
                ignore_retcode=False,
                output_encoding=None,
                saltenv='base',
                **kwargs):
    '''
    .. versionadded:: 2015.8.0

    Return the remote refs for the specified URL by running ``git ls-remote``.

    url
        URL of the remote repository

    filter
        Optionally provide a ref name to ``git ls-remote``. This can be useful
        to make this function run faster on repositories with many
        branches/tags.

        .. versionadded:: 2019.2.0

    heads : False
        Restrict output to heads. Can be combined with ``tags``.

    tags : False
        Restrict output to tags. Can be combined with ``heads``.

    user
        User under which to run the git command. By default, the command is run
        by the user under which the minion is running.

    password
        Windows only. Required when specifying ``user``. This parameter will be
        ignored on non-Windows platforms.

      .. versionadded:: 2016.3.4

    identity
        Path to a private key to use for ssh URLs

        .. warning::

            Unless Salt is invoked from the minion using ``salt-call``, the
            key(s) must be passphraseless. For greater security with
            passphraseless private keys, see the `sshd(8)`_ manpage for
            information on securing the keypair from the remote side in the
            ``authorized_keys`` file.

            .. _`sshd(8)`: http://www.man7.org/linux/man-pages/man8/sshd.8.html#AUTHORIZED_KEYS_FILE_FORMAT

        .. versionchanged:: 2015.8.7

            Salt will no longer attempt to use passphrase-protected keys unless
            invoked from the minion using ``salt-call``, to prevent blocking
            waiting for user input.

        Key can also be specified as a SaltStack file server URL, eg. salt://location/identity_file

        .. versionchanged:: 2016.3.0

    https_user
        Set HTTP Basic Auth username. Only accepted for HTTPS URLs.

    https_pass
        Set HTTP Basic Auth password. Only accepted for HTTPS URLs.

    ignore_retcode : False
        If ``True``, do not log an error to the minion log if the git command
        returns a nonzero exit status.

    saltenv
        The default salt environment to pull sls files from

        .. versionadded:: 2016.3.1

    output_encoding
        Use this option to specify which encoding to use to decode the output
        from any git commands which are run. This should not be needed in most
        cases.

        .. note::
            This should only be needed if the files in the repository were
            created with filenames using an encoding other than UTF-8 to handle
            Unicode characters.

        .. versionadded:: 2018.3.1

    CLI Example:

    .. code-block:: bash

        salt myminion git.remote_refs https://github.com/saltstack/salt.git
        salt myminion git.remote_refs https://github.com/saltstack/salt.git filter=develop
    '''
    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    filter_ = kwargs.pop('filter', None)
    if kwargs:
        salt.utils.args.invalid_kwargs(kwargs)

    command = ['git', 'ls-remote']
    if heads:
        command.append('--heads')
    if tags:
        command.append('--tags')
    try:
        command.append(salt.utils.url.add_http_basic_auth(url,
                                                          https_user,
                                                          https_pass,
                                                          https_only=True))
    except ValueError as exc:
        raise SaltInvocationError(exc.__str__())
    if filter_:
        command.append(filter_)
    output = _git_run(command,
                      user=user,
                      password=password,
                      identity=identity,
                      ignore_retcode=ignore_retcode,
                      saltenv=saltenv,
                      output_encoding=output_encoding)['stdout']
    ret = {}
    for line in salt.utils.itertools.split(output, '\n'):
        try:
            sha1_hash, ref_name = line.split(None, 1)
        except ValueError:
            continue
        ret[ref_name] = sha1_hash
    return ret