Skip to content

Commit

Permalink
Fix lock file generation with dev-master aliases to be compatible wit…
Browse files Browse the repository at this point in the history
…h Composer 1, fixes #9337
  • Loading branch information
Seldaek committed Oct 27, 2020
1 parent 44dc3c2 commit ff74d0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/Composer/Package/Locker.php
Expand Up @@ -19,6 +19,7 @@
use Composer\Util\ProcessExecutor;
use Composer\Package\Dumper\ArrayDumper;
use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Version\VersionParser;
use Composer\Plugin\PluginInterface;
use Composer\Util\Git as GitUtil;
use Composer\IO\IOInterface;
Expand Down Expand Up @@ -309,6 +310,15 @@ public function getLockData()
*/
public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags, $preferStable, $preferLowest, array $platformOverrides, $write = true)
{
// keep old default branch names normalized to DEFAULT_BRANCH_ALIAS for BC as that is how Composer 1 outputs the lock file
// when loading the lock file the version is anyway ignored in Composer 2, so it has no adverse effect
$aliases = array_map(function ($alias) {
if (in_array($alias['version'], array('dev-master', 'dev-trunk', 'dev-default'), true)) {
$alias['version'] = VersionParser::DEFAULT_BRANCH_ALIAS;
}
return $alias;
}, $aliases);

$lock = array(
'_readme' => array('This file locks the dependencies of your project to a known state',
'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies',
Expand Down Expand Up @@ -343,7 +353,6 @@ public function setLockData(array $packages, $devPackages, array $platformReqs,
if (!$isLocked || $lock !== $this->getLockData()) {
if ($write) {
$this->lockFile->write($lock);
// $this->lockDataCache = JsonFile::parseJson(JsonFile::encode($lock, 448 & JsonFile::JSON_PRETTY_PRINT));
$this->lockDataCache = null;
$this->virtualFileWritten = false;
} else {
Expand Down
Expand Up @@ -45,7 +45,7 @@ update
"packages-dev": [],
"aliases": [{
"package": "a/aliased",
"version": "dev-master",
"version": "9999999-dev",
"alias": "1.0.0",
"alias_normalized": "1.0.0.0"
}],
Expand Down
Expand Up @@ -44,7 +44,7 @@ Verify that a partial update with deps correctly keeps track of all aliases.
{
"alias": "1.1.0",
"alias_normalized": "1.1.0.0",
"version": "dev-master",
"version": "9999999-dev",
"package": "current/dep"
}
],
Expand All @@ -70,13 +70,13 @@ update new/pkg --with-all-dependencies
{
"alias": "1.1.0",
"alias_normalized": "1.1.0.0",
"version": "dev-master",
"version": "9999999-dev",
"package": "current/dep"
},
{
"alias": "1.1.2",
"alias_normalized": "1.1.2.0",
"version": "dev-master",
"version": "9999999-dev",
"package": "current/dep2"
}
],
Expand Down

0 comments on commit ff74d0e

Please sign in to comment.