diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 765e73f4f..0a7ac10a9 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -39,6 +39,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt protected $repoConfig; protected $branchErrorOccurred = false; private $drivers; + /** @var VcsDriverInterface */ + private $driver; public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null) { @@ -75,32 +77,33 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt public function getDriver() { + if ($this->driver) { + return $this->driver; + } + if (isset($this->drivers[$this->type])) { $class = $this->drivers[$this->type]; - $driver = new $class($this->repoConfig, $this->io, $this->config); - /** @var VcsDriverInterface $driver */ - $driver->initialize(); + $this->driver = new $class($this->repoConfig, $this->io, $this->config); + $this->driver->initialize(); - return $driver; + return $this->driver; } foreach ($this->drivers as $driver) { if ($driver::supports($this->io, $this->config, $this->url)) { - $driver = new $driver($this->repoConfig, $this->io, $this->config); - /** @var VcsDriverInterface $driver */ - $driver->initialize(); + $this->driver = new $driver($this->repoConfig, $this->io, $this->config); + $this->driver->initialize(); - return $driver; + return $this->driver; } } foreach ($this->drivers as $driver) { if ($driver::supports($this->io, $this->config, $this->url, true)) { - $driver = new $driver($this->repoConfig, $this->io, $this->config); - /** @var VcsDriverInterface $driver */ - $driver->initialize(); + $this->driver = new $driver($this->repoConfig, $this->io, $this->config); + $this->driver->initialize(); - return $driver; + return $this->driver; } } }