-
Notifications
You must be signed in to change notification settings - Fork 0
/
HgTagTask.php
162 lines (146 loc) · 3.33 KB
/
HgTagTask.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Utilise Mercurial from within Phing.
*
* PHP Version 5.4
*
* @category Tasks
* @package phing.tasks.ext
* @author Ken Guest <[email protected]>
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html)
* @link https://github.com/kenguest/Phing-HG
*/
namespace Phing\Task\Ext\Hg;
use Phing\Exception\BuildException;
use Phing\Project;
/**
* Integration/Wrapper for hg tag
*
* @category Tasks
* @package phing.tasks.ext.hg
* @author Ken Guest <[email protected]>
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html)
* @link HgTagTask.php
*/
class HgTagTask extends HgBaseTask
{
/**
* Message to be recorded against tagging.
*
* @var string
*/
protected $message = '';
/**
* Tag to assign/create.
*
* @var string
*/
protected $name = '';
/**
* Revision
*
* @var string
*/
protected $revision = '';
/**
* Set the name argument
*
* @param string $name Name
*
* @return void
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the name of the tag to be used.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set message to be used.
*
* @param string $message Message to use
*
* @return void
*/
public function setMessage($message)
{
$this->message = $message;
}
/**
* Get message to apply for the commit.
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* Set revision attribute
*
* @param string $revision Revision
*
* @return void
*/
public function setRevision($revision)
{
$this->revision = $revision;
}
/**
* The main entry point method.
*
* @return void
*/
public function main()
{
$clone = $this->getFactoryInstance('tag');
$cwd = getcwd();
if ($this->name === '') {
throw new BuildException("Tag name must be set.");
}
if ($this->repository === '') {
$prog = $this->getProject();
$dir = $prog->getProperty('application.startdir');
} else {
$dir = $this->repository;
}
if ($this->revision !== '') {
$clone->setRev($this->revision);
}
if ($this->user !== null) {
$clone->setUser($this->user);
}
$message = $this->getMessage();
$clone->setMessage($message);
$name = $this->getName();
if ($name == '') {
throw new BuildException("Name attribute must be set.");
}
$clone->addName($name);
$this->checkRepositoryIsDirAndExists($dir);
chdir($dir);
try {
$this->log("Executing: " . $clone, Project::MSG_INFO);
$output = $clone->execute();
if ($output !== '') {
$this->log($output);
}
} catch (\Exception $ex) {
$msg = $ex->getMessage();
$p = strpos($msg, 'hg returned:');
if ($p !== false) {
$msg = substr($msg, $p + 13);
}
chdir($cwd);
throw new BuildException($msg);
}
chdir($cwd);
}
}