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\Hook\Condition; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO; |
15
|
|
|
use CaptainHook\App\Hook\Restriction; |
16
|
|
|
use CaptainHook\App\Hooks; |
17
|
|
|
use SebastianFeldmann\Git\Repository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class FileChange |
21
|
|
|
* |
22
|
|
|
* @package CaptainHook |
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
24
|
|
|
* @link https://github.com/captainhookphp/captainhook |
25
|
|
|
* @since Class available since Release 5.2.0 |
26
|
|
|
*/ |
27
|
|
|
abstract class FileStaged extends File |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* List of file to watch |
31
|
|
|
* |
32
|
|
|
* @var array<string> |
33
|
|
|
*/ |
34
|
|
|
protected $filesToWatch; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* FileChange constructor |
38
|
|
|
* |
39
|
|
|
* @param array<string> $files |
40
|
|
|
*/ |
41
|
|
|
public function __construct(array $files) |
42
|
|
|
{ |
43
|
|
|
$this->filesToWatch = $files; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Return the hook restriction information |
48
|
|
|
* |
49
|
|
|
* @return \CaptainHook\App\Hook\Restriction |
50
|
|
|
*/ |
51
|
|
|
public static function getRestriction(): Restriction |
52
|
|
|
{ |
53
|
|
|
return Restriction::fromArray([Hooks::PRE_COMMIT]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Evaluates a condition |
58
|
|
|
* |
59
|
|
|
* @param \CaptainHook\App\Console\IO $io |
60
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
abstract public function isTrue(IO $io, Repository $repository): bool; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Use 'diff-index --cached' to find the staged files before the commit |
67
|
|
|
* |
68
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
69
|
|
|
* @return array<string> |
70
|
|
|
*/ |
71
|
|
|
protected function getStagedFiles(Repository $repository) |
72
|
|
|
{ |
73
|
|
|
return $repository->getIndexOperator()->getStagedFiles(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|