From 3c08318ea0613eb52311d13a1133c0faa01bf003 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 18 Sep 2015 15:31:54 +0200 Subject: [PATCH] Add test --- src/Composer/Installer.php | 12 +++- .../update-picks-up-change-of-vcs-type.test | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/update-picks-up-change-of-vcs-type.test diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 667d60d96..eacc0fe0e 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -1023,9 +1023,15 @@ class Installer $newPackage = $pool->literalToPackage($matches[0]); // update the dist and source URLs - $package->setSourceType($newPackage->getSourceType()); - $package->setSourceUrl($newPackage->getSourceUrl()); - $package->setSourceReference($newPackage->getSourceReference()); + $sourceUrl = $package->getSourceUrl(); + $newSourceUrl = $newPackage->getSourceUrl(); + + if ($sourceUrl !== $newSourceUrl) { + $package->setSourceType($newPackage->getSourceType()); + $package->setSourceUrl($newSourceUrl); + $package->setSourceReference($newPackage->getSourceReference()); + } + // only update dist url for github/bitbucket dists as they use a combination of dist url + dist reference to install // but for other urls this is ambiguous and could result in bad outcomes if (preg_match('{^https?://(?:(?:www\.)?bitbucket\.org|(api\.)?github\.com)/}', $newPackage->getDistUrl())) { diff --git a/tests/Composer/Test/Fixtures/installer/update-picks-up-change-of-vcs-type.test b/tests/Composer/Test/Fixtures/installer/update-picks-up-change-of-vcs-type.test new file mode 100644 index 000000000..1e528d047 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-picks-up-change-of-vcs-type.test @@ -0,0 +1,57 @@ +--TEST-- +Converting from one VCS type to another (including an URL change) should update the lock file. +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { + "name": "a/a", "version": "1.0.0", + "source": { "reference": "new-git-ref", "type": "git", "url": "new-git-url" } + } + ] + } + ], + "require": { + "a/a": "1.0.0" + } +} +--INSTALLED-- +[ + { + "name": "a/a", "version": "1.0.0", + "source": { "reference": "old-hg-ref", "type": "hg", "url": "old-hg-url" } + } +] +--LOCK-- +{ + "packages": [ + { + "name": "a/a", "version": "1.0.0", + "source": { "reference": "old-hg-ref", "type": "hg", "url": "old-hg-url" } + } + ] +} +--RUN-- +update +--EXPECT-LOCK-- +{ + "packages": [ + { + "name": "a/a", "version": "1.0.0", + "source": { "reference": "new-git-ref", "type": "git", "url": "new-git-url" }, + "type": "library" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} +--EXPECT-- +