ソースを参照

Display source/dist refs if updates do not change the version

We now output an update when only a source or dist ref changes even if
it's a stable version so in these cases the output needs to contain the
ref to make it clear to users what changed
Nils Adermann 5 年 前
コミット
a732ea5dd8

+ 1 - 1
src/Composer/DependencyResolver/Operation/InstallOperation.php

@@ -61,7 +61,7 @@ class InstallOperation extends SolverOperation
      */
     public function show($lock)
     {
-        return ($lock ? 'Locking ' : 'Installing ').$this->package->getPrettyName().' ('.$this->formatVersion($this->package).')';
+        return ($lock ? 'Locking ' : 'Installing ').$this->package->getPrettyName().' ('.$this->package->getFullPrettyVersion().')';
     }
 
     /**

+ 1 - 1
src/Composer/DependencyResolver/Operation/MarkAliasInstalledOperation.php

@@ -62,7 +62,7 @@ class MarkAliasInstalledOperation extends SolverOperation
      */
     public function show($lock)
     {
-        return 'Marking '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).') as installed, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->formatVersion($this->package->getAliasOf()).')';
+        return 'Marking '.$this->package->getPrettyName().' ('.$this->package->getFullPrettyVersion().') as installed, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->package->getAliasOf()->getFullPrettyVersion().')';
     }
 
     /**

+ 1 - 1
src/Composer/DependencyResolver/Operation/MarkAliasUninstalledOperation.php

@@ -62,7 +62,7 @@ class MarkAliasUninstalledOperation extends SolverOperation
      */
     public function show($lock)
     {
-        return 'Marking '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).') as uninstalled, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->formatVersion($this->package->getAliasOf()).')';
+        return 'Marking '.$this->package->getPrettyName().' ('.$this->package->getFullPrettyVersion().') as uninstalled, alias of '.$this->package->getAliasOf()->getPrettyName().' ('.$this->package->getAliasOf()->getFullPrettyVersion().')';
     }
 
     /**

+ 0 - 5
src/Composer/DependencyResolver/Operation/SolverOperation.php

@@ -48,9 +48,4 @@ abstract class SolverOperation implements OperationInterface
     * @return string
     */
     abstract public function show($lock);
-
-    protected function formatVersion(PackageInterface $package)
-    {
-        return $package->getFullPrettyVersion();
-    }
 }

+ 1 - 1
src/Composer/DependencyResolver/Operation/UninstallOperation.php

@@ -61,7 +61,7 @@ class UninstallOperation extends SolverOperation
      */
     public function show($lock)
     {
-        return 'Uninstalling '.$this->package->getPrettyName().' ('.$this->formatVersion($this->package).')';
+        return 'Uninstalling '.$this->package->getPrettyName().' ('.$this->package->getFullPrettyVersion().')';
     }
 
     /**

+ 12 - 1
src/Composer/DependencyResolver/Operation/UpdateOperation.php

@@ -74,7 +74,18 @@ class UpdateOperation extends SolverOperation
      */
     public function show($lock)
     {
-        return 'Updating '.$this->initialPackage->getPrettyName().' ('.$this->formatVersion($this->initialPackage).' => '.$this->formatVersion($this->targetPackage).')';
+        $fromVersion = $this->initialPackage->getFullPrettyVersion();
+        $toVersion = $this->targetPackage->getFullPrettyVersion();
+
+        if ($fromVersion === $toVersion && $this->initialPackage->getSourceReference() !== $this->targetPackage->getSourceReference()) {
+            $fromVersion = $this->initialPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_SOURCE_REF);
+            $toVersion = $this->targetPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_SOURCE_REF);
+        } elseif ($fromVersion === $toVersion && $this->initialPackage->getDistReference() !== $this->targetPackage->getDistReference()) {
+            $fromVersion = $this->initialPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_DIST_REF);
+            $toVersion = $this->targetPackage->getFullPrettyVersion(true, PackageInterface::DISPLAY_DIST_REF);
+        }
+
+        return 'Updating '.$this->initialPackage->getPrettyName().' ('.$fromVersion.' => '.$toVersion.')';
     }
 
     /**

+ 17 - 5
src/Composer/Package/BasePackage.php

@@ -210,18 +210,30 @@ abstract class BasePackage implements PackageInterface
     /**
      * {@inheritDoc}
      */
