1
0
mirror of https://github.com/hauke68/Magallanes.git synced 2025-09-13 20:50:18 +02:00
Magallanes/Mage/Task/BuiltIn/Scm/ChangeBranch.php

65 lines
1.8 KiB
PHP
Raw Normal View History

2012-12-26 16:15:37 +01:00
<?php
class Mage_Task_BuiltIn_Scm_ChangeBranch
extends Mage_Task_TaskAbstract
{
2013-07-07 01:46:19 +02:00
protected static $_startingBranch = 'master';
2012-12-26 16:15:37 +01:00
private $_name = 'SCM Changing branch [built-in]';
public function getName()
{
return $this->_name;
}
public function init()
{
2013-07-07 01:46:19 +02:00
switch ($this->getConfig()->general('scm')) {
2012-12-26 16:15:37 +01:00
case 'git':
$this->_name = 'SCM Changing branch (GIT) [built-in]';
break;
case 'svn':
$this->_name = 'SCM Changing branch (Subversion) [built-in]';
break;
}
}
public function run()
{
2013-07-07 01:46:19 +02:00
switch ($this->getConfig()->general('scm')) {
2012-12-26 16:15:37 +01:00
case 'git':
2013-07-07 01:46:19 +02:00
if ($this->getParameter('_changeBranchRevert', false)) {
$command = 'git checkout ' . self::$_startingBranch;
$result = $this->_runLocalCommand($command);
2012-12-26 16:15:37 +01:00
2013-07-07 01:46:19 +02:00
} else {
$command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
$currentBranch = 'master';
$result = $this->_runLocalCommand($command, $currentBranch);
2012-12-26 16:15:37 +01:00
2013-07-07 01:46:19 +02:00
$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;
}
}
2012-12-26 16:15:37 +01:00
break;
default:
2013-07-07 01:46:19 +02:00
throw new Mage_Task_SkipException;
2012-12-26 16:15:37 +01:00
break;
}
$this->getConfig()->reload();
return $result;
}
}