Private/Invoke-CCGit.ps1

function Invoke-CCGit {
    <#
    .SYNOPSIS
        Runs git in a repository and returns whether it succeeded, with its output.
    .NOTES
        A failure is returned, not thrown, so that the caller can say what to do about it. The
        arguments are one array because PowerShell would otherwise swallow a bare '--'.

        Output is everything git wrote, for a message. Answer is what it wrote to standard
        output alone, for a caller that reads a commit or a name: a warning is not an answer.
    #>

    param(
        [Parameter(Mandatory)][string]$Path,
        [Parameter(Mandatory)][string[]]$Arguments
    )

    $output = @(& git -C $Path @Arguments 2>&1)
    [pscustomobject]@{
        Ok     = ($LASTEXITCODE -eq 0)
        Output = ($output -join "`n").Trim()
        Answer = (@($output | Where-Object { $_ -isnot [System.Management.Automation.ErrorRecord] }) -join "`n").Trim()
    }
}