Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- git clone https://myrepo c:repo 2>&1
- git clone https://myrepo c:repo 2>$null
- <#
- .Synopsis
- Invoke git, handling its quirky stderr that isn't error
- .Outputs
- Git messages, and lastly the exit code
- .Example
- Invoke-Git push
- .Example
- Invoke-Git "add ."
- #>
- function Invoke-Git
- {
- param(
- [Parameter(Mandatory)]
- [string] $Command )
- try {
- $exit = 0
- $path = [System.IO.Path]::GetTempFileName()
- Invoke-Expression "git $Command 2> $path"
- $exit = $LASTEXITCODE
- if ( $exit -gt 0 )
- {
- Write-Error (Get-Content $path).ToString()
- }
- else
- {
- Get-Content $path | Select-Object -First 1
- }
- $exit
- }
- catch
- {
- Write-Host "Error: $_`n$($_.ScriptStackTrace)"
- }
- finally
- {
- if ( Test-Path $path )
- {
- Remove-Item $path
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement