Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream Gone #326

Merged
merged 3 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -224,6 +226,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 @@ -229,9 +229,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