1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
17
|
|
|
* and is licensed under the LGPL. For more information please see |
18
|
|
|
* <http://phing.info>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Phing\Task\Ext; |
22
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
24
|
|
|
use Phing\Project; |
25
|
|
|
use Phing\Type\Element\FileSetAware; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Wrapper around git-commit |
29
|
|
|
* |
30
|
|
|
* @package phing.tasks.ext.git |
31
|
|
|
* @author Jonathan Creasy <[email protected]> |
32
|
|
|
* @see VersionControl_Git |
33
|
|
|
* @since 2.4.3 |
34
|
|
|
*/ |
35
|
|
|
class GitCommitTask extends GitBaseTask |
36
|
|
|
{ |
37
|
|
|
use FileSetAware; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var boolean |
41
|
|
|
*/ |
42
|
|
|
private $allFiles = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $message; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The main entry point for the task |
51
|
|
|
*/ |
52
|
|
|
public function main() |
53
|
|
|
{ |
54
|
|
|
if (null === $this->getRepository()) { |
|
|
|
|
55
|
|
|
throw new BuildException('"repository" is required parameter'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($this->allFiles !== true && empty($this->filesets)) { |
59
|
|
|
throw new BuildException('"allFiles" cannot be false if no filesets are specified.'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$options = []; |
63
|
|
|
if ($this->allFiles === true) { |
64
|
|
|
$options['all'] = true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$arguments = []; |
68
|
|
|
if ($this->allFiles !== true) { |
69
|
|
|
foreach ($this->filesets as $fs) { |
70
|
|
|
$ds = $fs->getDirectoryScanner($this->project); |
71
|
|
|
$srcFiles = $ds->getIncludedFiles(); |
72
|
|
|
|
73
|
|
|
foreach ($srcFiles as $file) { |
74
|
|
|
$arguments[] = $file; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (!empty($this->message)) { |
80
|
|
|
$options['message'] = $this->message; |
81
|
|
|
} else { |
82
|
|
|
$options['allow-empty-message'] = true; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
try { |
86
|
|
|
$client = $this->getGitClient(false, $this->getRepository()); |
87
|
|
|
|
88
|
|
|
$command = $client->getCommand('commit'); |
89
|
|
|
$command->setArguments($arguments); |
90
|
|
|
$command->setOptions($options); |
91
|
|
|
$command->execute(); |
92
|
|
|
} catch (\Exception $e) { |
93
|
|
|
throw new BuildException('The remote end hung up unexpectedly', $e); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->logCommand($options, $arguments); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param array $options |
101
|
|
|
* @param array $arguments |
102
|
|
|
*/ |
103
|
|
|
protected function logCommand(array $options, array $arguments) |
104
|
|
|
{ |
105
|
|
|
$msg = 'git-commit: Executed git commit '; |
106
|
|
|
foreach ($options as $option => $value) { |
107
|
|
|
$msg .= ' --' . $option . '=' . $value; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
foreach ($arguments as $argument) { |
111
|
|
|
$msg .= ' ' . $argument; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$this->log($msg, Project::MSG_INFO); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function getAllFiles() |
121
|
|
|
{ |
122
|
|
|
return $this->allFiles; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param $flag |
127
|
|
|
*/ |
128
|
|
|
public function setAllFiles(bool $flag) |
129
|
|
|
{ |
130
|
|
|
$this->allFiles = $flag; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getMessage() |
137
|
|
|
{ |
138
|
|
|
return $this->message; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param $message |
143
|
|
|
*/ |
144
|
|
|
public function setMessage($message) |
145
|
|
|
{ |
146
|
|
|
$this->message = $message; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|