-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhgutils.ps1
95 lines (82 loc) · 2.4 KB
/
hgutils.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Mercurial (hg) functions
# Rainer Schuster (http://github.com/schuster-rainer/posh-spice)
# Adopted from HG version of:
# Kornelije Sajler (http://learnaholic.me)
# Adopted from Git version of:
# Mark Embling (http://www.markembling.info/view/my-ideal-powershell-prompt-with-git-integration)
function isCurrentDirectoryMercurialRepository {
if ((Test-Path ".hg") -eq $TRUE) {
return $TRUE
}
# Test within parent dirs
$checkIn = (Get-Item .).parent
while ($checkIn -ne $NULL) {
$pathToTest = $checkIn.fullname + '/.hg'
if ((Test-Path $pathToTest) -eq $TRUE) {
return $TRUE
} else {
$checkIn = $checkIn.parent
}
}
return $FALSE
}
# Get the current branch
function Get-MercurialBranch {
$currentBranch = ''
hg branch | foreach {
$currentBranch += $_
}
# Write-Host($currentBranch)
return $currentBranch
}
# Extracts status details about the repo
function Get-MercurialStatus {
$untracked = 0
$added = 0
$modified = 0
$deleted = 0
$missing = 0
$output = hg status
#$branchbits = $output[0].Split(' ')
#$branch = $branchbits[$branchbits.length - 1]
# Write-Host($output)
$output | foreach {
if ($_ -match "^R") {
$deleted += 1
}
elseif ($_ -match "^M") {
$modified += 1
}
elseif ($_ -match "^A") {
$added += 1
}
elseif ($_ -match "^\!") {
$missing += 1
}
elseif ($_ -match "^\?") {
$untracked += 1
}
}
return @{"untracked" = $untracked;
"added" = $added;
"modified" = $modified;
"deleted" = $deleted;
"missing" = $missing}
}
function generic-scm {
$scm = $null
@("HG","SVN") | foreach {
Write-Host $_
if(Test-RepositoryType $_ ) {
Write-ScmPrompt $_ (get-RepositoryBranch) (get-RepositoryStatus)
#Write-ScmPrompt "GIT" (get-GitBranch) (get-GitStatus)
$scm = $_
break
}
}
if( $scm -eq $null) {
Write-Host $(get-location) -foregroundcolor green
Write-Host ("PS " + $status_string + ">") `
-nonewline -foregroundcolor green
}
}