@@ -66,6 +66,11 @@ class ComposerPlugin implements PluginInterface, EventSubscriberInterface
6666 */
6767 private $ gitDirectory ;
6868
69+ /**
70+ * @var bool
71+ */
72+ private $ isWorktree = false ;
73+
6974 /**
7075 * Activate the plugin
7176 *
@@ -145,6 +150,10 @@ public function installHooks(Event $event): void
145150
146151 $ this ->detectConfiguration ();
147152 $ this ->detectGitDir ();
153+ if ($ this ->isWorktree ) {
154+ $ this ->io ->write (' <comment>ARRRRR! We ARRR in a worktree, no install attempted</comment> ' );
155+ return ;
156+ }
148157 $ this ->detectCaptainExecutable ();
149158
150159 if (!file_exists ($ this ->executable )) {
@@ -274,6 +283,15 @@ private function detectGitDir(): void
274283 if (is_dir ($ possibleGitDir )) {
275284 $ this ->gitDirectory = $ possibleGitDir ;
276285 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+
277295 }
278296
279297 // if we checked the root directory already, break to prevent endless loop
@@ -283,6 +301,9 @@ private function detectGitDir(): void
283301
284302 $ path = \dirname ($ path );
285303 }
304+ if ($ this ->isWorktree ) {
305+ return ;
306+ }
286307 throw new RuntimeException ($ this ->pluginErrorMessage ('git directory not found ' ));
287308 }
288309
0 commit comments