Skip to content

Instantly share code, notes, and snippets.

@WimObiwan
Created April 13, 2017 09:51
Show Gist options
  • Save WimObiwan/df5b7fe18f57374cdc34653f2065a84b to your computer and use it in GitHub Desktop.
Save WimObiwan/df5b7fe18f57374cdc34653f2065a84b to your computer and use it in GitHub Desktop.
# Based on http://stackoverflow.com/a/38381054/5247022
function Invoke-Git {
<#
.Synopsis
Wrapper function that deals with Powershell's peculiar error output when Git uses the error stream.
.Example
Invoke-Git ThrowError
$LASTEXITCODE
#>
[CmdletBinding()]
param(
[parameter(ValueFromRemainingArguments=$true)]
[string[]]$Arguments
)
& {
[CmdletBinding()]
param(
[parameter(ValueFromRemainingArguments=$true)]
[string[]]$InnerArgs
)
git.exe $InnerArgs
} -ErrorAction SilentlyContinue -ErrorVariable fail @Arguments
$resultcode = $LASTEXITCODE
if ($fail) {
$fail.Exception
}
if ($resultcode -ne 0) {
Write-Error "Git.exe failed with exitcode $resultcode"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment