1 | <?php |
||
32 | class Branch extends NodeObject implements TreeishInterface |
||
33 | { |
||
34 | /** |
||
35 | * current checked out branch |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $current = false; |
||
40 | |||
41 | /** |
||
42 | * branch name |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $name; |
||
|
|||
47 | |||
48 | /** |
||
49 | * sha |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $sha; |
||
54 | |||
55 | /** |
||
56 | * branch comment |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $comment; |
||
61 | |||
62 | /** |
||
63 | * the full branch reference |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | private $fullRef; |
||
68 | |||
69 | /** |
||
70 | * Creates a new branch on the repository and returns it |
||
71 | * |
||
72 | * @param \GitElephant\Repository $repository repository instance |
||
73 | * @param string $name branch name |
||
74 | * @param string $startPoint branch to start from |
||
75 | * |
||
76 | * @throws \RuntimeException |
||
77 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
78 | * @throws \Symfony\Component\Process\Exception\InvalidArgumentException |
||
79 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
80 | * @return \GitElephant\Objects\Branch |
||
81 | */ |
||
82 | 33 | public static function create( |
|
96 | |||
97 | /** |
||
98 | * static generator to generate a single commit from output of command.show service |
||
99 | * |
||
100 | * @param \GitElephant\Repository $repository repository |
||
101 | * @param string $outputLine output line |
||
102 | * |
||
103 | * @throws \InvalidArgumentException |
||
104 | * @return Branch |
||
105 | */ |
||
106 | 13 | public static function createFromOutputLine(Repository $repository, string $outputLine): \GitElephant\Objects\Branch |
|
114 | |||
115 | /** |
||
116 | * @param \GitElephant\Repository $repository repository instance |
||
117 | * @param string|TreeishInterface $name branch name |
||
118 | * @param bool $create like checkout -b, create a branch and check it out |
||
119 | * |
||
120 | * @throws \RuntimeException |
||
121 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
122 | * @return Branch |
||
123 | */ |
||
124 | 2 | public static function checkout(Repository $repository, $name, $create = false): \GitElephant\Objects\Branch |
|
132 | |||
133 | /** |
||
134 | * Class constructor |
||
135 | * |
||
136 | * @param \GitElephant\Repository $repository repository instance |
||
137 | * @param string $name branch name |
||
138 | * |
||
139 | * @throws \RuntimeException |
||
140 | * @throws \InvalidArgumentException |
||
141 | * @throws \GitElephant\Exception\InvalidBranchNameException |
||
142 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
143 | */ |
||
144 | 42 | public function __construct(Repository $repository, string $name) |
|
151 | |||
152 | /** |
||
153 | * get the branch properties from command |
||
154 | * |
||
155 | * @throws \InvalidArgumentException |
||
156 | */ |
||
157 | 42 | private function createFromCommand(): void |
|
173 | |||
174 | /** |
||
175 | * parse an output line from the BranchCommand::singleInfo command |
||
176 | * |
||
177 | * @param string $branchString an output line for a branch |
||
178 | * |
||
179 | * @throws \InvalidArgumentException |
||
180 | */ |
||
181 | 42 | public function parseOutputLine(string $branchString): void |
|
195 | |||
196 | /** |
||
197 | * get the matches from an output line |
||
198 | * |
||
199 | * @param string $branchString branch line output |
||
200 | * |
||
201 | * @throws \InvalidArgumentException |
||
202 | * @return array |
||
203 | */ |
||
204 | 45 | public static function getMatches(string $branchString): array |
|
223 | |||
224 | /** |
||
225 | * toString magic method |
||
226 | * |
||
227 | * @return string the sha |
||
228 | */ |
||
229 | 4 | public function __toString(): string |
|
233 | |||
234 | /** |
||
235 | * name setter |
||
236 | * |
||
237 | * @param string $name the branch name |
||
238 | */ |
||
239 | public function setName(string $name): void |
||
243 | |||
244 | /** |
||
245 | * name setter |
||
246 | * |
||
247 | * @return string |
||
248 | */ |
||
249 | 14 | public function getName(): string |
|
253 | |||
254 | /** |
||
255 | * sha setter |
||
256 | * |
||
257 | * @param string $sha the sha of the branch |
||
258 | */ |
||
259 | public function setSha(string $sha): void |
||
263 | |||
264 | /** |
||
265 | * sha getter |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | 9 | public function getSha(): string |
|
273 | |||
274 | /** |
||
275 | * current setter |
||
276 | * |
||
277 | * @param bool $current whether if the branch is the current or not |
||
278 | */ |
||
279 | public function setCurrent(bool $current): void |
||
283 | |||
284 | /** |
||
285 | * current getter |
||
286 | * |
||
287 | * @return bool |
||
288 | */ |
||
289 | 5 | public function getCurrent(): bool |
|
293 | |||
294 | /** |
||
295 | * comment setter |
||
296 | * |
||
297 | * @param string $comment the branch comment |
||
298 | */ |
||
299 | public function setComment(string $comment): void |
||
303 | |||
304 | /** |
||
305 | * comment getter |
||
306 | * |
||
307 | * @return string |
||
308 | */ |
||
309 | 1 | public function getComment(): string |
|
313 | |||
314 | /** |
||
315 | * fullref setter |
||
316 | * |
||
317 | * @param string $fullRef full git reference of the branch |
||
318 | */ |
||
319 | public function setFullRef(string $fullRef): void |
||
323 | |||
324 | /** |
||
325 | * fullRef getter |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | 2 | public function getFullRef(): string |
|
333 | } |
||
334 |