1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Rocketeer |
5
|
|
|
* |
6
|
|
|
* (c) Maxime Fabre <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Rocketeer\Binaries\Vcs; |
14
|
|
|
|
15
|
|
|
use Rocketeer\Binaries\AbstractBinary; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The Svn implementation of the VcsInterface. |
19
|
|
|
* |
20
|
|
|
* |
21
|
|
|
* @author Gasillo |
22
|
|
|
*/ |
23
|
|
|
class Svn extends AbstractBinary implements VcsInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The core binary. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
public $binary = 'svn'; |
31
|
|
|
|
32
|
|
|
//////////////////////////////////////////////////////////////////// |
33
|
|
|
///////////////////////////// INFORMATIONS ///////////////////////// |
34
|
|
|
//////////////////////////////////////////////////////////////////// |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Check if the VCS is available. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
1 |
|
public function check() |
42
|
|
|
{ |
43
|
1 |
|
return $this->getCommand('--version'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the current state. |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
1 |
|
public function currentState() |
52
|
|
|
{ |
53
|
1 |
|
return $this->getCommand('info | grep "Revision"'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function currentEndpoint() |
60
|
|
|
{ |
61
|
|
|
return $this->getCommand("info | grep '^URL' | awk '{print \$NF}'"); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the current branch. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
1 |
|
public function currentBranch() |
70
|
|
|
{ |
71
|
1 |
|
return 'echo trunk'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//////////////////////////////////////////////////////////////////// |
75
|
|
|
/////////////////////////////// ACTIONS //////////////////////////// |
76
|
|
|
//////////////////////////////////////////////////////////////////// |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Clone a repository. |
80
|
|
|
* |
81
|
|
|
* @param string $destination |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
5 |
|
public function checkout($destination) |
86
|
|
|
{ |
87
|
5 |
|
$repository = $this->credentials->getCurrentRepository(); |
88
|
5 |
|
$branch = $repository->branch; |
89
|
5 |
|
$repository = $repository->repository; |
90
|
5 |
|
$repository = rtrim($repository, '/').'/'.ltrim($branch, '/'); |
91
|
5 |
|
$repository = preg_replace('#//[a-zA-Z0-9.]+:?[a-zA-Z0-9]*@#', '//', $repository); |
92
|
|
|
|
93
|
5 |
|
return $this->co([$repository, $destination], $this->getCredentials()); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Resets the repository. |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
1 |
|
public function reset() |
102
|
|
|
{ |
103
|
1 |
|
$command = sprintf('status -q | grep -v \'^[~XI ]\' | awk \'{print $2;}\' | xargs --no-run-if-empty %s revert', $this->binary); |
104
|
|
|
|
105
|
1 |
|
return $this->getCommand($command); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Updates the repository. |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
1 |
|
public function update() |
114
|
|
|
{ |
115
|
1 |
|
return $this->up([], $this->getCredentials()); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Return credential options. |
120
|
|
|
* |
121
|
|
|
* @return array|array<string,null> |
122
|
|
|
*/ |
123
|
6 |
|
protected function getCredentials() |
124
|
|
|
{ |
125
|
6 |
|
$options = ['--non-interactive' => null]; |
126
|
6 |
|
$repository = $this->credentials->getCurrentRepository(); |
127
|
|
|
|
128
|
|
|
// Build command |
129
|
6 |
|
if ($user = $repository->username) { |
130
|
4 |
|
$options['--username'] = $user; |
131
|
4 |
|
} |
132
|
6 |
|
if ($pass = $repository->password) { |
133
|
4 |
|
$options['--password'] = $pass; |
134
|
4 |
|
} |
135
|
|
|
|
136
|
6 |
|
return $options; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Checkout the repository's submodules. |
141
|
|
|
* |
142
|
|
|
* @return string|null |
143
|
|
|
*/ |
144
|
2 |
|
public function submodules() |
145
|
|
|
{ |
146
|
2 |
|
} |
147
|
|
|
} |
148
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: