-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
svn.psm1
96 lines (91 loc) · 2.78 KB
/
svn.psm1
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
# takes one parameter and somehow notifies user; It could be email, growl message, output to file...
[scriptblock]$script:Notifier = {}
# todo: read output from xml
function Set-SvnNotifier {
param(
[Parameter(Mandatory=$true)][scriptblock]$notifier
)
$script:Notifier = $notifier
}
function Get-SvnInfo
{
param(
[Parameter(Mandatory=$true)][string]$dir
)
$info = svn info $dir
$ret = new-object PSObject
$info | % {
if ($_ -match '^Revision') { $ret | Add-Member NoteProperty Revision ($_ -replace 'Revision[\s:]*','') }
if ($_ -match '^Last Changed Author') { $ret | Add-Member NoteProperty Author ($_ -replace 'Last Changed Author[\s:]*','') }
if ($_ -match '^Last Changed Date') { $ret | Add-Member NoteProperty Date ($_ -replace 'Last Changed Date[\s:]*','') }
}
$ret
}
function Update-Svn
{
param(
[Parameter(Mandatory=$true)][string]$dir,
[switch]$gui,
[switch]$Wait
)
$info = Get-SvnInfo $dir
if ($gui) {
Start-Process TortoiseProc.exe -Argument "/command:update", "/path:`"$dir`"" -wait:$wait
} else {
svn update $dir |
% {
$m = $_
switch -regex ($m) {
'^(Updated to|At revision)' { write-host $m }
'^\s*U\s' { write-host $m -fore Yellow }
'^\s*A\s' { write-host $m -fore Green }
'^\s*D\s' { write-host $m -fore Red }
'^\s*G\s' { write-host $m -fore DarkCyan }
default { write-host $m -fore Magenta }
}
}
& $Notifier 'updated from SVN'
}
$info2 = Get-SvnInfo $dir
if ($info.Revision -ne $info2.Revision) {
#Write-Host ("State before: {0} - {1} - {2}" -f $info.Revision, $info.Author, $info.Date) -fore Green
#Write-Host ("State after: {0} - {1} - {2}" -f $info2.Revision, $info2.Author, $info2.Date) -fore Green
Get-SvnLogInfos -dir $dir -maxCount ($info2.Revision - $info.Revision) | % {
write-host $_.Header-fore Green
$_.Info | % { write-host " $_" }
}
}
# more colors:
#"Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White" -split ', '|% { write-host $_ -fore $_ }
}
function Commit-Svn
{
param(
[Parameter(Mandatory=$true)][string]$dir,
[switch]$Wait
)
Start-Process TortoiseProc.exe -Argument "/command:commit", "/path:`"$dir`"" -wait:$wait
}
function Get-SvnLogInfos
{
param(
[Parameter(Mandatory=$true)][string]$dir,
[Parameter(Mandatory=$false)][int]$maxCount=1
)
$ret = @()
svn log $dir -l $maxCount | % {
$line = $_
switch -regex ($_) {
'^(-*|\s*)$' { return }
'^r\d+\s*\|\s*[\w\.]+\s\|' {
if ($header -ne $null) { $ret += $header }
$header = new-object PSObject -property @{Header = $line; Info = @() }
}
default {
$header.Info += $line
}
}
}
if ($header -ne $null) { $ret += $header }
$ret
}