.. versionadded:: 2015.8.0

    Unset a key in the git configuration file

    cwd
        The path to the git checkout. Must be an absolute path, or the word
        ``global`` to indicate that a global key should be unset.

    key
        The name of the configuration key to unset

    value_regex
        Regular expression that matches exactly one key, used to delete a
        single value from a multivar. Ignored if ``all`` is set to ``True``.

    all : False
        If ``True`` unset all values for a multivar. If ``False``, and ``key``
        is a multivar, an error will be raised.

    global : False
        If ``True``, unset set a global variable. Otherwise, a local variable
        will be unset.

    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

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

    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.config_unset /path/to/repo foo.bar
        salt myminion git.config_unset /path/to/repo foo.bar all=True

def config_unset(key,
                 value_regex=None,
                 cwd=None,
                 user=None,
                 password=None,
                 ignore_retcode=False,
                 output_encoding=None,
                 **kwargs):
    '''
    .. versionadded:: 2015.8.0

    Unset a key in the git configuration file

    cwd
        The path to the git checkout. Must be an absolute path, or the word
        ``global`` to indicate that a global key should be unset.

    key
        The name of the configuration key to unset

    value_regex
        Regular expression that matches exactly one key, used to delete a
        single value from a multivar. Ignored if ``all`` is set to ``True``.

    all : False
        If ``True`` unset all values for a multivar. If ``False``, and ``key``
        is a multivar, an error will be raised.

    global : False
        If ``True``, unset set a global variable. Otherwise, a local variable
        will be unset.

    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

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

    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.config_unset /path/to/repo foo.bar
        salt myminion git.config_unset /path/to/repo foo.bar all=True
    '''
    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    all_ = kwargs.pop('all', False)
    global_ = kwargs.pop('global', False)
    if kwargs:
        salt.utils.args.invalid_kwargs(kwargs)

    if cwd is None:
        if not global_:
            raise SaltInvocationError(
                '\'cwd\' argument required unless global=True'
            )
    else:
        cwd = _expand_path(cwd, user)

    command = ['git', 'config']
    if all_:
        command.append('--unset-all')
    else:
        command.append('--unset')
    command.extend(_which_git_config(global_, cwd, user, password,
                                     output_encoding=output_encoding))

    command.append(key)
    if value_regex is not None:
        command.append(value_regex)
    ret = _git_run(command,
                   cwd=cwd if cwd != 'global' else None,
                   user=user,
                   password=password,
                   ignore_retcode=ignore_retcode,
                   failhard=False,
                   output_encoding=output_encoding)
    retcode = ret['retcode']
    if retcode == 0:
        return True
    elif retcode == 1:
        raise CommandExecutionError('Section or key is invalid')
    elif retcode == 5:
        if config_get(cwd,
                      key,
                      user=user,
                      password=password,
                      ignore_retcode=ignore_retcode,
                      output_encoding=output_encoding) is None:
            raise CommandExecutionError(
                'Key \'{0}\' does not exist'.format(key)
            )
        else:
            msg = 'Multiple values exist for key \'{0}\''.format(key)
            if value_regex is not None:
                msg += ' and value_regex matches multiple values'
            raise CommandExecutionError(msg)
    elif retcode == 6:
        raise CommandExecutionError('The value_regex is invalid')
    else:
        msg = (
            'Failed to unset key \'{0}\', git config returned exit code {1}'
            .format(key, retcode)
        )
        if ret['stderr']:
            msg += '; ' + ret['stderr']
        raise CommandExecutionError(msg)