From d8961674d3adf024474394ff1d8a4a0ba627f5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Fri, 8 Nov 2013 11:00:07 -0200 Subject: [PATCH] Experimental, git rebase deployment strategy. --- .../Deployment/Strategy/GitRebaseTask.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php new file mode 100644 index 0000000..332517a --- /dev/null +++ b/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php @@ -0,0 +1,79 @@ + +* +* 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 + */ +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; + } +} \ No newline at end of file