@@ -210,6 +210,21 @@ public function install( $args, $assoc_args ) {
210210 preg_match ( '#([^:\/]+\/[^\/]+)\.git# ' , $ package_name , $ matches );
211211 if ( ! empty ( $ matches [1 ] ) ) {
212212 $ package_name = $ matches [1 ];
213+
214+ // Generate raw git URL of composer.json file.
215+ $ raw_content_url = 'https://raw.githubusercontent.com/ ' . $ package_name . '/master/composer.json ' ;
216+
217+ // Convert composer.json JSON to Array.
218+ $ composer_content_as_array = json_decode ( WP_CLI \Utils \http_request ( 'GET ' , $ raw_content_url )->body , true );
219+
220+ // Package name in composer.json that is hosted on GitHub.
221+ $ package_name_on_repo = $ composer_content_as_array ['name ' ];
222+
223+ // If package name and repository name are not identical, then fix it.
224+ if ( $ package_name !== $ package_name_on_repo ) {
225+ $ package_name = $ package_name_on_repo ;
226+ WP_CLI ::warning ( 'Package name mismatch...Updating the name with correct value. ' );
227+ }
213228 } else {
214229 WP_CLI ::error ( "Couldn't parse package name from expected path '<name>/<package>'. " );
215230 }
@@ -282,7 +297,6 @@ public function install( $args, $assoc_args ) {
282297 WP_CLI ::log ( sprintf ( 'Registering %s as a path repository... ' , $ dir_package ) );
283298 $ json_manipulator ->addRepository ( $ package_name , array ( 'type ' => 'path ' , 'url ' => $ dir_package ) );
284299 }
285-
286300 $ composer_backup_decoded = json_decode ( $ composer_backup , true );
287301 // If the composer file does not contain the current package index repository, refresh the repository definition.
288302 if ( empty ( $ composer_backup_decoded ['repositories ' ]['wp-cli ' ]['url ' ] ) || self ::PACKAGE_INDEX_URL != $ composer_backup_decoded ['repositories ' ]['wp-cli ' ]['url ' ] ) {
@@ -300,7 +314,6 @@ public function install( $args, $assoc_args ) {
300314 // Set up the EventSubscriber
301315 $ event_subscriber = new \WP_CLI \PackageManagerEventSubscriber ;
302316 $ composer ->getEventDispatcher ()->addSubscriber ( $ event_subscriber );
303-
304317 // Set up the installer
305318 $ install = Installer ::create ( new ComposerIO , $ composer );
306319 $ install ->setUpdate ( true ); // Installer class will only override composer.lock with this flag
0 commit comments