Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. git clone https://myrepo c:repo 2>&1
  2.  
  3. git clone https://myrepo c:repo 2>$null
  4.  
  5. <#
  6. .Synopsis
  7. Invoke git, handling its quirky stderr that isn't error
  8.  
  9. .Outputs
  10. Git messages, and lastly the exit code
  11.  
  12. .Example
  13. Invoke-Git push
  14.  
  15. .Example
  16. Invoke-Git "add ."
  17. #>
  18. function Invoke-Git
  19. {
  20. param(
  21. [Parameter(Mandatory)]
  22. [string] $Command )
  23.  
  24. try {
  25.  
  26. $exit = 0
  27. $path = [System.IO.Path]::GetTempFileName()
  28.  
  29. Invoke-Expression "git $Command 2> $path"
  30. $exit = $LASTEXITCODE
  31. if ( $exit -gt 0 )
  32. {
  33. Write-Error (Get-Content $path).ToString()
  34. }
  35. else
  36. {
  37. Get-Content $path | Select-Object -First 1
  38. }
  39. $exit
  40. }
  41. catch
  42. {
  43. Write-Host "Error: $_`n$($_.ScriptStackTrace)"
  44. }
  45. finally
  46. {
  47. if ( Test-Path $path )
  48. {
  49. Remove-Item $path
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement