1 | <?php |
||
31 | class Branch extends NodeObject implements TreeishInterface |
||
32 | { |
||
33 | /** |
||
34 | * current checked out branch |
||
35 | * |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $current = false; |
||
39 | |||
40 | /** |
||
41 | * branch name |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $name; |
||
|
|||
46 | |||
47 | /** |
||
48 | * sha |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $sha; |
||
53 | |||
54 | /** |
||
55 | * branch comment |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | private $comment; |
||
60 | |||
61 | /** |
||
62 | * the full branch reference |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | private $fullRef; |
||
67 | |||
68 | /** |
||
69 | * Creates a new branch on the repository and returns it |
||
70 | * |
||
71 | * @param \GitElephant\Repository $repository repository instance |
||
72 | * @param string $name branch name |
||
73 | * @param string $startPoint branch to start from |
||
74 | * |
||
75 | * @throws \RuntimeException |
||
76 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
77 | * @throws \Symfony\Component\Process\Exception\InvalidArgumentException |
||
78 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
79 | * @return \GitElephant\Objects\Branch |
||
80 | */ |
||
81 | 33 | public static function create(Repository $repository, string $name, string $startPoint = null) |
|
89 | |||
90 | /** |
||
91 | * static generator to generate a single commit from output of command.show service |
||
92 | * |
||
93 | * @param \GitElephant\Repository $repository repository |
||
94 | * @param string $outputLine output line |
||
95 | * |
||
96 | * @throws \InvalidArgumentException |
||
97 | * @return Branch |
||
98 | */ |
||
99 | 13 | public static function createFromOutputLine(Repository $repository, string $outputLine) |
|
107 | |||
108 | /** |
||
109 | * @param \GitElephant\Repository $repository repository instance |
||
110 | * @param string|TreeishInterface $name branch name |
||
111 | * @param bool $create like checkout -b, create a branch and check it out |
||
112 | * |
||
113 | * @throws \RuntimeException |
||
114 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
115 | * @return Branch |
||
116 | */ |
||
117 | 2 | public static function checkout(Repository $repository, $name, $create = false) |
|
129 | |||
130 | /** |
||
131 | * Class constructor |
||
132 | * |
||
133 | * @param \GitElephant\Repository $repository repository instance |
||
134 | * @param string $name branch name |
||
135 | * |
||
136 | * @throws \RuntimeException |
||
137 | * @throws \InvalidArgumentException |
||
138 | * @throws \GitElephant\Exception\InvalidBranchNameException |
||
139 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
140 | */ |
||
141 | 42 | public function __construct(Repository $repository, string $name) |
|
148 | |||
149 | /** |
||
150 | * get the branch properties from command |
||
151 | * |
||
152 | * @throws \InvalidArgumentException |
||
153 | */ |
||
154 | 42 | private function createFromCommand() |
|
170 | |||
171 | /** |
||
172 | * parse an output line from the BranchCommand::singleInfo command |
||
173 | * |
||
174 | * @param string $branchString an output line for a branch |
||
175 | * |
||
176 | * @throws \InvalidArgumentException |
||
177 | */ |
||
178 | 42 | public function parseOutputLine(string $branchString) |
|
192 | |||
193 | /** |
||
194 | * get the matches from an output line |
||
195 | * |
||
196 | * @param string $branchString branch line output |
||
197 | * |
||
198 | * @throws \InvalidArgumentException |
||
199 | * @return array |
||
200 | */ |
||
201 | 45 | public static function getMatches(string $branchString) |
|
221 | |||
222 | /** |
||
223 | * toString magic method |
||
224 | * |
||
225 | * @return string the sha |
||
226 | */ |
||
227 | 4 | public function __toString() |
|
231 | |||
232 | /** |
||
233 | * name setter |
||
234 | * |
||
235 | * @param string $name the branch name |
||
236 | */ |
||
237 | public function setName(string $name) |
||
241 | |||
242 | /** |
||
243 | * name setter |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | 14 | public function getName() |
|
251 | |||
252 | /** |
||
253 | * sha setter |
||
254 | * |
||
255 | * @param string $sha the sha of the branch |
||
256 | */ |
||
257 | public function setSha(string $sha) |
||
261 | |||
262 | /** |
||
263 | * sha getter |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | 9 | public function getSha() |
|
271 | |||
272 | /** |
||
273 | * current setter |
||
274 | * |
||
275 | * @param bool $current whether if the branch is the current or not |
||
276 | */ |
||
277 | public function setCurrent(bool $current) |
||
281 | |||
282 | /** |
||
283 | * current getter |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | 5 | public function getCurrent() |
|
291 | |||
292 | /** |
||
293 | * comment setter |
||
294 | * |
||
295 | * @param string $comment the branch comment |
||
296 | */ |
||
297 | public function setComment(string $comment) |
||
301 | |||
302 | /** |
||
303 | * comment getter |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | 1 | public function getComment() |
|
311 | |||
312 | /** |
||
313 | * fullref setter |
||
314 | * |
||
315 | * @param string $fullRef full git reference of the branch |
||
316 | */ |
||
317 | public function setFullRef(string $fullRef) |
||
321 | |||
322 | /** |
||
323 | * fullRef getter |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | 2 | public function getFullRef() |
|
331 | } |
||
332 |