Completed
Push — master ( 0079af...103779 )
by Elf
03:43
created

MergeUpstream::executeShell()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace ElfSundae\Laravel\Support\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
8
class MergeUpstream extends Command
9
{
10
    use ConfirmableTrait;
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'support:merge-upstream
18
        {branch=master : git branch of upstream}
19
        {--remote=upstream : git remote name of upstream}
20
        {--force : Force the operation to run}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Merge upstream to the current branch';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return mixed
33
     */
34
    public function handle()
35
    {
36
        $branch = $this->argument('branch');
37
        $remote = $this->option('remote');
38
39
        $this->executeShell('git status');
40
41
        if (! $this->confirmToProceed("Will merge $remote/$branch to the current branch", true)) {
42
            return;
43
        }
44
45
        $commands = [
46
            "git fetch $remote --no-tags -v",
47
            "git merge $remote/$branch",
48
        ];
49
50
        foreach ($commands as $cmd) {
51
            $this->executeShell($cmd);
52
        }
53
    }
54
55
    /**
56
     * Execute shell command and output the result.
57
     *
58
     * @param  string  $cmd
59
     * @return void
60
     */
61
    protected function executeShell($cmd)
62
    {
63
        $this->comment('$ '.$cmd);
64
65
        $this->info(shell_exec($cmd));
66
    }
67
}
68