-    public function getFullPrettyVersion($truncate = true)
+    public function getFullPrettyVersion($truncate = true, $displayMode = PackageInterface::DISPLAY_SOURCE_REF_IF_DEV)
     {
-        if (!$this->isDev() || !in_array($this->getSourceType(), array('hg', 'git'))) {
+        if ($displayMode === PackageInterface::DISPLAY_SOURCE_REF_IF_DEV &&
+            (!$this->isDev() || !in_array($this->getSourceType(), array('hg', 'git')))
+        ) {
             return $this->getPrettyVersion();
         }
 
+        switch ($displayMode) {
+            case PackageInterface::DISPLAY_SOURCE_REF_IF_DEV:
+            case PackageInterface::DISPLAY_SOURCE_REF:
+                $reference = $this->getSourceReference();
+                break;
+            case PackageInterface::DISPLAY_DIST_REF:
+                $reference = $this->getDistReference();
+                break;
+        }
+
         // if source reference is a sha1 hash -- truncate
-        if ($truncate && strlen($this->getSourceReference()) === 40) {
-            return $this->getPrettyVersion() . ' ' . substr($this->getSourceReference(), 0, 7);
+        if ($truncate && strlen($reference) === 40) {
+            return $this->getPrettyVersion() . ' ' . substr($reference, 0, 7);
         }
 
-        return $this->getPrettyVersion() . ' ' . $this->getSourceReference();
+        return $this->getPrettyVersion() . ' ' . $reference;
     }
 
     public function getStabilityPriority()

+ 6 - 1
src/Composer/Package/PackageInterface.php

@@ -21,6 +21,10 @@ use Composer\Repository\RepositoryInterface;
  */
 interface PackageInterface
 {
+    const DISPLAY_SOURCE_REF_IF_DEV = 0;
+    const DISPLAY_SOURCE_REF = 1;
+    const DISPLAY_DIST_REF = 2;
+
     /**
      * Returns the package's name without version info, thus not a unique identifier
      *
@@ -198,9 +202,10 @@ interface PackageInterface
      * @see getPrettyVersion
      *
      * @param  bool   $truncate If the source reference is a sha1 hash, truncate it
+     * @param  int    $displayMode One of the DISPLAY_ constants on this interface determining display of references
      * @return string version
      */
-    public function getFullPrettyVersion($truncate = true);
+    public function getFullPrettyVersion($truncate = true, $displayMode = self::DISPLAY_SOURCE_REF_IF_DEV);
 
     /**
      * Returns the release date of the package

+ 1 - 0
tests/Composer/Test/Fixtures/installer/update-changes-url.test

@@ -215,5 +215,6 @@ g/g is dev and installed in a different ref than the #ref, so it gets updated an
 update a/a b/b d/d g/g
 --EXPECT--
 Updating a/a (dev-master 1111111 => dev-master 2222222)
+Updating b/b (2.0.3 1111111 => 2.0.3 2222222)
 Installing e/e (dev-master 1111111)
 Updating g/g (dev-master 0000000 => dev-master 1111111)

+ 1 - 0
tests/Composer/Test/Fixtures/installer/update-installed-reference.test

@@ -28,3 +28,4 @@ Updating a dev package forcing it's reference should not do anything if the refe
 --RUN--
 update
 --EXPECT--
+Updating a/a (dev-master def000 => dev-master )

+ 1 - 1
tests/Composer/Test/Fixtures/installer/update-picks-up-change-of-vcs-type.test

@@ -62,4 +62,4 @@ update mirrors
     "platform-dev": []
 }
 --EXPECT--
-
+Updating a/a (1.0.0 old-hg-ref => 1.0.0 new-git-ref)