.. versionadded:: 2015.8.0

    Returns the version of Git installed on the minion

    versioninfo : False
        If ``True``, return the version in a versioninfo list (e.g. ``[2, 5,
        0]``)

    CLI Example:

    .. code-block:: bash

        salt myminion git.version

def version(versioninfo=False):
    '''
    .. versionadded:: 2015.8.0

    Returns the version of Git installed on the minion

    versioninfo : False
        If ``True``, return the version in a versioninfo list (e.g. ``[2, 5,
        0]``)

    CLI Example:

    .. code-block:: bash

        salt myminion git.version
    '''
    contextkey = 'git.version'
    contextkey_info = 'git.versioninfo'
    if contextkey not in __context__:
        try:
            version_ = _git_run(['git', '--version'])['stdout']
        except CommandExecutionError as exc:
            log.error(
                'Failed to obtain the git version (error follows):\n%s',
                exc
            )
            version_ = 'unknown'
        try:
            __context__[contextkey] = version_.split()[-1]
        except IndexError:
            # Somehow git --version returned no stdout while not raising an
            # error. Should never happen but we should still account for this
            # possible edge case.
            log.error('Running \'git --version\' returned no stdout')
            __context__[contextkey] = 'unknown'
    if not versioninfo:
        return __context__[contextkey]
    if contextkey_info not in __context__:
        # Set ptr to the memory location of __context__[contextkey_info] to
        # prevent repeated dict lookups
        ptr = __context__.setdefault(contextkey_info, [])
        for part in __context__[contextkey].split('.'):
            try:
                ptr.append(int(part))
            except ValueError:
                ptr.append(part)
    return __context__[contextkey_info]