Skip to content

Commit 4b5f4b0

Browse files
committed
Load repository configuration from config file and change option name
Option is now --repository-url, because it better describes expected value. If repository URL is not found in configuration, an exception is thrown, to ensure consistency of partial builds with full build.
1 parent 86cb7f1 commit 4b5f4b0

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/Composer/Satis/Command/BuildCommand.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function configure()
5050
new InputArgument('output-dir', InputArgument::OPTIONAL, 'Location where to output built files', null),
5151
new InputOption('no-html-output', null, InputOption::VALUE_NONE, 'Turn off HTML view'),
5252
new InputOption('skip-errors', null, InputOption::VALUE_NONE, 'Skip Download or Archive errors'),
53-
new InputOption('repository', null, InputOption::VALUE_OPTIONAL, 'Only update the given repository', null),
53+
new InputOption('repository-url', null, InputOption::VALUE_OPTIONAL, 'Only update the repository at given url', null),
5454
))
5555
->setHelp(<<<EOT
5656
The <info>build</info> command reads the given json file
@@ -130,18 +130,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
130130
}
131131

132132

133-
if ($input->getOption('repository') !== null) {
134-
$singleRepository = $input->getOption('repository');
133+
if (($singleRepositoryUrl = $input->getOption('repository-url')) !== null
134+
&& FALSE !== ($otherPackagesCache = @file_get_contents($outputDir.'/packages.cache')))
135+
{
136+
$singleRepositoryUrl = $input->getOption('repository-url');
135137

136-
$otherPackages = unserialize(file_get_contents($outputDir.'/packages.cache'));
137-
unset($config['repositories']);
138-
$config['repositories'] = array(
139-
array('type' => 'vcs', 'url' => $singleRepository),
140-
);
138+
$otherPackages = unserialize($otherPackagesCache);
139+
140+
// find repository configuration
141+
$singleRepositoryConfig = null;
142+
foreach ($config['repositories'] as $r) {
143+
if ($r['url'] == $singleRepositoryUrl) {
144+
$singleRepositoryConfig = $r;
145+
break;
146+
}
147+
}
148+
if ($singleRepositoryConfig === null) {
149+
throw new \InvalidArgumentException('Requested repository not found in configuration: '.$singleRepositoryUrl);
150+
}
151+
152+
// use only selected repository
153+
$config['repositories'] = array($singleRepositoryConfig);
141154

142155
$composer = $this->getApplication()->getComposer(true, $config);
143156
$packages = $this->selectPackages($composer, $output, $verbose, $requireAll, $requireDependencies);
144157

158+
// merge with cached data
145159
$packages = array_merge($otherPackages, $packages);
146160
ksort($packages, SORT_STRING);
147161
} else {

0 commit comments

Comments
 (0)