Completed
Push — master ( dde524...92e3a2 )
by Sebastian
06:05
created

CommitMsg::beforeHook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Runner\Hook;
11
12
use CaptainHook\App\Hooks;
13
use CaptainHook\App\Runner\Hook;
14
use SebastianFeldmann\Git;
15
16
/**
17
 * CommitMsg
18
 *
19
 * @package CaptainHook
20
 * @author  Sebastian Feldmann <[email protected]>
21
 * @link    https://github.com/sebastianfeldmann/captainhook
22
 * @since   Class available since Release 3.1.0
23
 */
24
class CommitMsg extends Hook
25
{
26
    /**
27
     * Hook to execute
28
     *
29
     * @var string
30
     */
31
    protected $hookName = Hooks::COMMIT_MSG;
32
33
    /**
34
     * Read the commit message from file.
35
     */
36
    public function beforeHook()
37
    {
38
        $commentChar   = $this->repository->getConfigOperator()->getSafely('core.commentchar', '#');
39
        $commitMessage = Git\CommitMessage::createFromFile((string)$this->arguments->get('file'), $commentChar);
40
41
        $this->repository->setCommitMsg($commitMessage);
42
43
        parent::beforeHook();
44
    }
45
}
46