Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Detect when the current branch has multiple heads and indicate by cha…
Browse files Browse the repository at this point in the history
…nging the colour of the branch name. Helpful when knowing when a merge is neccessary.
  • Loading branch information
petemill committed Aug 13, 2012
1 parent 1220e52 commit 4908296
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions HgPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ function Write-HgStatus($status = (get-hgStatus $global:PoshHgSettings.GetFileSt
$branchFg = $s.Branch2ForegroundColor
$branchBg = $s.Branch2BackgroundColor
}

if ($status.MultipleHeads) {
$branchFg = $s.Branch3ForegroundColor
$branchBg = $s.Branch3BackgroundColor
}

Write-Host $s.BeforeText -NoNewline -BackgroundColor $s.BeforeBackgroundColor -ForegroundColor $s.BeforeForegroundColor
Write-Host $status.Branch -NoNewline -BackgroundColor $branchBg -ForegroundColor $branchFg
Expand Down
13 changes: 10 additions & 3 deletions HgUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
$tags = @()
$commit = ""
$behind = $false

$multipleHeads = $false
if ($getFileStatus -eq $false) {
hg parent | foreach {
switch -regex ($_) {
Expand All @@ -45,9 +45,15 @@ function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
}
$branch = hg branch
$behind = $true
$headCount = 0
hg heads $branch | foreach {
switch -regex ($_) {
'changeset:\s*(\S*)' { if ($commit -eq $matches[1]) { $behind=$false } }
'changeset:\s*(\S*)'
{
if ($commit -eq $matches[1]) { $behind=$false }
$headCount++
if ($headCount -gt 1) { $multipleHeads=$true }
}
}
}
}
Expand Down Expand Up @@ -95,6 +101,7 @@ function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
"Tags" = $tags;
"Commit" = $commit;
"Behind" = $behind;
"MultipleHeads" = $multipleHeads;
"ActiveBookmark" = $active;
"Branch" = $branch}
}
Expand Down
3 changes: 3 additions & 0 deletions Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ $global:PoshHgSettings = New-Object PSObject -Property @{
# Current branch when not updated
Branch2ForegroundColor = [ConsoleColor]::Red
Branch2BackgroundColor = $host.UI.RawUI.BackgroundColor
# Current branch when there are multiple heads
Branch3ForegroundColor = [ConsoleColor]::Magenta
Branch3BackgroundColor = $host.UI.RawUI.BackgroundColor

# Working directory status
AddedForegroundColor = [ConsoleColor]::Green
Expand Down

0 comments on commit 4908296

Please sign in to comment.