1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of CaptainHook. |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Git\Range\Detector; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO; |
15
|
|
|
use CaptainHook\App\Git\Range\Detecting; |
16
|
|
|
use CaptainHook\App\Git\Range\PrePush as Range; |
17
|
|
|
use CaptainHook\App\Git\Rev\PrePush as Rev; |
18
|
|
|
use CaptainHook\App\Git\Rev\Util; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class to access the pre-push stdIn data |
22
|
|
|
* |
23
|
|
|
* @package CaptainHook |
24
|
|
|
* @author Sebastian Feldmann <[email protected]> |
25
|
|
|
* @link https://github.com/captainhookphp/captainhook |
26
|
|
|
* @since Class available since Release 5.15.0 |
27
|
|
|
*/ |
28
|
|
|
class PrePush implements Detecting |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Returns list of refs |
32
|
|
|
* |
33
|
|
|
* @param \CaptainHook\App\Console\IO $io |
34
|
|
|
* @return array<\CaptainHook\App\Git\Range\PrePush> |
35
|
|
|
*/ |
36
|
15 |
|
public function getRanges(IO $io): array |
37
|
|
|
{ |
38
|
15 |
|
return $this->createFromStdIn($io->getStandardInput()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Factory method |
43
|
|
|
* |
44
|
|
|
* @param array<string> $stdIn |
45
|
|
|
* @return array<\CaptainHook\App\Git\Range\PrePush> |
46
|
|
|
*/ |
47
|
15 |
|
private function createFromStdIn(array $stdIn): array |
48
|
|
|
{ |
49
|
15 |
|
$ranges = []; |
50
|
15 |
|
foreach ($stdIn as $line) { |
51
|
14 |
|
if (empty($line)) { |
52
|
1 |
|
continue; |
53
|
|
|
} |
54
|
|
|
|
55
|
13 |
|
[$localRef, $localHash, $remoteRef, $remoteHash] = explode(' ', trim($line)); |
56
|
|
|
|
57
|
13 |
|
$from = new Rev($remoteRef, $remoteHash, Util::extractBranchInfo($remoteRef)['branch']); |
58
|
13 |
|
$to = new Rev($localRef, $localHash, Util::extractBranchInfo($localRef)['branch']); |
59
|
13 |
|
$ranges[] = new Range($from, $to); |
60
|
|
|
} |
61
|
15 |
|
return $ranges; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|