1 | <?php |
||
17 | class Scripts |
||
18 | { |
||
19 | const BACKUP_EXTENSION = '.bak'; |
||
20 | |||
21 | const GIT_PATH = '.git'; |
||
22 | |||
23 | const HOOKS_PATH = 'hooks'; |
||
24 | |||
25 | const HOOK_FILENAME = 'commit-msg'; |
||
26 | |||
27 | const TEMPLATE_FILENAME = '.gitmessage'; |
||
28 | |||
29 | /** |
||
30 | * Default Permissions (Copied from example hooks). |
||
31 | * |
||
32 | * User: Read, Write, Execute |
||
33 | * Group: Read, Execute |
||
34 | * Other: Execute |
||
35 | */ |
||
36 | const EXECUTABLE_PERMISSIONS = 0751; |
||
37 | |||
38 | const HOOK_CONTENTS = <<<'CONTENT' |
||
39 | #!/bin/sh |
||
40 | |||
41 | vendor/bin/git-lint-validators git-lint-validator:hook $1 |
||
42 | CONTENT; |
||
43 | |||
44 | const TEMPLATE_CONTENTS = <<<'CONTENT' |
||
45 | Subject line |
||
46 | |||
47 | # - Capitalise the subject line and do not end it with a period |
||
48 | # - Use the imperative mood in the subject line |
||
49 | # - Summarise changes in around 50 (soft limit, hard limit at 69) |
||
50 | # characters or less in the subject line |
||
51 | # - Separate subject line from body with a blank line |
||
52 | Subject body |
||
53 | # - Use the subject body to explain what and why vs. how |
||
54 | # - Wrap the subject body at 72 characters |
||
55 | |||
56 | CONTENT; |
||
57 | |||
58 | /** |
||
59 | * Installs and activates the Git commit message |
||
60 | * hook when confirmed by the user. An existing hook |
||
61 | * is backed with the .bak extension. |
||
62 | * |
||
63 | * @param Event $event The script event |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | public static function installGitMessageHook(Event $event) |
||
116 | |||
117 | /** |
||
118 | * Installs and configures the Git commit message |
||
119 | * template when confirmed by the user. |
||
120 | * |
||
121 | * @param Event $event The script event |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public static function installGitCommitMessageTemplate(Event $event) |
||
164 | |||
165 | /** |
||
166 | * Returns the .git directory if present. Errors the given |
||
167 | * message if not. |
||
168 | * |
||
169 | * @param string $message The message to error |
||
170 | * @param IOInterface $inputOutput The Input/Output helper interface |
||
171 | * |
||
172 | * @return false|string |
||
173 | */ |
||
174 | private static function getGuardedGitDirectory($message, IOInterface $inputOutput) |
||
186 | } |
||
187 |