PowerShell ISE throws an error on git checkout

后端 未结 4 498
梦毁少年i
梦毁少年i 2020-12-06 17:14

In PowerShell, git checkout runs without any error message. In the ISE, while git checkout stills works, the ISE gives an error message.

         


        
4条回答
  •  时光说笑
    2020-12-06 17:55

    A profile ready Function-ized version of @BartekB's excellent answer...

    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
            )
            C:\Full\Path\To\git.exe $InnerArgs
        } -ErrorAction SilentlyContinue -ErrorVariable fail @Arguments
    
        if ($fail) {
            $fail.Exception
        }
    
    }
    
    # Could shorten the function name. I instead alias it, for terseness.
    Set-Alias -Name git -Value Invoke-Git
    
    # Also alias the name with the extension, as it is called by some applications this way.
    Set-Alias -Name git.exe -Value Invoke-Git
    

提交回复
热议问题