forked from nlmayday/PhpLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Svn.php
121 lines (101 loc) · 2.85 KB
/
Svn.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
class Svn
{
private $username;
private $password;
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
public function info($path)
{
$cmd = "svn info $path --xml";
return new SimpleXMLElement(implode('', $this->run($cmd)));
}
public function log($path)
{
$cmd = "svn log $path --xml";
return new SimpleXMLElement(implode('', $this->run($cmd)));
}
public function diffPath($pathA, $pathB)
{
$cmd = "svn diff $pathA $pathB";
return implode(PHP_EOL, $this->run($cmd));
}
public function diffFile($path, $fromVersion, $toRevision = 'HEAD')
{
$cmd = "svn diff -r {$fromVersion}:{$toRevision} $path";
return implode(PHP_EOL, $this->run($cmd));
}
public function file_get_contents($path, $version = 'HEAD')
{
$cmd = "svn cat -r {$version} $path";
return implode(PHP_EOL, $this->run($cmd));
}
public function ls($path)
{
$cmd = "svn list $path";
return $this->run($cmd);
}
public function export($path, $dir, $version = 'HEAD')
{
$cmd = "svn export -r {$version} $path $dir";
return $this->run($cmd);
}
public function add($path)
{
$cmd = "svn add $path";
return $this->run($cmd);
}
public function copy($src, $dst, $comment)
{
$cmd = "svn copy $src $dst -m '$comment'";
return $this->run($cmd);
}
public function delete($path, $comment)
{
$cmd = "svn delete $path -m '$comment'";
return $this->run($cmd);
}
public function move($src, $dst, $comment)
{
$cmd = "svn move $src $dst -m '$comment'";
return $this->run($cmd);
}
public function mkdir($path, $comment)
{
$cmd = "svn mkdir $path -m '$comment'";
return $this->run($cmd);
}
public function checkout($path, $dir, $version = 'HEAD')
{
$cmd = "svn checkout -r {$version} $path $dir";
return $this->run($cmd);
}
public function merge($revision, $path, $dir)
{
$cmd = "svn merge -r1:$revision $path $dir";
return $this->run($cmd);
}
public function commit($dir, $comment)
{
$cmd = "svn commit $dir -m '$comment'";
return $this->run($cmd);
}
public function update($dir, $version = 'HEAD')
{
$cmd = "svn update -r {$version} $dir";
return $this->run($cmd);
}
public function status($dir)
{
$cmd = "svn status $dir";
return $this->run($cmd);
}
private function run($cmd, $pipe = "")
{
exec($cmd . ' --username ' . $this->username . ' --password ' . $this->password . ' --no-auth-cache --non-interactive 2>&1' . $pipe, $result);
return $result;
}
}