Passed
Push — master ( f01d00...2f7647 )
by Nicolaas
03:27
created

AddLegacyBranch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A runActualTask() 0 15 1
A getTitle() 0 3 1
A getDescription() 0 4 1
A hasCommitAndPush() 0 3 1
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
6
7
/**
8
 * This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for
9
 * holding a version of the module before it was changed
10
 */
11
class AddLegacyBranch extends Task
12
{
13
    protected $taskStep = 's10';
14
15
    /**
16
     * @var string what should the legacy branch be called
17
     */
18
    protected $nameOfLegacyBranch = '3';
19
20
    public function getTitle()
21
    {
22
        return 'Add Legacy Branch';
23
    }
24
25
    public function getDescription()
26
    {
27
        return '
28
            Creates a legacy branch: "' . $this->nameOfLegacyBranch . '" of your module so that you
29
            can keep making bugfixes to older versions.
30
            You can set the name of the legacy branch as you see fit.';
31
    }
32
33
    /**
34
     * @param  array  $params not currently used for this task
35
     */
36
    public function runActualTask($params = [])
37
    {
38
        $gitRootDir = $this->mu()->getGitRootDir();
39
        $this->mu()->execMe(
40
            $gitRootDir,
41
            '
42
            if $(git ls-remote --heads ${REPO} ${BRANCH} | grep -q ' . "'refs/heads/" . $this->nameOfLegacyBranch . "'" . '); then
43
                    echo branch exists
44
                else
45
                    git checkout -b ' . $this->nameOfLegacyBranch . ';
46
                    git push origin ' . $this->nameOfLegacyBranch . ';
47
48
            fi',
49
            'create legacy branch: ' . $this->nameOfLegacyBranch . ' in ' . $gitRootDir,
50
            false
51
        );
52
    }
53
54
    protected function hasCommitAndPush()
55
    {
56
        return false;
57
    }
58
}
59