Skip to content

Commit ee8847f

Browse files
authored
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 b6f3410 commit ee8847f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Merge/ExtraPackage.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ protected function prependRepositories(RootPackageInterface $root)
202202
$repoManager = $this->composer->getRepositoryManager();
203203
$newRepos = array();
204204

205-
foreach ($this->json['repositories'] as $repoJson) {
205+
$namedIndex = false;
206+
foreach ($this->json['repositories'] as $repoKey => $repoJson) {
206207
if (!isset($repoJson['type'])) {
207208
continue;
208209
}
@@ -212,14 +213,21 @@ protected function prependRepositories(RootPackageInterface $root)
212213
$repoJson
213214
);
214215
$repoManager->prependRepository($repo);
215-
$newRepos[] = $repo;
216+
217+
if (is_numeric($repoKey)) {
218+
$newRepos[] = $repo;
219+
}
220+
else {
221+
// Indexed repository name.
222+
$newRepos[$repoKey] = $repo;
223+
$namedIndex = true;
224+
}
216225
}
217226

218227
$unwrapped = self::unwrapIfNeeded($root, 'setRepositories');
219-
$unwrapped->setRepositories(array_merge(
220-
$newRepos,
221-
$root->getRepositories()
222-
));
228+
$repositories = $root->getRepositories();
229+
$repositories = $namedIndex ? ($newRepos + $repositories) : array_merge($newRepos, $repositories);
230+
$unwrapped->setRepositories($repositories);
223231
}
224232

225233
/**

0 commit comments

Comments
 (0)