@@ -66,6 +66,11 @@ class ComposerPlugin implements PluginInterface, EventSubscriberInterface
66
66
*/
67
67
private $ gitDirectory ;
68
68
69
+ /**
70
+ * @var bool
71
+ */
72
+ private $ isWorktree = false ;
73
+
69
74
/**
70
75
* Activate the plugin
71
76
*
@@ -145,6 +150,10 @@ public function installHooks(Event $event): void
145
150
146
151
$ this ->detectConfiguration ();
147
152
$ this ->detectGitDir ();
153
+ if ($ this ->isWorktree ) {
154
+ $ this ->io ->write (' <comment>ARRRRR! We ARRR in a worktree, no install attempted</comment> ' );
155
+ return ;
156
+ }
148
157
$ this ->detectCaptainExecutable ();
149
158
150
159
if (!file_exists ($ this ->executable )) {
@@ -274,6 +283,15 @@ private function detectGitDir(): void
274
283
if (is_dir ($ possibleGitDir )) {
275
284
$ this ->gitDirectory = $ possibleGitDir ;
276
285
return ;
286
+ } elseif (is_file ($ possibleGitDir )) {
287
+ $ gitfile = file ($ possibleGitDir );
288
+ $ match = [];
289
+ preg_match ('#^gitdir: (?<gitdir>[a-zA-Z/\.]*\.git)# ' , $ gitfile [0 ] ?? '' , $ match );
290
+ $ dir = $ match ['gitdir ' ] ?? '' ;
291
+ if (is_dir ($ dir )) {
292
+ $ this ->isWorktree = true ;
293
+ }
294
+
277
295
}
278
296
279
297
// if we checked the root directory already, break to prevent endless loop
@@ -283,6 +301,9 @@ private function detectGitDir(): void
283
301
284
302
$ path = \dirname ($ path );
285
303
}
304
+ if ($ this ->isWorktree ) {
305
+ return ;
306
+ }
286
307
throw new RuntimeException ($ this ->pluginErrorMessage ('git directory not found ' ));
287
308
}
288
309
0 commit comments