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

Added Get-HasIncoming command #26

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dad5c85
added Get-HasIncoming command
FelicePollano Jan 8, 2014
f151de7
added command Get-HasIncoming
FelicePollano Jan 8, 2014
391ad6d
fixed error in Get-HasIncoming
FelicePollano Jan 8, 2014
ee4598e
used regex match
FelicePollano Jan 9, 2014
8fc85a9
tidy
FelicePollano Jan 9, 2014
b11cbff
tidy
FelicePollano Jan 9, 2014
96934b1
preserve $lastexit code
maxslimmer Nov 6, 2014
cc8ee50
Merge pull request #30 from maxslimmer/patch-1
JeremySkinner Nov 6, 2014
3053e18
Avoid populating $error on module load
JeremySkinner Feb 9, 2015
489d71b
Use ProviderPath in prompt
JeremySkinner Feb 10, 2015
584fbc7
Added the HG revison information to the prompt in the format "<{rev}:…
Mar 20, 2015
8d6f3c1
Merge pull request #33 from raleighbuckner/master
JeremySkinner Mar 25, 2015
833d792
Updated the README to include info about the added revision information.
Mar 25, 2015
79f1827
Merge pull request #34 from raleighbuckner/master
JeremySkinner Mar 25, 2015
44ad3ed
Make tab expansion case-insensitive for branches, tags and bookmarks
woodyza Apr 7, 2015
0b86b0d
added ShowRevision setting for extra prompt config
jordanmorris Apr 9, 2015
9955cab
Merge pull request #36 from jordanmorris/show-revision-optional
JeremySkinner Apr 10, 2015
e273b0d
Merge pull request #35 from woodyza/master
JeremySkinner Apr 10, 2015
8fe8c9e
Update README.md
JeremySkinner Feb 27, 2018
81d33f9
default to show mq patch,only currently applied
FelicePollano Mar 28, 2023
b0b8146
Merge branch 'master' of https://github.com/FelicePollano/posh-hg
FelicePollano Mar 28, 2023
b69f52e
single char as patch prefix
FelicePollano Mar 28, 2023
43ab73d
Update README.md
FelicePollano Mar 28, 2023
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: 13 additions & 6 deletions HgPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Write-HgStatus($status = (get-hgStatus $global:PoshHgSettings.GetFileSt
$tagCounter++;
}
}

if($s.ShowPatches) {
$patches = Get-MqPatches
if($patches.All.Length) {
Expand All @@ -88,25 +88,32 @@ function Write-HgStatus($status = (get-hgStatus $global:PoshHgSettings.GetFileSt
}
$patchCounter++;
}

<#
$patches.Unapplied | % {
Write-Prompt $_ -ForegroundColor $s.UnappliedPatchForegroundColor -BackgroundColor $s.UnappliedPatchBackgroundColor
if($patchCounter -lt ($patches.All.Length -1)) {
Write-Prompt $s.PatchSeparator -ForegroundColor $s.PatchSeparatorColor
}
$patchCounter++;
}
}#>
}
}

if($s.ShowRevision -and $status.Revision) {
Write-Prompt " <" -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor
Write-Prompt $status.Revision -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor
Write-Prompt ">" -BackgroundColor $s.TagBackgroundColor -ForegroundColor $s.TagForegroundColor
}


Write-Prompt $s.AfterText -BackgroundColor $s.AfterBackgroundColor -ForegroundColor $s.AfterForegroundColor
}
}

# Should match https://github.com/dahlbyk/posh-git/blob/master/GitPrompt.ps1
if((Get-Variable -Scope Global -Name VcsPromptStatuses -ErrorAction SilentlyContinue) -eq $null) {
$Global:VcsPromptStatuses = @()
}
if(!(Test-Path Variable:Global:VcsPromptStatuses)) {
$Global:VcsPromptStatuses = @()
}
function Global:Write-VcsStatus { $Global:VcsPromptStatuses | foreach { & $_ } }

