@@ -152,15 +152,22 @@ public function install( $args, $assoc_args ) {
152152 if ( preg_match ( '#github\.com/([^/]+)/([^/]+)/releases/download/# ' , $ local_or_remote_zip_file ) || preg_match ( '#github\.com/([^/]+)/([^/]+)/raw/# ' , $ local_or_remote_zip_file ) ) {
153153 return $ source ;
154154 }
155- $ branch_length = strlen ( pathinfo ( $ local_or_remote_zip_file , PATHINFO_FILENAME ) );
156- if ( $ branch_length ) {
157- $ new_path = substr ( rtrim ( $ source , '/ ' ), 0 , - ( $ branch_length + 1 ) ) . '/ ' ;
158- if ( $ GLOBALS ['wp_filesystem ' ]->move ( $ source , $ new_path ) ) {
159- WP_CLI ::log ( "Renamed Github-based project from ' " . Utils \basename ( $ source ) . "' to ' " . Utils \basename ( $ new_path ) . "'. " );
160- return $ new_path ;
161- } else {
162- return new \WP_Error ( 'wpcli_install_gitub ' , "Couldn't move Github-based project to appropriate directory. " );
163- }
155+
156+ $ branch_name = pathinfo ( $ local_or_remote_zip_file , PATHINFO_FILENAME );
157+
158+ // Always be attached "archive" into release tag and tag on github.
159+ if ( preg_match ( '#github\.com/([^/]+)/([^/]+)/archive/# ' , $ local_or_remote_zip_file ) ) {
160+ $ path_array = explode ( "/ " , pathinfo ( $ local_or_remote_zip_file , PATHINFO_DIRNAME ) );
161+ array_pop ( $ path_array );
162+ $ branch_name = end ( $ path_array );
163+ }
164+
165+ $ new_path = str_replace ( pathinfo ( $ source , PATHINFO_BASENAME ), $ branch_name , $ source );
166+ if ( $ GLOBALS ['wp_filesystem ' ]->move ( $ source , $ new_path ) ) {
167+ WP_CLI ::log ( "Renamed Github-based project from ' " . Utils \basename ( $ source ) . "' to ' " . Utils \basename ( $ new_path ) . "'. " );
168+ return $ new_path ;
169+ } else {
170+ return new \WP_Error ( 'wpcli_install_github ' , "Couldn't move Github-based project to appropriate directory. " );
164171 }
165172 return $ source ;
166173 };
0 commit comments