Permalink
Browse files

Convert Get-GitStatus to use 'git branch --short --branch', new in 1.7.1

  • Loading branch information...
1 parent 223c61a commit f3a8ab8f0542a19ba418c1b98be4754d498f5848 @dahlbyk committed Jul 28, 2010
Showing with 34 additions and 0 deletions.
  1. +34 −0 GitUtils.ps1
View
@@ -62,6 +62,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
{
$branch = ''
$aheadBy = 0
+ $behindBy = 0
$indexAdded = @()
$indexModified = @()
$indexDeleted = @()
@@ -71,6 +72,36 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
$filesDeleted = @()
$filesUnmerged = @()
+ $status = git status --short --branch 2>$null
+ $status | where { $_ } | foreach {
+ switch -regex ($_) {
+ '^## (?<branch>\S+)(?:\.\.\.(?<upstream>\S+) \[(?:ahead (?<ahead>\d+))?(?:, )?(?:behind (?<behind>\d+))?\])?$' {
+ $branch = $matches['branch']
+ $upstream = $matches['upstream']
+ $aheadBy = [int]$matches['ahead']
+ $behindBy = [int]$matches['behind']
+ }
+
+ '^(?<index>[^#])(?<working>.) (?<path1>.*?)(?: -> (?<path2>.*))?$' {
+ switch ($matches['index']) {
+ 'A' { $indexAdded += $matches['path1'] }
+ 'M' { $indexModified += $matches['path1'] }
+ 'R' { $indexModified += $matches['path1'] }
+ 'C' { $indexModified += $matches['path1'] }
+ 'D' { $indexDeleted += $matches['path1'] }
+ 'U' { $indexUnmerged += $matches['path1'] }
+ }
+ switch ($matches['working']) {
+ '?' { $filesAdded += $matches['path1'] }
+ 'A' { $filesAdded += $matches['path1'] }
+ 'M' { $filesModified += $matches['path1'] }
+ 'D' { $filesDeleted += $matches['path1'] }
+ 'U' { $filesUnmerged += $matches['path1'] }
+ }
+ }
+ }
+ }
+<#
if ($global:GitPromptSettings.AutoRefreshIndex) {
git update-index -q --refresh >$null 2>$null
}
@@ -100,6 +131,9 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
$indexPaths = @($diffIndex | %{ $_.Path })
$workingPaths = @($diffFiles | %{ $_.Path }) + $filesAdded
+#>
+ $indexPaths = $indexAdded + $indexModified + $indexDeleted + $indexUnmerged
+ $workingPaths = $filesAdded + $filesModified + $filesDeleted + $filesUnmerged
$index = New-Object PSObject @(,@($indexPaths | ?{ $_ } | Select -Unique)) |
Add-Member -PassThru NoteProperty Added $indexAdded |
Add-Member -PassThru NoteProperty Modified $indexModified |

0 comments on commit f3a8ab8

Please sign in to comment.