# Add scriptblock that will execute for Write-VcsStatus
Expand Down
10 changes: 5 additions & 5 deletions HgTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function findBranchOrBookmarkOrTags($filter){
function hgLocalBranches($filter) {
hg branches -a | foreach {
if($_ -match "(\S+) .*") {
if($filter -and $matches[1].StartsWith($filter)) {
if($filter -and $matches[1].StartsWith($filter, "CurrentCultureIgnoreCase")) {
$matches[1]
}
elseif(-not $filter) {
Expand All @@ -170,7 +170,7 @@ function hgLocalBranches($filter) {
function hgLocalTags($filter) {
hg tags | foreach {
if($_ -match "(\S+) .*") {
if($filter -and $matches[1].StartsWith($filter)) {
if($filter -and $matches[1].StartsWith($filter, "CurrentCultureIgnoreCase")) {
$matches[1]
}
elseif(-not $filter) {
Expand All @@ -195,7 +195,7 @@ function hgLocalBookmarks($filter) {
hg bookmarks --quiet | foreach {
if($_ -match "(\S+) .*") {
$bookmark = bookmarkName($matches[0])
if($filter -and $bookmark.StartsWith($filter)) {
if($filter -and $bookmark.StartsWith($filter, "CurrentCultureIgnoreCase")) {
$bookmark
}
elseif(-not $filter) {
Expand All @@ -208,7 +208,7 @@ function hgLocalBookmarks($filter) {
function hgRemoteBookmarks($filter) {
hg incoming -B | foreach {
if($_ -match "(\S+) .*") {
if($filter -and $matches[1].StartsWith($filter)) {
if($filter -and $matches[1].StartsWith($filter, "CurrentCultureIgnoreCase")) {
$matches[1]
}
elseif(-not $filter) {
Expand Down Expand Up @@ -298,7 +298,7 @@ function populatehgflowStreams($filename) {
$script:hgflowStreams = if ($ini["Basic"]) { $ini["Basic"] } else { $ini["branchname"] }
}

$PowerTab_RegisterTabExpansion = Get-Command Register-TabExpansion -Module powertab -ErrorAction SilentlyContinue
$PowerTab_RegisterTabExpansion = if (Get-Module -Name powertab) { Get-Command Register-TabExpansion -Module powertab -ErrorAction SilentlyContinue }
if ($PowerTab_RegisterTabExpansion)
{
& $PowerTab_RegisterTabExpansion "hg.exe" -Type Command {
Expand Down
22 changes: 20 additions & 2 deletions HgUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ function isHgDirectory() {
return $false
}

function Get-HasIncoming() {
$has=$false;
if(isHgDirectory) {
$has=$true
hg incoming --insecure | foreach {
if($_ -match 'no changes found'){
$has=$false
}
}
}
return $has;
}

function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
if(isHgDirectory) {
$untracked = 0
Expand All @@ -35,7 +48,8 @@ function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
$commit = ""
$behind = $false
$multipleHeads = $false

$rev = ""

if ($getFileStatus -eq $false) {
hg parent | foreach {
switch -regex ($_) {
Expand Down Expand Up @@ -92,6 +106,9 @@ function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
}
}
}

$rev = hg log -r . --template '{rev}:{node|short}'

return @{"Untracked" = $untracked;
"Added" = $added;
"Modified" = $modified;
Expand All @@ -103,7 +120,8 @@ function Get-HgStatus($getFileStatus=$true, $getBookmarkStatus=$true) {
"Behind" = $behind;
"MultipleHeads" = $multipleHeads;
"ActiveBookmark" = $active;
"Branch" = $branch}
"Branch" = $branch
"Revision" = $rev}
}
}

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
posh-hg
========

This version default to showing mq applied patch with ':' after the branch name. It does not show unapplied ones.

Inspired by the Posh-Git project (http://github.com/dahlbyk/posh-git), Posh-Hg provides a set of PowerShell scripts which provide Mercurial/PowerShell integration

### Prompt for Hg repositories
Expand Down Expand Up @@ -40,23 +42,24 @@ PowerShell generates its prompt by executing a `prompt` function, if one exists.

By default, the status summary has the following format:

[{HEAD-name} +A ~B -C ?D !E ^F]
[{HEAD-name} +A ~B -C ?D !E ^F <G:H>]

* `{HEAD-name}` is the current branch, or the SHA of a detached HEAD
* Cyan means the branch matches its remote
* Red means the branch is behind its remote
* ABCDEF represent the working directory
* ABCDEFGH represent the working directory
* `+` = Added files
* `~` = Modified files
* `-` = Removed files
* `?` = Untracked files
* `!` = Missing files
* `^` = Renamed files
* `<G:H>` = Current revision information matching the output of `hg log -r . --template '{rev}:{node|short}'`

Additionally, Posh-Hg can show any tags and bookmarks in the prompt as well as MQ patches if the MQ extension is enabled (disabled by default)

### Based on work by:

- Jeremy Skinner, http://www.jeremyskinner.co.uk/
- Keith Dahlby, http://solutionizing.net/
- Mark Embling, http://www.markembling.info/
- Mark Embling, http://www.markembling.info/
11 changes: 7 additions & 4 deletions Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ $global:PoshHgSettings = New-Object PSObject -Property @{
TagSeparatorColor = [ConsoleColor]::White

# MQ Integration
ShowPatches = $false
BeforePatchText = ' patches: '
ShowPatches = $true
BeforePatchText = ':'
UnappliedPatchForegroundColor = [ConsoleColor]::DarkGray
UnappliedPatchBackgroundColor = $Host.UI.RawUI.BackgroundColor
AppliedPatchForegroundColor = [ConsoleColor]::DarkYellow
AppliedPatchBackgroundColor = $Host.UI.RawUI.BackgroundColor
PatchSeparator = ''
PatchSeparator = '|'
PatchSeparatorColor = [ConsoleColor]::White

# Current revision
ShowRevision = $true

# Status Count Prefixes for prompt
AddedStatusPrefix = ' +'
Expand All @@ -62,4 +65,4 @@ $global:PoshHgSettings = New-Object PSObject -Property @{
UntrackedStatusPrefix = ' ?'
MissingStatusPrefix = ' !'
RenamedStatusPrefix = ' ^'
}
}
1 change: 1 addition & 0 deletions posh-hg.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Push-Location $psScriptRoot
Pop-Location

Export-ModuleMember -Function @(
'Get-HasIncoming',
'Get-HgStatus',
'TabExpansion',
'Get-MqPatches',
Expand Down
5 changes: 3 additions & 2 deletions profile.example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ Import-Module .\posh-hg

# Set up a simple prompt, adding the hg prompt parts inside hg repos
function prompt {
Write-Host($pwd) -nonewline
$realLASTEXITCODE = $LASTEXITCODE
Write-Host($pwd.ProviderPath) -nonewline

Write-VcsStatus
$global:LASTEXITCODE = $realLASTEXITCODE
return "> "
}

Expand Down