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): \GitElephant\Objects\Branch |
|
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): \GitElephant\Objects\Branch |
|
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): \GitElephant\Objects\Branch |
|
125 | |||
126 | /** |
||
127 | * Class constructor |
||
128 | * |
||
129 | * @param \GitElephant\Repository $repository repository instance |
||
130 | * @param string $name branch name |
||
131 | * |
||
132 | * @throws \RuntimeException |
||
133 | * @throws \InvalidArgumentException |
||
134 | * @throws \GitElephant\Exception\InvalidBranchNameException |
||
135 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
136 | */ |
||
137 | 42 | public function __construct(Repository $repository, string $name) |
|
144 | |||
145 | /** |
||
146 | * get the branch properties from command |
||
147 | * |
||
148 | * @throws \InvalidArgumentException |
||
149 | */ |
||
150 | 42 | private function createFromCommand() |
|
166 | |||
167 | /** |
||
168 | * parse an output line from the BranchCommand::singleInfo command |
||
169 | * |
||
170 | * @param string $branchString an output line for a branch |
||
171 | * |
||
172 | * @throws \InvalidArgumentException |
||
173 | */ |
||
174 | 42 | public function parseOutputLine(string $branchString): void |
|
188 | |||
189 | /** |
||
190 | * get the matches from an output line |
||
191 | * |
||
192 | * @param string $branchString branch line output |
||
193 | * |
||
194 | * @throws \InvalidArgumentException |
||
195 | * @return array |
||
196 | */ |
||
197 | 45 | public static function getMatches(string $branchString): array |
|
217 | |||
218 | /** |
||
219 | * toString magic method |
||
220 | * |
||
221 | * @return string the sha |
||
222 | */ |
||
223 | 4 | public function __toString(): string |
|
227 | |||
228 | /** |
||
229 | * name setter |
||
230 | * |
||
231 | * @param string $name the branch name |
||
232 | */ |
||
233 | public function setName(string $name): void |
||
237 | |||
238 | /** |
||
239 | * name setter |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | 14 | public function getName(): string |
|
247 | |||
248 | /** |
||
249 | * sha setter |
||
250 | * |
||
251 | * @param string $sha the sha of the branch |
||
252 | */ |
||
253 | public function setSha(string $sha): void |
||
257 | |||
258 | /** |
||
259 | * sha getter |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | 9 | public function getSha(): string |
|
267 | |||
268 | /** |
||
269 | * current setter |
||
270 | * |
||
271 | * @param bool $current whether if the branch is the current or not |
||
272 | */ |
||
273 | public function setCurrent(bool $current): void |
||
277 | |||
278 | /** |
||
279 | * current getter |
||
280 | * |
||
281 | * @return bool |
||
282 | */ |
||
283 | 5 | public function getCurrent(): bool |
|
287 | |||
288 | /** |
||
289 | * comment setter |
||
290 | * |
||
291 | * @param string $comment the branch comment |
||
292 | */ |
||
293 | public function setComment(string $comment): void |
||
297 | |||
298 | /** |
||
299 | * comment getter |
||
300 | * |
||
301 | * @return string |
||
302 | */ |
||
303 | 1 | public function getComment(): string |
|
307 | |||
308 | /** |
||
309 | * fullref setter |
||
310 | * |
||
311 | * @param string $fullRef full git reference of the branch |
||
312 | */ |
||
313 | public function setFullRef(string $fullRef): void |
||
317 | |||
318 | /** |
||
319 | * fullRef getter |
||
320 | * |
||
321 | * @return string |
||
322 | */ |
||
323 | 2 | public function getFullRef(): string |
|
327 | } |
||
328 |