Skip to content

Commit

Permalink
Merge pull request #326 from dahlbyk/upstream-gone
Browse files Browse the repository at this point in the history
Upstream Gone
  • Loading branch information
dahlbyk authored Dec 30, 2016
2 parents 3299116 + a32d1a5 commit 2d436bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
19 changes: 14 additions & 5 deletions GitPrompt.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Inspired by Mark Embling
# Inspired by Mark Embling
# http://www.markembling.info/view/my-ideal-powershell-prompt-with-git-integration

$global:GitPromptSettings = New-Object PSObject -Property @{
Expand Down Expand Up @@ -39,19 +39,23 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
BranchForegroundColor = [ConsoleColor]::Cyan
BranchBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchIdenticalStatusToSymbol = [char]0x2261 # Three horizontal lines
BranchGoneStatusSymbol = [char]0x00D7 # × Multiplication sign
BranchGoneStatusForegroundColor = [ConsoleColor]::DarkCyan
BranchGoneStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchIdenticalStatusToSymbol = [char]0x2261 # ≡ Three horizontal lines
BranchIdenticalStatusToForegroundColor = [ConsoleColor]::Cyan
BranchIdenticalStatusToBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchAheadStatusSymbol = [char]0x2191 # Up arrow
BranchAheadStatusSymbol = [char]0x2191 # Up arrow
BranchAheadStatusForegroundColor = [ConsoleColor]::Green
BranchAheadStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchBehindStatusSymbol = [char]0x2193 # Down arrow
BranchBehindStatusSymbol = [char]0x2193 # Down arrow
BranchBehindStatusForegroundColor = [ConsoleColor]::Red
BranchBehindStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

BranchBehindAndAheadStatusSymbol = [char]0x2195 # Up & Down arrow
BranchBehindAndAheadStatusSymbol = [char]0x2195 # Up & Down arrow
BranchBehindAndAheadStatusForegroundColor = [ConsoleColor]::Yellow
BranchBehindAndAheadStatusBackgroundColor = $Host.UI.RawUI.BackgroundColor

Expand Down Expand Up @@ -143,6 +147,11 @@ function Write-GitStatus($status) {

if (!$status.Upstream) {
$branchStatusSymbol = $s.BranchUntrackedSymbol
} elseif ($status.UpstreamGone -eq $true) {
# Upstream branch is gone
$branchStatusSymbol = $s.BranchGoneStatusSymbol
$branchStatusBackgroundColor = $s.BranchGoneStatusBackgroundColor
$branchStatusForegroundColor = $s.BranchGoneStatusForegroundColor
} elseif ($status.BehindBy -eq 0 -and $status.AheadBy -eq 0) {
# We are aligned with remote
$branchStatusSymbol = $s.BranchIdenticalStatusToSymbol
Expand Down
5 changes: 4 additions & 1 deletion GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
$branch = $null
$aheadBy = 0
$behindBy = 0
$gone = $false
$indexAdded = New-Object System.Collections.Generic.List[string]
$indexModified = New-Object System.Collections.Generic.List[string]
$indexDeleted = New-Object System.Collections.Generic.List[string]
Expand Down Expand Up @@ -177,13 +178,14 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
continue
}

'^## (?<branch>\S+?)(?:\.\.\.(?<upstream>\S+))?(?: \[(?:ahead (?<ahead>\d+))?(?:, )?(?:behind (?<behind>\d+))?\])?$' {
'^## (?<branch>\S+?)(?:\.\.\.(?<upstream>\S+))?(?: \[(?:ahead (?<ahead>\d+))?(?:, )?(?:behind (?<behind>\d+))?(?<gone>gone)?\])?$' {
if ($sw) { dbg "Status: $_" $sw }

$branch = $matches['branch']
$upstream = $matches['upstream']
$aheadBy = [int]$matches['ahead']
$behindBy = [int]$matches['behind']
$gone = [string]$matches['gone'] -eq 'gone'
continue
}

Expand Down Expand Up @@ -240,6 +242,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
Branch = $branch
AheadBy = $aheadBy
BehindBy = $behindBy
UpstreamGone = $gone
Upstream = $upstream
HasIndex = [bool]$index
Index = $index
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ By default, the status summary has the following format:
* Yellow means the branch is both ahead of and behind its remote
* S represents the branch status in relation to remote (tracked origin) branch. Note: This information reflects the state of the remote tracked branch after the last `git fetch/pull` of the remote.
* ≡ = The local branch in at the same commit level as the remote branch (`BranchIdenticalStatus`)
* ↑ = The local branch is ahead of the remote branch, a 'git push' is required to update the remote branch (`BranchAheadStatus`)
* ↓ = The local branch is behind the remote branch, a 'git pull' is required to update the local branch (`BranchBehindStatus`)
* ↕ = The local branch is both ahead and behind the remote branch, a rebase of the local branch is required before pushing local changes to the remote branch (`BranchBehindAndAheadStatus`)
* ↑ = The local branch is ahead of the remote branch; a 'git push' is required to update the remote branch (`BranchAheadStatus`)
* ↓ = The local branch is behind the remote branch; a 'git pull' is required to update the local branch (`BranchBehindStatus`)
* ↕ = The local branch is both ahead and behind the remote branch; a rebase of the local branch is required before pushing local changes to the remote branch (`BranchBehindAndAheadStatus`)
* × = The local branch is tracking a branch that is gone from the remote (`BranchGoneStatus')
* ABCD represent the index; ` | ` (`DelimText`); EFGH represent the working directory
* `+` = Added files
* `~` = Modified files
Expand Down

0 comments on commit 2d436bb

Please sign in to comment.