From 1c012b74a62c9c6f27cad291a1bc2eb000804b1e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 1 Nov 2019 17:20:09 +0100 Subject: [PATCH 01/12] Update dependencies --- composer.lock | 88 +++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/composer.lock b/composer.lock index ca55827ee..0580c0b1b 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "composer/ca-bundle", - "version": "1.2.3", + "version": "1.2.4", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "f26a67e397be0e5c00d7c52ec7b5010098e15ce5" + "reference": "10bb96592168a0f8e8f6dcde3532d9fa50b0b527" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/f26a67e397be0e5c00d7c52ec7b5010098e15ce5", - "reference": "f26a67e397be0e5c00d7c52ec7b5010098e15ce5", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/10bb96592168a0f8e8f6dcde3532d9fa50b0b527", + "reference": "10bb96592168a0f8e8f6dcde3532d9fa50b0b527", "shasum": "" }, "require": { @@ -60,7 +60,7 @@ "ssl", "tls" ], - "time": "2019-08-02T09:05:43+00:00" + "time": "2019-08-30T08:44:50+00:00" }, { "name": "composer/semver", @@ -230,23 +230,23 @@ }, { "name": "justinrainbow/json-schema", - "version": "5.2.8", + "version": "5.2.9", "source": { "type": "git", "url": "https://github.com/justinrainbow/json-schema.git", - "reference": "dcb6e1006bb5fd1e392b4daa68932880f37550d4" + "reference": "44c6787311242a979fa15c704327c20e7221a0e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/dcb6e1006bb5fd1e392b4daa68932880f37550d4", - "reference": "dcb6e1006bb5fd1e392b4daa68932880f37550d4", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/44c6787311242a979fa15c704327c20e7221a0e4", + "reference": "44c6787311242a979fa15c704327c20e7221a0e4", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20", + "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", "json-schema/json-schema-test-suite": "1.2.0", "phpunit/phpunit": "^4.8.35" }, @@ -292,20 +292,20 @@ "json", "schema" ], - "time": "2019-01-14T23:55:14+00:00" + "time": "2019-09-25T14:49:45+00:00" }, { "name": "psr/log", - "version": "1.1.0", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" + "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", - "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801", + "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801", "shasum": "" }, "require": { @@ -314,7 +314,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -339,20 +339,20 @@ "psr", "psr-3" ], - "time": "2018-11-20T15:27:04+00:00" + "time": "2019-11-01T11:05:21+00:00" }, { "name": "seld/jsonlint", - "version": "1.7.1", + "version": "1.7.2", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "d15f59a67ff805a44c50ea0516d2341740f81a38" + "reference": "e2e5d290e4d2a4f0eb449f510071392e00e10d19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/d15f59a67ff805a44c50ea0516d2341740f81a38", - "reference": "d15f59a67ff805a44c50ea0516d2341740f81a38", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/e2e5d290e4d2a4f0eb449f510071392e00e10d19", + "reference": "e2e5d290e4d2a4f0eb449f510071392e00e10d19", "shasum": "" }, "require": { @@ -388,7 +388,7 @@ "parser", "validator" ], - "time": "2018-01-24T12:46:19+00:00" + "time": "2019-10-24T14:27:39+00:00" }, { "name": "seld/phar-utils", @@ -653,16 +653,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -674,7 +674,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -690,13 +690,13 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -707,20 +707,20 @@ "polyfill", "portable" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609" + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609", - "reference": "fe5e94c604826c35a32fa832f35bd036b6799609", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/b42a2f66e8f1b15ccf25652c3424265923eb4f17", + "reference": "b42a2f66e8f1b15ccf25652c3424265923eb4f17", "shasum": "" }, "require": { @@ -732,7 +732,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -766,7 +766,7 @@ "portable", "shim" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/process", @@ -924,22 +924,22 @@ }, { "name": "phpspec/prophecy", - "version": "1.8.1", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", - "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203", + "reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, @@ -983,7 +983,7 @@ "spy", "stub" ], - "time": "2019-06-13T12:50:23+00:00" + "time": "2019-10-03T11:07:50+00:00" }, { "name": "phpunit/php-code-coverage", From f7f7883a5ed62b3e0a26533e3afb3730fdfa54d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 3 Nov 2019 14:04:38 +0100 Subject: [PATCH 02/12] Fix: Xdebug vs xdebug --- .travis.yml | 2 +- CHANGELOG.md | 4 ++-- bin/composer | 2 +- doc/articles/troubleshooting.md | 4 ++-- src/Composer/Console/Application.php | 2 +- src/Composer/Repository/PlatformRepository.php | 2 +- tests/Composer/Test/ApplicationTest.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2e3270b65..e741d1678 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,7 @@ matrix: - php: 7.4snapshot before_install: - # disable xdebug if available + # disable Xdebug if available - phpenv config-rm xdebug.ini || echo "xdebug not available" # disable default memory limit - export INI=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini diff --git a/CHANGELOG.md b/CHANGELOG.md index ade8d99cd..1daf5f097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -252,7 +252,7 @@ * Fixed output inconsistencies * Fixed unicode handling in `init` command for author names * Fixed useless warning when doing partial updates/removes on packages that are not currently installed - * Fixed xdebug disabling issue when combined with disable_functions and allow_url_fopen CLI overrides + * Fixed Xdebug disabling issue when combined with disable_functions and allow_url_fopen CLI overrides ### [1.4.1] - 2017-03-10 @@ -313,7 +313,7 @@ * Added `gitlab-token` auth config for GitLab private tokens * Added `--strict` to the `outdated` command to return a non-zero exit code when there are outdated packages * Added ability to call php scripts using the current php interpreter (instead of finding php in PATH by default) in script handlers via `@php ...` - * Added `COMPOSER_ALLOW_XDEBUG` env var to circumvent the xdebug-disabling behavior + * Added `COMPOSER_ALLOW_XDEBUG` env var to circumvent the Xdebug-disabling behavior * Added `COMPOSER_MIRROR_PATH_REPOS` env var to force mirroring of path repositories vs symlinking * Added `COMPOSER_DEV_MODE` env var that is set by Composer to forward the dev mode to script handlers * Fixed support for git 2.11 diff --git a/bin/composer b/bin/composer index 3585787f2..b7ab5318b 100755 --- a/bin/composer +++ b/bin/composer @@ -13,7 +13,7 @@ use Composer\XdebugHandler\XdebugHandler; error_reporting(-1); -// Restart without xdebug +// Restart without Xdebug $xdebug = new XdebugHandler('Composer', '--ansi'); $xdebug->check(); unset($xdebug); diff --git a/doc/articles/troubleshooting.md b/doc/articles/troubleshooting.md index 7a5725ec4..33471cd53 100644 --- a/doc/articles/troubleshooting.md +++ b/doc/articles/troubleshooting.md @@ -156,10 +156,10 @@ This issue can also happen on cPanel instances, when the shell fork bomb protect ## Xdebug impact on Composer -To improve performance when the xdebug extension is enabled, Composer automatically restarts PHP without it. +To improve performance when the Xdebug extension is enabled, Composer automatically restarts PHP without it. You can override this behavior by using an environment variable: `COMPOSER_ALLOW_XDEBUG=1`. -Composer will always show a warning if xdebug is being used, but you can override this with an environment variable: +Composer will always show a warning if Xdebug is being used, but you can override this with an environment variable: `COMPOSER_DISABLE_XDEBUG_WARN=1`. If you see this warning unexpectedly, then the restart process has failed: please report this [issue](https://github.com/composer/composer/issues). diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index e45ea8027..15167af9c 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -205,7 +205,7 @@ class Application extends BaseApplication } if (extension_loaded('xdebug') && !getenv('COMPOSER_DISABLE_XDEBUG_WARN')) { - $io->writeError('You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug'); + $io->writeError('You are running composer with Xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug'); } if (defined('COMPOSER_DEV_WARNING_TIME') && $commandName !== 'self-update' && $commandName !== 'selfupdate' && time() > COMPOSER_DEV_WARNING_TIME) { diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 3126f860a..265cdbf4a 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -125,7 +125,7 @@ class PlatformRepository extends ArrayRepository $this->addExtension($name, $prettyVersion); } - // Check for xdebug in a restarted process + // Check for Xdebug in a restarted process if (!in_array('xdebug', $loadedExtensions, true) && ($prettyVersion = XdebugHandler::getSkippedVersion())) { $this->addExtension('xdebug', $prettyVersion); } diff --git a/tests/Composer/Test/ApplicationTest.php b/tests/Composer/Test/ApplicationTest.php index 97921950f..85ae6840e 100644 --- a/tests/Composer/Test/ApplicationTest.php +++ b/tests/Composer/Test/ApplicationTest.php @@ -62,7 +62,7 @@ class ApplicationTest extends TestCase $outputMock->expects($this->at($index++)) ->method("write") - ->with($this->equalTo('You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug')); + ->with($this->equalTo('You are running composer with Xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug')); } $outputMock->expects($this->at($index++)) From f4ff91da6c06379e2c6d46f0a0fd3aa1f1911adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 3 Nov 2019 14:23:09 +0100 Subject: [PATCH 03/12] Fix: Add environment variables related to Xdebug to documentation --- doc/03-cli.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/03-cli.md b/doc/03-cli.md index 8cfd5cac0..d73f5a81e 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -808,6 +808,10 @@ If set to 1, this env disables the warning about running commands as root/super It also disables automatic clearing of sudo sessions, so you should really only set this if you use Composer as super user at all times like in docker containers. +### COMPOSER_ALLOW_XDEBUG + +If set to 1, this env allows running Composer when the Xdebug extension is enabled, without restarting PHP without it. + ### COMPOSER_AUTH The `COMPOSER_AUTH` var allows you to set up authentication as an environment variable. @@ -833,6 +837,10 @@ By default it points to `$COMPOSER_HOME/cache` on \*nix and macOS, and By setting this environmental value, you can set a path to a certificate bundle file to be used during SSL/TLS peer verification. +### COMPOSER_DISABLE_XDEBUG_WARN + +If set to 1, this env suppresses a warning when Composer is running with the Xdebug extension enabled. + ### COMPOSER_DISCARD_CHANGES This env var controls the [`discard-changes`](06-config.md#discard-changes) config option. From 7e649fac41d844835bc86e1131dde465366cc0df Mon Sep 17 00:00:00 2001 From: johnstevenson Date: Thu, 7 Nov 2019 09:53:22 +0000 Subject: [PATCH 04/12] Fix Windows test regression from commit 149250a Commit: 149250ab92feadd9fe045b54d6e42f33d185a595 ProcessExecutor::escape handled a false value inconsistently across platforms, returning an emtpy string on Windows, otherwise `''`. This is fixed to return `""` on Windows. The GitDownloaderTest code has been appropriately updated. --- src/Composer/Util/ProcessExecutor.php | 2 +- tests/Composer/Test/Downloader/GitDownloaderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index d72a02981..00b2e7547 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -155,7 +155,7 @@ class ProcessExecutor //@see https://bugs.php.net/bug.php?id=43784 //@see https://bugs.php.net/bug.php?id=49446 if ('\\' === DIRECTORY_SEPARATOR) { - if ('' === $argument) { + if ((string) $argument === '') { return escapeshellarg($argument); } diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index cd3375464..9ff169925 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -734,7 +734,7 @@ composer https://github.com/old/url (push) $cmd = str_replace('cd ', 'cd /D ', $cmd); $cmd = str_replace('composerPath', getcwd().'/composerPath', $cmd); - return str_replace('""', '', strtr($cmd, "'", '"')); + return strtr($cmd, "'", '"'); } return $cmd; From 6c9e2d0b3f4365b4bc92b826b1f94b2b1f5374cf Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 16 Nov 2019 17:46:49 +0100 Subject: [PATCH 05/12] Allow Symfony 5 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index da7e2e8cd..b99d064fc 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,10 @@ "psr/log": "^1.0", "seld/jsonlint": "^1.4", "seld/phar-utils": "^1.0", - "symfony/console": "^2.7 || ^3.0 || ^4.0", - "symfony/filesystem": "^2.7 || ^3.0 || ^4.0", - "symfony/finder": "^2.7 || ^3.0 || ^4.0", - "symfony/process": "^2.7 || ^3.0 || ^4.0" + "symfony/console": "^2.7 || ^3.0 || ^4.0 || ^5.0", + "symfony/filesystem": "^2.7 || ^3.0 || ^4.0 || ^5.0", + "symfony/finder": "^2.7 || ^3.0 || ^4.0 || ^5.0", + "symfony/process": "^2.7 || ^3.0 || ^4.0 || ^5.0" }, "conflict": { "symfony/console": "2.8.38" From b09fef659ba0a8c1d09b0f4da280807c4bd343f6 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Sat, 16 Nov 2019 17:58:39 +0100 Subject: [PATCH 06/12] Update composer.lock --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index aaec0a2d7..9ec942d61 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "617f7e5e1a6d8429c246415ec685bd90", + "content-hash": "ffd75ce76e2044a19a68b4e363cf4308", "packages": [ { "name": "composer/ca-bundle", From f8010d5220d94d26ce3a05cc191d5d0a1d8e82dc Mon Sep 17 00:00:00 2001 From: Michael Thessel Date: Wed, 20 Nov 2019 14:58:28 -0800 Subject: [PATCH 07/12] Improved hasPackage() performance --- src/Composer/Repository/ArrayRepository.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index 4f0409a60..815bc0087 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -28,6 +28,7 @@ class ArrayRepository extends BaseRepository { /** @var PackageInterface[] */ protected $packages; + protected $packageMap; public function __construct(array $packages = array()) { @@ -121,15 +122,13 @@ class ArrayRepository extends BaseRepository */ public function hasPackage(PackageInterface $package) { - $packageId = $package->getUniqueName(); - - foreach ($this->getPackages() as $repoPackage) { - if ($packageId === $repoPackage->getUniqueName()) { - return true; + if (empty($this->packageMap)) { + foreach ($this->getPackages() as $repoPackage) { + $this->packageMap[$repoPackage->getUniqueName()] = $repoPackage; } } - return false; + return isset($this->packageMap[$package->getUniqueName()]); } /** From 96af98370093c18ebd9ad7e1cdb4b021da73f4b0 Mon Sep 17 00:00:00 2001 From: Michael Thessel Date: Thu, 21 Nov 2019 10:08:09 -0800 Subject: [PATCH 08/12] Fixed map initialization --- src/Composer/Repository/ArrayRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index 815bc0087..3d9e22d14 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -122,7 +122,8 @@ class ArrayRepository extends BaseRepository */ public function hasPackage(PackageInterface $package) { - if (empty($this->packageMap)) { + if ($this->packageMap === null) { + $this->packageMap = array(); foreach ($this->getPackages() as $repoPackage) { $this->packageMap[$repoPackage->getUniqueName()] = $repoPackage; } From a9fec9b9725e7b122ed93239c9a1461506835e13 Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Thu, 21 Nov 2019 23:00:29 +0100 Subject: [PATCH 09/12] Fix language. --- doc/06-config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/06-config.md b/doc/06-config.md index 6ffbea411..0f110a428 100644 --- a/doc/06-config.md +++ b/doc/06-config.md @@ -260,7 +260,7 @@ driver directly, Composer will still attempt to use GitHub's zip files. Defaults to `true`. Composer allows repositories to define a notification URL, so that they get notified whenever a package from that repository is installed. -This option allows you to disable that behaviour. +This option allows you to disable that behavior. ## discard-changes From b8471156175c2133df61432b4455b709cbfc33f9 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Thu, 7 Nov 2019 00:43:19 +0100 Subject: [PATCH 10/12] Git: fix authentication handling for private GitHub repositories --- src/Composer/Util/Git.php | 6 +- tests/Composer/Test/Util/GitTest.php | 145 +++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 tests/Composer/Test/Util/GitTest.php diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index 15c46d080..81c685011 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -85,7 +85,9 @@ class Git } // failed to checkout, first check git accessibility - $this->throwException('Failed to clone ' . $url . ' via ' . implode(', ', $protocols) . ' protocols, aborting.' . "\n\n" . implode("\n", $messages), $url); + if (!$this->io->hasAuthentication($match[1]) && !$this->io->isInteractive()) { + $this->throwException('Failed to clone ' . $url . ' via ' . implode(', ', $protocols) . ' protocols, aborting.' . "\n\n" . implode("\n", $messages), $url); + } } // if we have a private github url and the ssh protocol is disabled then we skip it and directly fallback to https @@ -97,7 +99,7 @@ class Git if ($bypassSshForGitHub || 0 !== $this->process->execute($command, $ignoredOutput, $cwd)) { // private github repository without ssh key access, try https with auth if (preg_match('{^git@' . self::getGitHubDomainsRegex($this->config) . ':(.+?)\.git$}i', $url, $match) - || preg_match('{^(https?)://' . self::getGitHubDomainsRegex($this->config) . '/(.*)}', $url, $match) + || preg_match('{^https?://' . self::getGitHubDomainsRegex($this->config) . '/(.*)}', $url, $match) ) { if (!$this->io->hasAuthentication($match[1])) { $gitHubUtil = new GitHub($this->io, $this->config, $this->process); diff --git a/tests/Composer/Test/Util/GitTest.php b/tests/Composer/Test/Util/GitTest.php new file mode 100644 index 000000000..7aa66be12 --- /dev/null +++ b/tests/Composer/Test/Util/GitTest.php @@ -0,0 +1,145 @@ +io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); + $this->config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock(); + $this->process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->disableOriginalConstructor()->getMock(); + $this->fs = $this->getMockBuilder('Composer\Util\Filesystem')->disableOriginalConstructor()->getMock(); + $this->git = new Git($this->io, $this->config, $this->process, $this->fs); + } + + /** + * @dataProvider publicGithubNoCredentialsProvider + */ + public function testRunCommandPublicGitHubRepositoryNotInitialClone($protocol, $expectedUrl) + { + $that = $this; + $commandCallable = function ($url) use ($that, $expectedUrl) { + $that->assertSame($expectedUrl, $url); + + return 'git command'; + }; + + $this->mockConfig($protocol); + + $this->process + ->expects($this->once()) + ->method('execute') + ->with($this->equalTo('git command')) + ->willReturn(0); + + $this->git->runCommand($commandCallable, 'https://github.com/acme/repo', null, true); + } + + public function publicGithubNoCredentialsProvider() + { + return array( + array('ssh', 'git@github.com:acme/repo'), + array('https', 'https://github.com/acme/repo'), + ); + } + + /** + * @expectedException \RuntimeException + */ + public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithoutAuthentication() + { + $that = $this; + $commandCallable = function ($url) use ($that) { + $that->assertSame('https://github.com/acme/repo', $url); + + return 'git command'; + }; + + $this->mockConfig('https'); + + $this->process + ->method('execute') + ->willReturnMap(array( + array('git command', null, null, 1), + array('git --version', null, null, 0), + )); + + $this->git->runCommand($commandCallable, 'https://github.com/acme/repo', null, true); + } + + /** + * @dataProvider privateGithubWithCredentialsProvider + */ + public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithAuthentication($gitUrl, $protocol, $gitHubToken, $expectedUrl) + { + $commandCallable = function ($url) use ($expectedUrl) { + if ($url !== $expectedUrl) { + return 'git command failing'; + } + + return 'git command ok'; + }; + + $this->mockConfig($protocol); + + $this->process + ->method('execute') + ->willReturnMap(array( + array('git command failing', null, null, 1), + array('git command ok', null, null, 0), + )); + + $this->io + ->method('isInteractive') + ->willReturn(false); + + $this->io + ->method('hasAuthentication') + ->with($this->equalTo('github.com')) + ->willReturn(true); + + $this->io + ->method('getAuthentication') + ->with($this->equalTo('github.com')) + ->willReturn(array('username' => 'token', 'password' => $gitHubToken)); + + $this->git->runCommand($commandCallable, $gitUrl, null, true); + } + + public function privateGithubWithCredentialsProvider() + { + return array( + array('git@github.com:acme/repo.git', 'ssh', 'MY_GITHUB_TOKEN', 'https://token:MY_GITHUB_TOKEN@github.com/acme/repo.git'), + array('https://github.com/acme/repo', 'https', 'MY_GITHUB_TOKEN', 'https://token:MY_GITHUB_TOKEN@github.com/acme/repo.git'), + ); + } + + private function mockConfig($protocol) + { + $this->config + ->method('get') + ->willReturnMap(array( + array('github-domains', 0, array('github.com')), + array('github-protocols', 0, array($protocol)), + )); + } +} From 44cdc37c0cb7023dbdd2e124f65a5b544f2650d2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 23 Nov 2019 12:07:29 +0100 Subject: [PATCH 11/12] Invalidate map cache when addPackage/removePackage is called --- src/Composer/Repository/ArrayRepository.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index 3d9e22d14..c11c7fe68 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -28,6 +28,10 @@ class ArrayRepository extends BaseRepository { /** @var PackageInterface[] */ protected $packages; + + /** + * @var PackageInterface[] indexed by package unique name and used to cache hasPackage calls + */ protected $packageMap; public function __construct(array $packages = array()) @@ -151,6 +155,9 @@ class ArrayRepository extends BaseRepository $this->addPackage($aliasedPackage); } } + + // invalidate package map cache + $this->packageMap = null; } protected function createAliasPackage(PackageInterface $package, $alias, $prettyAlias) @@ -171,6 +178,9 @@ class ArrayRepository extends BaseRepository if ($packageId === $repoPackage->getUniqueName()) { array_splice($this->packages, $key, 1); + // invalidate package map cache + $this->packageMap = null; + return; } } From 0bd3f27693530e41b98d7b835adf37302bc6e968 Mon Sep 17 00:00:00 2001 From: Cyril VERLOOP Date: Sat, 16 Nov 2019 16:17:49 +0100 Subject: [PATCH 12/12] Do not show commit signature for git log. --- src/Composer/Repository/Vcs/GitDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 4a14974fb..cc6e3edb4 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -143,7 +143,7 @@ class GitDriver extends VcsDriver public function getChangeDate($identifier) { $this->process->execute(sprintf( - 'git log -1 --format=%%at %s', + 'git -c log.showSignature=false log -1 --format=%%at %s', ProcessExecutor::escape($identifier) ), $output, $this->repoDir);