1 | <?php |
||
7 | class HookCopier |
||
8 | { |
||
9 | public const DEFAULT_GIT_HOOKS_DIR = '.git/hooks'; |
||
10 | |||
11 | protected $hooksDir = self::DEFAULT_GIT_HOOKS_DIR; |
||
12 | protected $sourceHooksDir = __DIR__ . '/../../../../Infrastructure/Hook'; |
||
13 | |||
14 | public function copyPreCommitHook(): void |
||
15 | { |
||
16 | $this->copyHookFile('pre-commit'); |
||
17 | } |
||
18 | |||
19 | public function copyCommitMsgHook(): void |
||
20 | { |
||
21 | $this->copyHookFile('commit-msg'); |
||
22 | } |
||
23 | |||
24 | public function copyPrePushHook(): void |
||
25 | { |
||
26 | $this->copyHookFile('pre-push'); |
||
27 | } |
||
28 | |||
29 | public function copyPrepareCommitMsgHook(): void |
||
30 | { |
||
31 | $this->copyHookFile('prepare-commit-msg'); |
||
32 | } |
||
33 | |||
34 | protected function hookExists(string $hookFile): bool |
||
35 | { |
||
36 | return file_exists(sprintf('%s%s', $this->hooksDir, $hookFile)); |
||
37 | } |
||
38 | |||
39 | protected function copyFile(string $hookFile): void |
||
44 | |||
45 | protected function setPermissions(string $hookFile): void |
||
46 | { |
||
47 | $permissions = new Process(sprintf('chmod 775 %s%s', $this->hooksDir, $hookFile)); |
||
48 | $permissions->run(); |
||
49 | } |
||
50 | |||
51 | protected function copyHookFile(string $file): void |
||
58 | } |
||
59 |