Allow to fail a task with a message via Mage_Task_ErrorWithMessageException

This commit is contained in:
Andrés Montañez 2013-11-02 19:14:52 -02:00
parent d5ebf6e6e3
commit fe60dfbdd4
4 changed files with 28 additions and 11 deletions

View file

@ -305,6 +305,10 @@ class Mage_Command_BuiltIn_Deploy
Mage_Console::output('<red>FAIL</red>', 0);
$result = false;
}
} catch (Mage_Task_ErrorWithMessageException $e) {
Mage_Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
$result = false;
} catch (Mage_Task_SkipException $e) {
Mage_Console::output('<yellow>SKIPPED</yellow>', 0);
$result = true;

View file

@ -2,7 +2,7 @@
class Mage_Task_BuiltIn_Scm_ChangeBranch
extends Mage_Task_TaskAbstract
{
protected static $_startingBranch = 'master';
protected static $startingBranch = 'master';
private $_name = 'SCM Changing branch [built-in]';
public function getName()
@ -25,10 +25,11 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
public function run()
{
switch ($this->getConfig()->general('scm')) {
$scmConfig = $this->getConfig()->general('scm', array());
switch ((isset($scmConfig['type']) ? $scmConfig['type'] : false)) {
case 'git':
if ($this->getParameter('_changeBranchRevert', false)) {
$command = 'git checkout ' . self::$_startingBranch;
$command = 'git checkout ' . self::$startingBranch;
$result = $this->_runLocalCommand($command);
} else {
@ -37,19 +38,25 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
$result = $this->_runLocalCommand($command, $currentBranch);
$scmData = $this->getConfig()->deployment('scm', false);
if ($result && is_array($scmData) && isset($scmData['branch'])) {
$branch = $this->getParameter('branch', $scmData['branch']);
$command = 'git checkout ' . $branch;
$result = $this->_runLocalCommand($command);
self::$_startingBranch = $currentBranch;
if ($result && is_array($scmData) && isset($scmData['branch']) && $scmData['branch'] != $currentBranch) {
$command = 'git branch | grep \'' . $scmData['branch'] . '\' | tr -s \' \' | sed \'s/^[ ]//g\'';
$isBranchTracked = '';
$result = $this->_runLocalCommand($command, $isBranchTracked);
if ($isBranchTracked == '') {
throw new Mage_Task_ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
}
$branch = $this->getParameter('branch', $scmData['branch']);
$command = 'git checkout ' . $branch;
$result = $this->_runLocalCommand($command);
self::$startingBranch = $currentBranch;
} else {
throw new Mage_Task_SkipException;
}
}
break;
default:

View file

@ -0,0 +1,6 @@
<?php
class Mage_Task_ErrorWithMessageException
extends Exception
{
}

View file

@ -4,7 +4,7 @@ deployment:
from: ./
to: /var/www/
scm:
branch: master
branch: master2
releases:
enabled: true
max: 5