|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of CaptainHook. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace CaptainHook\App\Console\Command\Hook; |
|
11
|
|
|
|
|
12
|
|
|
use CaptainHook\App\Config; |
|
13
|
|
|
use CaptainHook\App\Console\Command\Hook; |
|
14
|
|
|
use CaptainHook\App\Console\IO; |
|
15
|
|
|
use CaptainHook\App\Hooks; |
|
16
|
|
|
use SebastianFeldmann\Git; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class PrepareCommitMessage |
|
23
|
|
|
* |
|
24
|
|
|
* @package CaptainHook |
|
25
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
26
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
|
27
|
|
|
* @since Class available since Release 3.0.1 |
|
28
|
|
|
*/ |
|
29
|
|
|
class PrepareCommitMsg extends Hook |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Hook to execute |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $hookName = Hooks::PREPARE_COMMIT_MSG; |
|
37
|
|
|
|
|
38
|
|
|
private $file; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Configure the command. |
|
42
|
|
|
*/ |
|
43
|
1 |
|
protected function configure() |
|
44
|
|
|
{ |
|
45
|
1 |
|
parent::configure(); |
|
46
|
1 |
|
$this->addArgument('file', InputArgument::REQUIRED, 'File containing the commit log message'); |
|
47
|
1 |
|
$this->addArgument('mode', InputArgument::OPTIONAL, 'Current commit mode'); |
|
48
|
1 |
|
$this->addArgument('hash', InputArgument::OPTIONAL, 'Given commit hash'); |
|
49
|
1 |
|
} |
|
50
|
|
|
/** |
|
51
|
|
|
* Read the commit message from file. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
54
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
55
|
|
|
* @param \CaptainHook\App\Config $config |
|
56
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
|
57
|
|
|
*/ |
|
58
|
1 |
|
protected function setup(InputInterface $input, OutputInterface $output, Config $config, Git\Repository $repository) |
|
59
|
|
|
{ |
|
60
|
1 |
|
$this->file = $input->getArgument('file'); |
|
61
|
|
|
|
|
62
|
1 |
|
$gitConfig = $repository->getConfigOperator(); |
|
63
|
1 |
|
$commentCharacter = $gitConfig->getSafely('core.commentchar', '#'); |
|
64
|
|
|
|
|
65
|
1 |
|
$repository->setCommitMsg(Git\CommitMessage::createFromFile($this->file, $commentCharacter)); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
1 |
|
parent::setup($input, $output, $config, $repository); |
|
68
|
1 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function teardown(IO $io, Config $config, Git\Repository $repository) |
|
71
|
|
|
{ |
|
72
|
|
|
file_put_contents($this->file, $repository->getCommitMsg()->getRawContent()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.