1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* GitElephant - An abstraction layer for git written in PHP |
4
|
|
|
* Copyright (C) 2013 Matteo Giachino |
5
|
|
|
* |
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with this program. If not, see [http://www.gnu.org/licenses/]. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
namespace GitElephant\Command; |
22
|
|
|
|
23
|
|
|
use \GitElephant\Objects\Branch; |
24
|
|
|
use \GitElephant\Objects\Remote; |
25
|
|
|
use \GitElephant\Repository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class PushCommand |
29
|
|
|
*/ |
30
|
|
|
class PushCommand extends BaseCommand |
31
|
|
|
{ |
32
|
|
|
const GIT_PUSH_COMMAND = 'push'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* constructor |
36
|
|
|
* |
37
|
|
|
* @param \GitElephant\Repository $repo The repository object this command |
38
|
|
|
* will interact with |
39
|
|
|
*/ |
40
|
2 |
|
public function __construct(Repository $repo = null) |
41
|
|
|
{ |
42
|
2 |
|
parent::__construct($repo); |
43
|
2 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Remote|string $remote |
47
|
|
|
* @param Branch|string $branch |
48
|
|
|
* |
49
|
|
|
* @throws \RuntimeException |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
2 |
|
public function push($remote = 'origin', $branch = 'master', $args = null) |
53
|
|
|
{ |
54
|
2 |
|
if ($remote instanceof Remote) { |
55
|
1 |
|
$remote = $remote->getName(); |
56
|
1 |
|
} |
57
|
2 |
|
if ($branch instanceof Branch) { |
58
|
1 |
|
$branch = $branch->getName(); |
59
|
1 |
|
} |
60
|
2 |
|
$this->clearAll(); |
61
|
2 |
|
$this->addCommandName(self::GIT_PUSH_COMMAND); |
62
|
2 |
|
$this->addCommandSubject($remote); |
63
|
2 |
|
$this->addCommandSubject2($branch); |
64
|
|
|
|
65
|
2 |
|
if(!is_null($args)) { |
|
|
|
|
66
|
|
|
$this->addCommandArgument($args); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
return $this->getCommand(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|