1 | <?php |
||
30 | class FetchCommand extends BaseCommand |
||
31 | { |
||
32 | const GIT_FETCH_COMMAND = 'fetch'; |
||
33 | const GIT_FETCH_OPTION_TAGS = '--tags'; |
||
34 | |||
35 | /** |
||
36 | * constructor |
||
37 | * |
||
38 | * @param \GitElephant\Repository $repo The repository object this command |
||
39 | * will interact with |
||
40 | */ |
||
41 | 2 | public function __construct(Repository $repo = null) |
|
45 | |||
46 | /** |
||
47 | * @param Remote|string $remote |
||
48 | * @param Branch|string $branch |
||
49 | * @param array $options |
||
50 | * |
||
51 | * @throws \RuntimeException |
||
52 | * @return string |
||
53 | */ |
||
54 | 2 | public function fetch($remote = null, $branch = null, Array $options = array()) |
|
|
|||
55 | { |
||
56 | 2 | if ($remote instanceof Remote) { |
|
57 | 1 | $remote = $remote->getName(); |
|
58 | 1 | } |
|
59 | 2 | if ($branch instanceof Branch) { |
|
60 | 1 | $branch = $branch->getName(); |
|
61 | 1 | } |
|
62 | 2 | $normalizedOptions = $this->normalizeOptions($options, $this->fetchCmdSwitchOptions()); |
|
63 | |||
64 | 2 | $this->clearAll(); |
|
65 | 2 | $this->addCommandName(self::GIT_FETCH_COMMAND); |
|
66 | |||
67 | 2 | foreach ($normalizedOptions as $value) { |
|
68 | 2 | $this->addCommandArgument($value); |
|
69 | 2 | } |
|
70 | |||
71 | 2 | if (!is_null($remote)) { |
|
72 | 1 | $this->addCommandSubject($remote); |
|
73 | 1 | } |
|
74 | 2 | if (!is_null($branch)) { |
|
75 | 1 | $this->addCommandSubject2($branch); |
|
76 | 1 | } |
|
77 | |||
78 | 2 | return $this->getCommand(); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Valid options for remote command that do not require an associated value |
||
83 | * |
||
84 | * @return array Associative array mapping all non-value options and their respective normalized option |
||
85 | */ |
||
86 | 2 | public function fetchCmdSwitchOptions() |
|
92 | } |
||
93 |