def _handle_git_worktree_error(
        self, pack_name, pack_directory, content_version, exit_code, stdout, stderr
    ):
        """
        Handle "git worktree" related errors and throw a more user-friendly exception.
        """
        error_prefix = 'Failed to create git worktree for pack "%s": ' % (pack_name)

        if isinstance(stdout, six.binary_type):
            stdout = stdout.decode("utf-8")

        if isinstance(stderr, six.binary_type):
            stderr = stderr.decode("utf-8")

        # 1. Installed version of git which doesn't support worktree command
        if "git: 'worktree' is not a git command." in stderr:
            msg = (
                "Installed git version doesn't support git worktree command. "
                "To be able to utilize this functionality you need to use git "
                ">= 2.5.0."
            )
            raise ValueError(error_prefix + msg)

        # 2. Provided pack directory is not a git repository
        if "Not a git repository" in stderr:
            msg = (
                'Pack directory "%s" is not a git repository. To utilize this functionality, '
                "pack directory needs to be a git repository." % (pack_directory)
            )
            raise ValueError(error_prefix + msg)

        # 3. Invalid revision provided
        if "invalid reference" in stderr:
            msg = (
                'Invalid content_version "%s" provided. Make sure that git repository is up '
                "to date and contains that revision." % (content_version)
            )
            raise ValueError(error_prefix + msg)

        Handle "git worktree" related errors and throw a more user-friendly exception.
        
st2common/st2common/runners/base.py