Skip to content

Commit

Permalink
Merge pull request #18 from f1r3ph03n1xX
Browse files Browse the repository at this point in the history
Prevent error output if we are in a git worktree
  • Loading branch information
sebastianfeldmann committed Oct 14, 2021
2 parents 56e889e + c39d594 commit 4d33939
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class ComposerPlugin implements PluginInterface, EventSubscriberInterface
*/
private $gitDirectory;

/**
* @var bool
*/
private $isWorktree = false;

/**
* Activate the plugin
*
Expand Down Expand Up @@ -145,6 +150,10 @@ public function installHooks(Event $event): void

$this->detectConfiguration();
$this->detectGitDir();
if ($this->isWorktree) {
$this->io->write(' <comment>ARRRRR! We ARRR in a worktree, no install attempted</comment>');
return;
}
$this->detectCaptainExecutable();

if (!file_exists($this->executable)) {
Expand Down Expand Up @@ -274,6 +283,15 @@ private function detectGitDir(): void
if (is_dir($possibleGitDir)) {
$this->gitDirectory = $possibleGitDir;
return;
} elseif (is_file($possibleGitDir)) {
$gitfile = file($possibleGitDir);
$match = [];
preg_match('#^gitdir: (?<gitdir>[a-zA-Z/\.]*\.git)#', $gitfile[0] ?? '', $match);
$dir = $match['gitdir'] ?? '';
if (is_dir($dir)) {
$this->isWorktree = true;
}

}

// if we checked the root directory already, break to prevent endless loop
Expand All @@ -283,6 +301,9 @@ private function detectGitDir(): void

$path = \dirname($path);
}
if ($this->isWorktree) {
return;
}
throw new RuntimeException($this->pluginErrorMessage('git directory not found'));
}

Expand Down

0 comments on commit 4d33939

Please sign in to comment.