File tree Expand file tree Collapse file tree 3 files changed +30
-12
lines changed Expand file tree Collapse file tree 3 files changed +30
-12
lines changed Original file line number Diff line number Diff line change 15
15
16
16
use CaptainHook \App \CH ;
17
17
use CaptainHook \App \Hook \Template ;
18
+ use CaptainHook \App \Hooks ;
18
19
use SebastianFeldmann \Camino \Path ;
19
20
use SebastianFeldmann \Camino \Path \Directory ;
20
21
use Symfony \Component \Process \PhpExecutableFinder ;
21
22
22
23
/**
23
- * Local class
24
+ * Shell class
24
25
*
25
26
* Generates the sourcecode for the php hook scripts in .git/hooks/*.
26
27
*
31
32
*/
32
33
class Shell extends Template \Local
33
34
{
34
- /**
35
- * Does the hook allow user input
36
- *
37
- * @var bool[]
38
- */
39
- private array $ allowUserInput = [
40
- 'prepare-commit-msg ' => true
41
- ];
42
-
43
35
/**
44
36
* Returns lines of code for the local src installation
45
37
*
@@ -51,7 +43,7 @@ protected function getHookLines(string $hook): array
51
43
$ useStdIn = ' <&0 ' ;
52
44
$ useTTY = [];
53
45
54
- if (isset ( $ this -> allowUserInput [ $ hook] )) {
46
+ if (Hooks:: allowsUserInput ( $ hook )) {
55
47
$ useStdIn = '' ;
56
48
$ useTTY = [
57
49
'if [ -t 1 ]; then ' ,
Original file line number Diff line number Diff line change @@ -51,12 +51,21 @@ final class Hooks
51
51
*
52
52
* @var string[]
53
53
*/
54
- private static $ virtualHookTriggers = [
54
+ private static array $ virtualHookTriggers = [
55
55
self ::POST_CHECKOUT => self ::POST_CHANGE ,
56
56
self ::POST_MERGE => self ::POST_CHANGE ,
57
57
self ::POST_REWRITE => self ::POST_CHANGE ,
58
58
];
59
59
60
+ /**
61
+ * Is it necessary to give the Captain access to user input
62
+ *
63
+ * @var array<string, bool>
64
+ */
65
+ private static array $ hooksAllowingUserInput = [
66
+ self ::PREPARE_COMMIT_MSG => true ,
67
+ ];
68
+
60
69
/**
61
70
* Returns the list of valid hooks
62
71
*
@@ -137,6 +146,17 @@ public static function getOriginalHookArguments(string $hook): string
137
146
return $ arguments [$ hook ];
138
147
}
139
148
149
+ /**
150
+ * Does a given hook allow for user input to be used
151
+ *
152
+ * @param string $hook
153
+ * @return bool
154
+ */
155
+ public static function allowsUserInput (string $ hook ): bool
156
+ {
157
+ return self ::$ hooksAllowingUserInput [$ hook ] ?? false ;
158
+ }
159
+
140
160
/**
141
161
* Tell if the given hook should trigger a virtual hook
142
162
*
Original file line number Diff line number Diff line change @@ -63,4 +63,10 @@ public function testGetVirtualHookFail(): void
63
63
$ this ->expectException (Exception::class);
64
64
Hooks::getVirtualHook ('pre-commit ' );
65
65
}
66
+
67
+ public function testAllowsUserInput (): void
68
+ {
69
+ $ this ->assertTrue (Hooks::allowsUserInput (Hooks::PREPARE_COMMIT_MSG ));
70
+ $ this ->assertFalse (Hooks::allowsUserInput (Hooks::PRE_COMMIT ));
71
+ }
66
72
}
You can’t perform that action at this time.
0 commit comments