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

AddLegacyBranch::hasCommitAndPush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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