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\Runner\Action\Cli\Command\Placeholder; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Git; |
15
|
|
|
use CaptainHook\App\Hook\FileList; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Changed Files Placeholder |
19
|
|
|
* |
20
|
|
|
* This placeholder only works for pre-push, post-rewrite, post-checkout and post-merge actions. |
21
|
|
|
* If it is used in a pre-push hook and multiple refs are pushed the placeholder will contain |
22
|
|
|
* all changed files for all refs. |
23
|
|
|
* |
24
|
|
|
* Usage examples: |
25
|
|
|
* - {$BRANCH_FILES|compare-to:main|separated-by:,} |
26
|
|
|
* - {$BRANCH_FILES|in-dir:foo/bar} |
27
|
|
|
* - {$BRANCH_FILES|of-type:php} |
28
|
|
|
* |
29
|
|
|
* @package CaptainHook |
30
|
|
|
* @author Sebastian Feldmann <[email protected]> |
31
|
|
|
* @link https://github.com/captainhook-git/captainhook |
32
|
|
|
* @since Class available since Release 5.21.0 |
33
|
|
|
*/ |
34
|
|
|
class BranchFiles extends Foundation |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @param array<string, string> $options |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
5 |
|
public function replacement(array $options): string |
41
|
|
|
{ |
42
|
5 |
|
$branch = $this->repository->getInfoOperator()->getCurrentBranch(); |
43
|
5 |
|
$start = $options['compared-to'] ?? $this->repository->getLogOperator()->getBranchRevFromRefLog($branch); |
44
|
|
|
|
45
|
5 |
|
if (empty($start)) { |
46
|
1 |
|
$this->io->write('could not find branch start'); |
47
|
1 |
|
return ''; |
48
|
|
|
} |
49
|
4 |
|
$files = $this->repository->getLogOperator()->getChangedFilesSince($start, ['A', 'C', 'M', 'R']); |
50
|
|
|
|
51
|
4 |
|
return implode(($options['separated-by'] ?? ' '), FileList::filter($files, $options)); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|