1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Utilise Mercurial from within Phing. |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category Tasks |
8
|
|
|
* @package phing.tasks.ext |
9
|
|
|
* @author Ken Guest <[email protected]> |
10
|
|
|
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html) |
11
|
|
|
* @link https://github.com/kenguest/Phing-HG |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Integration/Wrapper for hg revert |
16
|
|
|
* |
17
|
|
|
* @category Tasks |
18
|
|
|
* @package phing.tasks.ext.hg |
19
|
|
|
* @author Ken Guest <[email protected]> |
20
|
|
|
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html) |
21
|
|
|
* @link HgRevertTask.php |
22
|
|
|
*/ |
23
|
|
|
class HgRevertTask extends HgBaseTask |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* All |
27
|
|
|
* |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $all = false; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Name of file to be reverted. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $file = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Revision |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $revision = ''; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set whether all files are to be reverted. |
48
|
|
|
* |
49
|
|
|
* @param string $value Jenkins style boolean value |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
2 |
|
public function setAll($value) |
54
|
|
|
{ |
55
|
2 |
|
$this->all = StringHelper::booleanValue($value); |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Set filename to be reverted. |
60
|
|
|
* |
61
|
|
|
* @param string $file Filename |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function setFile($file) |
66
|
|
|
{ |
67
|
|
|
$this->file = $file; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get filename to be reverted. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getFile() |
76
|
|
|
{ |
77
|
|
|
return $this->file; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set revision attribute |
82
|
|
|
* |
83
|
|
|
* @param string $revision Revision |
84
|
|
|
* |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
1 |
|
public function setRevision($revision) |
88
|
|
|
{ |
89
|
1 |
|
$this->revision = $revision; |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* The main entry point method. |
94
|
|
|
* |
95
|
|
|
* @throws BuildException |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
3 |
|
public function main() |
99
|
|
|
{ |
100
|
3 |
|
$clone = $this->getFactoryInstance('revert'); |
101
|
3 |
|
$clone->setQuiet($this->getQuiet()); |
102
|
3 |
|
$clone->setAll($this->all); |
103
|
3 |
|
if ($this->repository === '') { |
104
|
|
|
$project = $this->getProject(); |
105
|
|
|
$dir = $project->getProperty('application.startdir'); |
106
|
|
|
} else { |
107
|
3 |
|
$dir = $this->repository; |
108
|
|
|
} |
109
|
3 |
|
$cwd = getcwd(); |
|
|
|
|
110
|
3 |
|
$this->checkRepositoryIsDirAndExists($dir); |
111
|
3 |
|
chdir($dir); |
112
|
3 |
|
if ($this->revision !== '') { |
113
|
1 |
|
$clone->setRev($this->revision); |
114
|
|
|
} |
115
|
3 |
|
if ($this->file !== null) { |
116
|
|
|
$clone->addName($this->file); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
try { |
120
|
3 |
|
$this->log("Executing: " . $clone->asString(), Project::MSG_INFO); |
121
|
3 |
|
$output = $clone->execute(); |
122
|
1 |
|
if ($output !== '') { |
123
|
1 |
|
$this->log(PHP_EOL . $output); |
124
|
|
|
} |
125
|
2 |
|
} catch (Exception $ex) { |
126
|
2 |
|
$msg = $ex->getMessage(); |
127
|
2 |
|
$p = strpos($msg, 'hg returned:'); |
128
|
2 |
|
if ($p !== false) { |
129
|
2 |
|
$msg = substr($msg, $p + 13); |
130
|
|
|
} |
131
|
2 |
|
throw new BuildException($msg); |
132
|
|
|
} |
133
|
1 |
|
} |
134
|
|
|
} |
135
|
|
|
|