mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-29 18:48:56 +02:00
Change structure.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Task\BuiltIn\Git;
|
||||
|
||||
use Mage\Task\Exception\SkipException;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Git Task - Checkout Branch
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class ChangeBranchTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'git/change-branch';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$branch = $options['branch'];
|
||||
|
||||
if ($this->runtime->getVar('git_revert_branch', false)) {
|
||||
$branch = $this->runtime->getVar('git_revert_branch');
|
||||
}
|
||||
|
||||
return sprintf('[Git] Change Branch (%s)', $branch);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$branch = $this->runtime->getVar('git_revert_branch', false);
|
||||
|
||||
if ($branch === false) {
|
||||
$cmdGetCurrent = sprintf('%s branch | grep "*"', $options['path']);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runLocalCommand($cmdGetCurrent);
|
||||
if (!$process->isSuccessful()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentBranch = str_replace('* ', '', trim($process->getOutput()));
|
||||
if ($currentBranch == $options['branch']) {
|
||||
throw new SkipException();
|
||||
}
|
||||
|
||||
$branch = $options['branch'];
|
||||
$this->runtime->setVar('git_revert_branch', $currentBranch);
|
||||
}
|
||||
|
||||
$cmdChange = sprintf('%s checkout %s', $options['path'], $branch);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runLocalCommand($cmdChange);
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$config = $this->runtime->getEnvironmentConfig();
|
||||
$branch = 'master';
|
||||
if (array_key_exists('branch', $config)) {
|
||||
$branch = $config['branch'];
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
['path' => 'git', 'branch' => $branch],
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Task\BuiltIn\Git;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Git Task - Pull
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class UpdateTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'git/update';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Git] Update';
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$command = $options['path'] . ' pull';
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runLocalCommand($command);
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$config = $this->runtime->getEnvironmentConfig();
|
||||
$branch = 'master';
|
||||
if (array_key_exists('branch', $config)) {
|
||||
$branch = $config['branch'];
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
['path' => 'git', 'branch' => $branch],
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user