Skip to content

Commit 2aebca0

Browse files
committed
Update ExtraPackage.php
Add ability to override indexed repositories. e.g. ``` "repositories": { "privaterepo": { "type": "vcs", "url": "https://github.com/mycompany/privaterepo" }, "repo": { "type": "vcs", "url": "http://svn.example.org/private/repo" }, "privaterepo2": { "type": "vcs", "url": "https://github.com/mycompany/privaterepo2" } } ```
1 parent 1d8842f commit 2aebca0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/ExtraPackage.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ protected function prependRepositories(RootPackageInterface $root)
214214
$repoManager = $this->composer->getRepositoryManager();
215215
$newRepos = [];
216216

217-
foreach ($this->json['repositories'] as $repoJson) {
217+
$namedIndex = false;
218+
foreach ($this->json['repositories'] as $repoKey => $repoJson) {
218219
if (!isset($repoJson['type'])) {
219220
continue;
220221
}
@@ -224,14 +225,21 @@ protected function prependRepositories(RootPackageInterface $root)
224225
$repoJson
225226
);
226227
$repoManager->prependRepository($repo);
227-
$newRepos[] = $repo;
228+
229+
if (is_numeric($repoKey)) {
230+
$newRepos[] = $repo;
231+
}
232+
else {
233+
// Indexed repository name.
234+
$newRepos[$repoKey] = $repo;
235+
$namedIndex = true;
236+
}
228237
}
229238

230239
$unwrapped = self::unwrapIfNeeded($root, 'setRepositories');
231-
$unwrapped->setRepositories(array_merge(
232-
$newRepos,
233-
$root->getRepositories()
234-
));
240+
$repositories = $root->getRepositories();
241+
$repositories = $namedIndex ? ($newRepos + $repositories) : array_merge($newRepos, $repositories);
242+
$unwrapped->setRepositories($repositories);
235243
}
236244

237245
/**

0 commit comments

Comments
 (0)