Private/Invoke-GhostGit.ps1

function Invoke-GhostGit {
    <#
    .SYNOPSIS
        Runs a git command and fails when the command fails.

    .DESCRIPTION
        git is run as it is set up on this machine, so it signs in to a private repository the way it does for
        any other clone. What the command writes is passed on as information, line by line.

    .EXAMPLE
        Invoke-GhostGit -Arguments 'clone', $address, $folder

        Clones the repository into the folder.
    #>

    [CmdletBinding()]
    [OutputType([void])]
    param(
        # The command and its options, such as 'clone', $address, $folder.
        [Parameter(Mandatory)]
        [string[]] $Arguments
    )

    # git reports its progress on the error stream, which is not a failure.
    $ErrorActionPreference = 'Continue'
    & git @Arguments 2>&1 | ForEach-Object { Write-Information -MessageData " $_" }

    if ($LASTEXITCODE -ne 0) {
        # Without the address: it can hold a password.
        throw "git $($Arguments[0]) failed with exit code $LASTEXITCODE. See what it wrote above."
    }
}