forked from JeremySkinner/posh-svn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SvnUtils.ps1
80 lines (67 loc) · 1.78 KB
/
SvnUtils.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
function isSvnDirectory() {
return (test-path ".svn")
}
function Get-SvnStatus {
if(IsSvnDirectory) {
$untracked = 0
$added = 0
$modified = 0
$deleted = 0
$missing = 0
$conflicted = 0
$branch = Get-SvnBranch
svn status | foreach {
$char = $_[0]
switch($char) {
'A' { $added++ }
'C' { $conflicted++ }
'D' { $deleted++ }
'M' { $modified++ }
'R' { $modified++ }
'?' { $untracked++ }
'!' { $missing++ }
}
}
return @{"Untracked" = $untracked;
"Added" = $added;
"Modified" = $modified;
"Deleted" = $deleted;
"Missing" = $missing;
"Conflicted" = $conflicted;
"Branch" = $branch}
}
}
function Get-SvnBranch {
if(IsSvnDirectory) {
$info = svn info
$url = $info[1].Replace("URL: ", "") #URL: svn://server/repo/trunk/test
$root = $info[2].Replace("Repository Root: ", "") #Repository Root: svn://server/repo
$path = $url.Replace($root, "")
$pathBits = $path.Split("/", [StringSplitOptions]::RemoveEmptyEntries)
if($pathBits[0] -eq "trunk") {
return "trunk";
}
if($pathBits[0] -match "branches|tags") {
return $pathBits[1]
}
}
}
function tsvn {
if($args) {
if($args[0] -eq "help") {
#I don't like the built in help behaviour!
$tsvnCommands.keys | sort | % { write-host $_ }
return
}
$newArgs = @()
$newArgs += "/command:" + $args[0]
$cmd = $tsvnCommands[$args[0]]
if($cmd -and $cmd.useCurrentDirectory) {
$newArgs += "/path:."
}
if($args.length -gt 1) {
$args[1..$args.length] | % { $newArgs += $_ }
}
tortoiseproc $newArgs
}
}