diff --git a/Mage/Command/BuiltIn/Deploy.php b/Mage/Command/BuiltIn/Deploy.php index 7227c28..fbec452 100644 --- a/Mage/Command/BuiltIn/Deploy.php +++ b/Mage/Command/BuiltIn/Deploy.php @@ -167,7 +167,8 @@ class Mage_Command_BuiltIn_Deploy if ($stage == 'post-deploy') { // Change Branch Back if ($this->getConfig()->deployment('scm', false)) { - array_unshift($tasksToRun, 'scm/change-branch-back'); + array_unshift($tasksToRun, 'scm/change-branch'); + $config->addParameter('_changeBranchRevert'); } // Remove Remote Source diff --git a/Mage/Config.php b/Mage/Config.php index caa8bdb..28b36a0 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -8,7 +8,6 @@ class Mage_Config private $_releaseId = null; private $_config = array( 'general' => array(), - 'scm' => array(), 'environment' => array(), ); @@ -78,6 +77,16 @@ class Mage_Config return $this->_parameters; } + /** + * Adds (or replaces) a parameter + * @param string $name + * @param mixed $value + */ + public function addParameter($name, $value = true) + { + $this->_parameters[$name] = $value; + } + /** * Returns the Current environment * @@ -218,27 +227,6 @@ class Mage_Config } } - /** - * Gets SCM Configuration - * - * @param string $option - * @param string $default - * @return mixed - */ - public function scm($option, $default = false) - { - $config = $this->_config['scm']; - if (isset($config[$option])) { - if (is_array($default) && ($config[$option] == '')) { - return $default; - } else { - return $config[$option]; - } - } else { - return $default; - } - } - /** * Get deployment configuration * @@ -354,16 +342,6 @@ class Mage_Config } } - /** - * Loads the SCM Configuration - */ - private function _loadSCM() - { - if (file_exists('.mage/config/scm.yml')) { - $this->_config['scm'] = spyc_load_file('.mage/config/scm.yml'); - } - } - /** * Loads the Environment configuration * diff --git a/Mage/Task/BuiltIn/Scm/ChangeBranch.php b/Mage/Task/BuiltIn/Scm/ChangeBranch.php index 259bd78..f79a733 100644 --- a/Mage/Task/BuiltIn/Scm/ChangeBranch.php +++ b/Mage/Task/BuiltIn/Scm/ChangeBranch.php @@ -2,6 +2,7 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch extends Mage_Task_TaskAbstract { + protected static $_startingBranch = 'master'; private $_name = 'SCM Changing branch [built-in]'; public function getName() @@ -11,7 +12,7 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch public function init() { - switch ($this->getConfig()->scm('type')) { + switch ($this->getConfig()->general('scm')) { case 'git': $this->_name = 'SCM Changing branch (GIT) [built-in]'; break; @@ -24,29 +25,35 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch public function run() { - switch ($this->getConfig()->scm('type')) { + switch ($this->getConfig()->general('scm')) { case 'git': - $command = 'git branch | grep \'*\' | cut -d\' \' -f 2'; - $currentBranch = 'master'; - $result = $this->_runLocalCommand($command, $currentBranch); + if ($this->getParameter('_changeBranchRevert', false)) { + $command = 'git checkout ' . self::$_startingBranch; + $result = $this->_runLocalCommand($command); - $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); + } else { + $command = 'git branch | grep \'*\' | cut -d\' \' -f 2'; + $currentBranch = 'master'; + $result = $this->_runLocalCommand($command, $currentBranch); - $oldBranchFile = '.mage/' . $this->getConfig()->getEnvironment() . '.oldBranch'; - file_put_contents($oldBranchFile, $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; + + } else { + throw new Mage_Task_SkipException; + } + } - } else { - throw new Mage_Task_SkipException; - } break; default: - return false; + throw new Mage_Task_SkipException; break; } diff --git a/Mage/Task/BuiltIn/Scm/ChangeBranchBack.php b/Mage/Task/BuiltIn/Scm/ChangeBranchBack.php deleted file mode 100644 index d44838e..0000000 --- a/Mage/Task/BuiltIn/Scm/ChangeBranchBack.php +++ /dev/null @@ -1,47 +0,0 @@ -_name; - } - - public function init() - { - switch ($this->getConfig()->scm('type')) { - case 'git': - $this->_name = 'SCM Changing branch Back (GIT) [built-in]'; - break; - - case 'svn': - $this->_name = 'SCM Changing branch Back (Subversion) [built-in]'; - break; - } - } - - public function run() - { - switch ($this->getConfig()->scm('type')) { - case 'git': - $oldBranchFile = '.mage/' . $this->getConfig()->getEnvironment() . '.oldBranch'; - $currentBranch = trim(file_get_contents($oldBranchFile)); - - $command = 'git checkout ' . $currentBranch; - $result = $this->_runLocalCommand($command); - @unlink($oldBranchFile); - break; - - default: - return false; - break; - } - - - $this->getConfig()->reload(); - - return $result; - } -} \ No newline at end of file diff --git a/Mage/Task/BuiltIn/Scm/Clone.php b/Mage/Task/BuiltIn/Scm/Clone.php index b5951c4..87cbbf3 100644 --- a/Mage/Task/BuiltIn/Scm/Clone.php +++ b/Mage/Task/BuiltIn/Scm/Clone.php @@ -43,7 +43,7 @@ class Mage_Task_BuiltIn_Scm_Clone break; case 'svn': - return false; + throw new Mage_Task_SkipException; break; } diff --git a/Mage/Task/BuiltIn/Scm/Update.php b/Mage/Task/BuiltIn/Scm/Update.php index 9341582..6589a49 100644 --- a/Mage/Task/BuiltIn/Scm/Update.php +++ b/Mage/Task/BuiltIn/Scm/Update.php @@ -11,7 +11,7 @@ class Mage_Task_BuiltIn_Scm_Update public function init() { - switch ($this->getConfig()->scm('type')) { + switch ($this->getConfig()->general('scm')) { case 'git': $this->_name = 'SCM Update (GIT) [built-in]'; break; @@ -34,7 +34,7 @@ class Mage_Task_BuiltIn_Scm_Update break; default: - return false; + throw new Mage_Task_SkipException; break; }