mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-23 08:02:15 +02:00
Experimental, git rebase deployment strategy.
This commit is contained in:
parent
c36f82ea4e
commit
d8961674d3
79
Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php
Normal file
79
Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Task\BuiltIn\Deployment\Strategy;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Mage\Task\Releases\IsReleaseAware;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Task for using Git Working Copy as the Deployed Code
|
||||
*
|
||||
* @author Oscar Reales <oreales@gmail.com>
|
||||
*/
|
||||
class GitRebaseTask extends AbstractTask implements IsReleaseAware
|
||||
{
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see \Mage\Task\AbstractTask::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Deploy via Git Rebase [built-in]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebases the Git Working Copy as the Deployed Code
|
||||
* @see \Mage\Task\AbstractTask::run()
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$branch = $this->getParameter('branch');
|
||||
$remote = $this->getParameter('remote');
|
||||
|
||||
// Fetch Remote
|
||||
$command = 'git fetch ' . $remote;
|
||||
$result = $this->runCommandRemote($command) && $result;
|
||||
|
||||
// Checkout
|
||||
$command = 'git checkout ' . $branch;
|
||||
$result = $this->runCommandRemote($command) && $result;
|
||||
|
||||
// Check Working Copy status
|
||||
$stashed = false;
|
||||
$status = '';
|
||||
$command = 'git checkout ' . $branch;
|
||||
$result = $this->runCommandRemote($command) && $result;
|
||||
|
||||
// Stash if Working Copy is not clean
|
||||
if(!$status) {
|
||||
$stashResult = '';
|
||||
$command = 'git stash';
|
||||
$result = $this->runCommandRemote($command, $stashResult) && $result;
|
||||
if($stashResult != "No local changes to save") {
|
||||
$stashed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Rebase
|
||||
$command = 'git rebase ' . $remote . '/' . $branch;
|
||||
$result = $this->runCommandRemote($command) && $result;
|
||||
|
||||
// If Stashed, restore.
|
||||
if ($stashed) {
|
||||
$command = 'git tash pop';
|
||||
$result = $this->runCommandRemote($command) && $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue