diff --git a/Mage/Command/BuiltIn/Deploy.php b/Mage/Command/BuiltIn/Deploy.php
index b20bed7..11ec5c8 100644
--- a/Mage/Command/BuiltIn/Deploy.php
+++ b/Mage/Command/BuiltIn/Deploy.php
@@ -305,6 +305,10 @@ class Mage_Command_BuiltIn_Deploy
Mage_Console::output('FAIL', 0);
$result = false;
}
+ } catch (Mage_Task_ErrorWithMessageException $e) {
+ Mage_Console::output('FAIL [Message: ' . $e->getMessage() . ']', 0);
+ $result = false;
+
} catch (Mage_Task_SkipException $e) {
Mage_Console::output('SKIPPED', 0);
$result = true;
diff --git a/Mage/Task/BuiltIn/Scm/ChangeBranch.php b/Mage/Task/BuiltIn/Scm/ChangeBranch.php
index f79a733..465d7ca 100644
--- a/Mage/Task/BuiltIn/Scm/ChangeBranch.php
+++ b/Mage/Task/BuiltIn/Scm/ChangeBranch.php
@@ -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 ' . $scmData['branch'] . ' 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:
diff --git a/Mage/Task/ErrorWithMessageException.php b/Mage/Task/ErrorWithMessageException.php
new file mode 100644
index 0000000..f2c7650
--- /dev/null
+++ b/Mage/Task/ErrorWithMessageException.php
@@ -0,0 +1,6 @@
+