forked from JeremySkinner/posh-hg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHgUtils.ps1
107 lines (93 loc) · 2.63 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
96
97
98
99
100
101
102
103
104
105
106
107
function isHgDirectory() {
if(test-path ".hg") {
return $true;
}
if(test-path ".git") {
return $false; #short circuit if git repo
}
# 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
}
function Get-HgStatus {
if(isHgDirectory) {
$untracked = 0
$added = 0
$modified = 0
$deleted = 0
$missing = 0
$renamed = 0
$tags = @()
$commit = ""
$behind = $false
hg summary | foreach {
switch -regex ($_) {
'parent: (\S*) ?(.*)' { $commit = $matches[1]; $tags = $matches[2].Replace("(empty repository)", "").Split(" ", [StringSplitOptions]::RemoveEmptyEntries) }
'branch: (\S*)' { $branch = $matches[1] }
'update: (\d+)' { $behind = $true }
'pmerge: (\d+) pending' { $behind = $true }
'commit: (.*)' {
$matches[1].Split(",") | foreach {
switch -regex ($_.Trim()) {
'(\d+) modified' { $modified = $matches[1] }
'(\d+) added' { $added = $matches[1] }
'(\d+) removed' { $deleted = $matches[1] }
'(\d+) deleted' { $missing = $matches[1] }
'(\d+) unknown' { $untracked = $matches[1] }
'(\d+) renamed' { $renamed = $matches[1] }
}
}
}
}
}
$active = ""
hg bookmarks | ?{$_} | foreach {
if($_.Trim().StartsWith("*")) {
$split = $_.Split(" ");
$active= $split[2]
}
}
return @{"Untracked" = $untracked;
"Added" = $added;
"Modified" = $modified;
"Deleted" = $deleted;
"Missing" = $missing;
"Renamed" = $renamed;
"Tags" = $tags;
"Commit" = $commit;
"Behind" = $behind;
"ActiveBookmark" = $active;
"Branch" = $branch}
}
}
function Get-MqPatches($filter) {
$applied = @()
$unapplied = @()
hg qseries -v | % {
$bits = $_.Split(" ")
$status = $bits[1]
$name = $bits[2]
if($status -eq "A") {
$applied += $name
} else {
$unapplied += $name
}
}
$all = $unapplied + $applied
if($filter) {
$all = $all | ? { $_.StartsWith($filter) }
}
return @{
"All" = $all;
"Unapplied" = $unapplied;
"Applied" = $applied
}
}