From 923f198a1f433d34e16f42fed104bc65a9272844 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 19 Jun 2020 15:08:01 +0200 Subject: [PATCH] Fix default-branch attribute on package files, and add it to schema --- res/composer-schema.json | 4 ++++ src/Composer/Package/Dumper/ArrayDumper.php | 2 +- src/Composer/Package/Loader/ArrayLoader.php | 4 ++-- src/Composer/Repository/VcsRepository.php | 12 ++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/res/composer-schema.json b/res/composer-schema.json index 165ffcf85..04db6d3a3 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -565,6 +565,10 @@ "type": "string" } }, + "default-branch": { + "type": ["boolean"], + "description": "Internal use only, do not specify this in composer.json. Indicates whether this version is the default branch of the linked VCS repository. Defaults to false." + }, "abandoned": { "type": ["boolean", "string"], "description": "Indicates whether this package has been abandoned, it can be boolean or a package name/URL pointing to a recommended alternative. Defaults to false." diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 84af84778..903997601 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -96,7 +96,7 @@ class ArrayDumper } if ($package->isDefaultBranch()) { - $data['default_branch'] = true; + $data['default-branch'] = true; } $data = $this->dumpValues($package, $keys, $data); diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 314019e17..b2330e6e2 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -124,7 +124,7 @@ class ArrayLoader implements LoaderInterface $package->setInstallationSource($config['installation-source']); } - if (isset($config['default_branch']) && $config['default_branch'] === true) { + if (isset($config['default-branch']) && $config['default-branch'] === true) { $package->setIsDefaultBranch(true); } @@ -368,7 +368,7 @@ class ArrayLoader implements LoaderInterface } } - if (isset($config['default_branch']) && $config['default_branch'] === true) { + if (isset($config['default-branch']) && $config['default-branch'] === true) { return VersionParser::DEV_MASTER_ALIAS; } } diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index d63623ccb..f3d7fe56b 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -231,8 +231,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']); $data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']); - // make sure tag do not contain the default_branch marker - unset($data['default_branch']); + // make sure tag do not contain the default-branch marker + unset($data['default-branch']); // broken package, version doesn't match tag if ($data['version_normalized'] !== $parsedTag) { @@ -337,9 +337,9 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt $data['version'] = $version; $data['version_normalized'] = $parsedBranch; - unset($data['default_branch']); + unset($data['default-branch']); if ($driver->getRootIdentifier() === $branch) { - $data['default_branch'] = true; + $data['default-branch'] = true; } if ($isVeryVerbose) { @@ -446,9 +446,9 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt $this->io->overwriteError($msg, false); } - unset($cachedPackage['default_branch']); + unset($cachedPackage['default-branch']); if ($isDefaultBranch) { - $cachedPackage['default_branch'] = true; + $cachedPackage['default-branch'] = true; } if ($existingPackage = $this->findPackage($cachedPackage['name'], new Constraint('=', $cachedPackage['version_normalized']))) {