Skip to content

Commit

Permalink
Merge pull request #453 from dahlbyk/prompt-error
Browse files Browse the repository at this point in the history
Handle Get/Write-GitStatus Errors
  • Loading branch information
dahlbyk authored Mar 12, 2017
2 parents c5447d6 + a134285 commit 99c1fc5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ $global:GitPromptSettings = [pscustomobject]@{
StashBackgroundColor = $null
StashForegroundColor = [ConsoleColor]::Red

ErrorForegroundColor = [ConsoleColor]::Red
ErrorBackgroundColor = $null

ShowStatusWhenZero = $true

AutoRefreshIndex = $true
Expand Down Expand Up @@ -327,8 +330,18 @@ function Global:Write-VcsStatus {

# Add scriptblock that will execute for Write-VcsStatus
$PoshGitVcsPrompt = {
$Global:GitStatus = Get-GitStatus
Write-GitStatus $GitStatus
try {
$Global:GitStatus = Get-GitStatus
Write-GitStatus $GitStatus
}
catch {
$s = $Global:GitPromptSettings
if ($s) {
Write-Prompt $s.BeforeText -BackgroundColor $s.BeforeBackgroundColor -ForegroundColor $s.BeforeForegroundColor
Write-Prompt "Error: $_" -BackgroundColor $s.ErrorBackgroundColor -ForegroundColor $s.ErrorForegroundColor
Write-Prompt $s.AfterText -BackgroundColor $s.AfterBackgroundColor -ForegroundColor $s.AfterForegroundColor
}
}
}

$Global:VcsPromptStatuses += $PoshGitVcsPrompt

0 comments on commit 99c1fc5

Please sign in to comment.