|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Biurad opensource projects. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright 2022 Biurad Group (https://biurad.com/) |
|
7
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Biurad\Git; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Represents a git branch object. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class Branch extends Revision |
|
21
|
|
|
{ |
|
22
|
|
|
private bool $remote = false; |
|
23
|
|
|
|
|
24
|
|
|
public function isRemote(): bool |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->remote; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function isLocal(): bool |
|
30
|
|
|
{ |
|
31
|
|
|
return !$this->remote; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getRemoteName(): ?string |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->remote ? \explode('/', $this->name, 2)[1] : null; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param null|int $offset Start listing from a given position |
|
41
|
|
|
* @param null|int $limit Limit the fetched number of commits |
|
42
|
|
|
* |
|
43
|
|
|
* @return array<int,Commit> |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getCommits(int $offset = null, int $limit = null): array |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->repository->getLog($this->getName(), null, $offset, $limit)->getCommits(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
protected function doName(): string |
|
51
|
|
|
{ |
|
52
|
|
|
if (\str_starts_with($ref = $this->revision, 'refs/')) { |
|
53
|
|
|
$name = \substr($this->revision, 11); |
|
54
|
|
|
|
|
55
|
|
|
if (\str_starts_with($name, 's/')) { |
|
56
|
|
|
$this->remote = true; |
|
57
|
|
|
$name = \substr($name, 2); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $name; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// Maybe we should throw an exception here? I'm not sure. |
|
64
|
|
|
$this->revision = 'refs/heads/'.$this->revision; |
|
65
|
|
|
|
|
66
|
|
|
return $ref; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|