This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
/
Svn.php
147 lines (128 loc) · 3.26 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
* This file is part of Rocketeer
*
* (c) Maxime Fabre <ehtnam6@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Rocketeer\Binaries\Vcs;
use Rocketeer\Binaries\AbstractBinary;
/**
* The Svn implementation of the VcsInterface.
*
*
* @author Gasillo
*/
class Svn extends AbstractBinary implements VcsInterface
{
/**
* The core binary.
*
* @var string
*/
public $binary = 'svn';
////////////////////////////////////////////////////////////////////
///////////////////////////// INFORMATIONS /////////////////////////
////////////////////////////////////////////////////////////////////
/**
* Check if the VCS is available.
*
* @return string
*/
public function check()
{
return $this->getCommand('--version');
}
/**
* Get the current state.
*
* @return string
*/
public function currentState()
{
return $this->getCommand('info | grep "Revision"');
}
/**
* @return string
*/
public function currentEndpoint()
{
return $this->getCommand("info | grep '^URL' | awk '{print \$NF}'");
}
/**
* Get the current branch.
*
* @return string
*/
public function currentBranch()
{
return 'echo trunk';
}
////////////////////////////////////////////////////////////////////
/////////////////////////////// ACTIONS ////////////////////////////
////////////////////////////////////////////////////////////////////
/**
* Clone a repository.
*
* @param string $destination
*
* @return string
*/
public function checkout($destination)
{
$repository = $this->credentials->getCurrentRepository();
$branch = $repository->branch;
$repository = $repository->repository;
$repository = rtrim($repository, '/').'/'.ltrim($branch, '/');
$repository = preg_replace('#//[a-zA-Z0-9.]+:?[a-zA-Z0-9]*@#', '//', $repository);
return $this->co([$repository, $destination], $this->getCredentials());
}
/**
* Resets the repository.
*
* @return string
*/
public function reset()
{
$command = sprintf('status -q | grep -v \'^[~XI ]\' | awk \'{print $2;}\' | xargs --no-run-if-empty %s revert', $this->binary);
return $this->getCommand($command);
}
/**
* Updates the repository.
*
* @return string
*/
public function update()
{
return $this->up([], $this->getCredentials());
}
/**
* Return credential options.
*
* @return array|array<string,null>
*/
protected function getCredentials()
{
$options = ['--non-interactive' => null];
$repository = $this->credentials->getCurrentRepository();
// Build command
if ($user = $repository->username) {
$options['--username'] = $user;
}
if ($pass = $repository->password) {
$options['--password'] = $pass;
}
return $options;
}
/**
* Checkout the repository's submodules.
*
* @return string|null
*/
public function submodules()
{
}
}