| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * $Id$ |
|---|
| 4 | * |
|---|
| 5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 16 | * |
|---|
| 17 | * This software consists of voluntary contributions made by many individuals |
|---|
| 18 | * and is licensed under the LGPL. For more information please see |
|---|
| 19 | * <http://phing.info>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | require_once 'phing/Task.php'; |
|---|
| 23 | require_once 'phing/tasks/ext/git/GitBaseTask.php'; |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | * Wrapper aroung git-fetch |
|---|
| 27 | * |
|---|
| 28 | * @author Victor Farazdagi <simple.square@gmail.com> |
|---|
| 29 | * @version $Id$ |
|---|
| 30 | * @package phing.tasks.ext.git |
|---|
| 31 | * @see VersionControl_Git |
|---|
| 32 | * @since 2.4.3 |
|---|
| 33 | */ |
|---|
| 34 | class GitFetchTask extends GitBaseTask |
|---|
| 35 | { |
|---|
| 36 | /** |
|---|
| 37 | * --force, -f key to git-fetch |
|---|
| 38 | * @var boolean |
|---|
| 39 | */ |
|---|
| 40 | private $force = false; |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * --quiet, -q key to git-fetch |
|---|
| 44 | * @var boolean |
|---|
| 45 | */ |
|---|
| 46 | private $quiet = false; |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | * Fetch all remotes |
|---|
| 50 | * --all key to git-fetch |
|---|
| 51 | * @var boolean |
|---|
| 52 | */ |
|---|
| 53 | private $allRemotes = false; |
|---|
| 54 | |
|---|
| 55 | /** |
|---|
| 56 | * Keep downloaded pack |
|---|
| 57 | * --keep key to git-fetch |
|---|
| 58 | * @var boolean |
|---|
| 59 | */ |
|---|
| 60 | private $keepFiles = false; |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * After fetching, remove any remote tracking branches which no longer |
|---|
| 64 | * exist on the remote. |
|---|
| 65 | * --prune key to git fetch |
|---|
| 66 | * @var boolean |
|---|
| 67 | */ |
|---|
| 68 | private $prune = false; |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * Disable/enable automatic tag following |
|---|
| 72 | * --no-tags key to git-fetch |
|---|
| 73 | * @var boolean |
|---|
| 74 | */ |
|---|
| 75 | private $noTags = false; |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * Fetch all tags (even not reachable from branch heads) |
|---|
| 79 | * --tags key to git-fetch |
|---|
| 80 | * @var boolean |
|---|
| 81 | */ |
|---|
| 82 | private $tags = false; |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * <group> argument to git-fetch |
|---|
| 86 | * @var string |
|---|
| 87 | */ |
|---|
| 88 | private $group; |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | * <repository> argument to git-fetch |
|---|
| 92 | * @var string |
|---|
| 93 | */ |
|---|
| 94 | private $source = 'origin'; |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * <refspec> argument to git-fetch |
|---|
| 98 | * @var string |
|---|
| 99 | */ |
|---|
| 100 | private $refspec; |
|---|
| 101 | |
|---|
| 102 | /** |
|---|
| 103 | * The main entry point for the task |
|---|
| 104 | */ |
|---|
| 105 | public function main() |
|---|
| 106 | { |
|---|
| 107 | if (null === $this->getRepository()) { |
|---|
| 108 | throw new BuildException('"repository" is required parameter'); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | $client = $this->getGitClient(false, $this->getRepository()); |
|---|
| 112 | $command = $client->getCommand('fetch'); |
|---|
| 113 | $command |
|---|
| 114 | ->setOption('tags', $this->isTags()) |
|---|
| 115 | ->setOption('no-tags', $this->isNoTags()) |
|---|
| 116 | ->setOption('prune', $this->isPrune()) |
|---|
| 117 | ->setOption('keep', $this->isKeepFiles()) |
|---|
| 118 | ->setOption('q', $this->isQuiet()) |
|---|
| 119 | ->setOption('force', $this->isForce()); |
|---|
| 120 | |
|---|
| 121 | // set operation target |
|---|
| 122 | if ($this->isAllRemotes()) { // --all |
|---|
| 123 | $command->setOption('all', true); |
|---|
| 124 | } elseif ($this->getGroup()) { // <group> |
|---|
| 125 | $command->addArgument($this->getGroup()); |
|---|
| 126 | } elseif ($this->getSource()) { // <repository> [<refspec>] |
|---|
| 127 | $command->addArgument($this->getSource()); |
|---|
| 128 | if ($this->getRefspec()) { |
|---|
| 129 | $command->addArgument($this->getRefspec()); |
|---|
| 130 | } |
|---|
| 131 | } else { |
|---|
| 132 | throw new BuildException('No remote repository specified'); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | // I asked Ebihara to make this method public - will see |
|---|
| 136 | //echo $command->createCommandString(); |
|---|
| 137 | //exit; |
|---|
| 138 | |
|---|
| 139 | try { |
|---|
| 140 | $output = $command->execute(); |
|---|
| 141 | } catch (Exception $e) { |
|---|
| 142 | throw new BuildException('Task execution failed.'); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | $this->log( |
|---|
| 146 | sprintf('git-fetch: branch "%s" repository', $this->getRepository()), |
|---|
| 147 | Project::MSG_INFO); |
|---|
| 148 | $this->log('git-fetch output: ' . trim($output), Project::MSG_INFO); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | public function setForce($flag) |
|---|
| 152 | { |
|---|
| 153 | $this->force = $flag; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | public function getForce($flag) |
|---|
| 157 | { |
|---|
| 158 | return $this->force; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | public function isForce() |
|---|
| 162 | { |
|---|
| 163 | return $this->getForce(); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | public function setQuiet($flag) |
|---|
| 167 | { |
|---|
| 168 | $this->quiet = $flag; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | public function getQuiet() |
|---|
| 172 | { |
|---|
| 173 | return $this->quiet; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | public function isQuiet() |
|---|
| 177 | { |
|---|
| 178 | return $this->getQuiet(); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | public function setAll($flag) |
|---|
| 182 | { |
|---|
| 183 | $this->allRemotes = $flag; |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | public function getAll() |
|---|
| 187 | { |
|---|
| 188 | return $this->allRemotes; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | public function isAllRemotes() |
|---|
| 192 | { |
|---|
| 193 | return $this->getAll(); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | public function setKeep($flag) |
|---|
| 197 | { |
|---|
| 198 | $this->keepFiles = $flag; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | public function getKeep() |
|---|
| 202 | { |
|---|
| 203 | return $this->keepFiles; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | public function isKeepFiles() |
|---|
| 207 | { |
|---|
| 208 | return $this->getKeep(); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | public function setPrune($flag) |
|---|
| 212 | { |
|---|
| 213 | $this->prune = $flag; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | public function getPrune() |
|---|
| 217 | { |
|---|
| 218 | return $this->prune; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | public function isPrune() |
|---|
| 222 | { |
|---|
| 223 | return $this->getPrune(); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | public function setNoTags($flag) |
|---|
| 227 | { |
|---|
| 228 | $this->noTags = $flag; |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | public function getNoTags() |
|---|
| 232 | { |
|---|
| 233 | return $this->noTags; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | public function isNoTags() |
|---|
| 237 | { |
|---|
| 238 | return $this->getNoTags(); |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | public function setTags($flag) |
|---|
| 242 | { |
|---|
| 243 | $this->tags = $flag; |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | public function getTags() |
|---|
| 247 | { |
|---|
| 248 | return $this->tags; |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | public function isTags() |
|---|
| 252 | { |
|---|
| 253 | return $this->getTags(); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | public function setSource($source) |
|---|
| 257 | { |
|---|
| 258 | $this->source = $source; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | public function getSource() |
|---|
| 262 | { |
|---|
| 263 | return $this->source; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | public function setRefspec($spec) |
|---|
| 267 | { |
|---|
| 268 | $this->refspec = $spec; |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | public function getRefspec() |
|---|
| 272 | { |
|---|
| 273 | return $this->refspec; |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | public function setGroup($group) |
|---|
| 277 | { |
|---|
| 278 | $this->group = $group; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | public function getGroup() |
|---|
| 282 | { |
|---|
| 283 | return $this->group; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | } |
|---|