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
|
<?php
/*
* $Id: 26df19d3456fad7013ddf85c7dd0f99fc1fce387 $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/Task.php';
require_once 'phing/tasks/ext/git/GitBaseTask.php';
/**
* Wrapper around git-commit
*
* @package phing.tasks.ext.git
* @author Jonathan Creasy <jonathan.creasy@gmail.com>
* @see VersionControl_Git
* @since 2.4.3
*/
class GitCommitTask extends GitBaseTask
{
/**
* @var boolean
*/
private $allFiles = false;
/**
* @var string
*/
private $message;
/**
* @var FileSet[]
*/
private $filesets = array();
/**
* The main entry point for the task
*/
public function main()
{
if (null === $this->getRepository()) {
throw new BuildException('"repository" is required parameter');
}
if ($this->allFiles !== true && empty($this->filesets)) {
throw new BuildException('"allFiles" cannot be false if no filesets are specified.');
}
$options = array();
if ($this->allFiles === true) {
$options['all'] = true;
}
$arguments = array();
if ($this->allFiles !== true) {
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$srcFiles = $ds->getIncludedFiles();
foreach ($srcFiles as $file) {
$arguments[] = $file;
}
}
}
if (!empty($this->message)) {
$options['message'] = $this->message;
} else {
$options['allow-empty-message'] = true;
}
try {
$client = $this->getGitClient(false, $this->getRepository());
$command = $client->getCommand('commit');
$command->setArguments($arguments);
$command->setOptions($options);
$command->execute();
} catch (Exception $e) {
throw new BuildException('The remote end hung up unexpectedly', $e);
}
$this->logCommand($options, $arguments);
}
protected function logCommand(array $options, array $arguments)
{
$msg = 'git-commit: Executed git commit ';
foreach ($options as $option=>$value)
{
$msg .= ' --' . $option . '=' . $value;
}
foreach ($arguments as $argument)
{
$msg .= ' ' . $argument;
}
$this->log($msg, Project::MSG_INFO);
}
public function getAllFiles()
{
return $this->allFiles;
}
public function setAllFiles($flag)
{
$this->allFiles = (bool)$flag;
}
public function getMessage()
{
return $this->message;
}
public function setMessage($message)
{
$this->message = $message;
}
/**
* Nested adder, adds a set of files (nested fileset attribute).
*
* @return void
*/
public function addFileSet(FileSet $fs) {
$this->filesets[] = $fs;
}
}
|