@@ -445,13 +445,54 @@ public static function log( $url, $revision = 'HEAD', $options = array() ) {
445445 * }
446446 */
447447 public static function rename ( $ from , $ to , $ options = array () ) {
448+ return SVN ::_copy_rename_helper ( 'mv ' , $ from , $ to , $ options );
449+ }
450+
451+ /**
452+ * Copy a file or folder in a SVN checkout.
453+ *
454+ * @static
455+ *
456+ * @param string $source The path of the file to copy. May be a URL.
457+ * @param string $destination The path to copy the file to. May be a URL.
458+ * @param array $options Optional. A list of options to pass to SVN. Default: empty array.
459+ * @return array {
460+ * @type bool $result The result of the operation.
461+ * @type int $revision The revision.
462+ * @type false|array $errors Whether any errors or warnings were encountered.
463+ * }
464+ */
465+ public static function copy ( $ from , $ to , $ options = array () ) {
466+ return SVN ::_copy_rename_helper ( 'cp ' , $ from , $ to , $ options = array () );
467+ }
468+
469+ /**
470+ * Helper function for copy and rename operations.
471+ *
472+ * @static
473+ * @param string $svn_op The SVN operation to perform. 'cp' or 'mv'.
474+ * @param string $from The path of the SVN folder to rename. May be a URL.
475+ * @param string $to The new path of the SVN folder. May be a URL.
476+ * @param array $options Optional. A list of options to pass to SVN. Default: empty array.
477+ * @return array {
478+ * @type bool $result The result of the operation.
479+ * @type int $revision The revision.
480+ * @type false|array $errors Whether any errors or warnings were encountered.
481+ * }
482+ */
483+ public static function _copy_rename_helper ( $ svn_op , $ from , $ to , $ options = array () ) {
448484 $ options [] = 'non-interactive ' ;
449485 $ is_url = ( preg_match ( '#https?://#i ' , $ from ) && preg_match ( '#https?://#i ' , $ to ) );
450486
451487 if ( $ is_url ) {
452488 // Set the message if not provided.
453489 if ( ! isset ( $ options ['message ' ] ) && ! isset ( $ options ['m ' ] ) ) {
454- $ options ['message ' ] = sprintf ( "Rename %s to %s. " , basename ( $ from ), basename ( $ to ) );
490+ $ options ['message ' ] = sprintf (
491+ "%s %s to %s. " ,
492+ 'mv ' === $ svn_op ? 'Rename ' : 'Copy ' ,
493+ basename ( $ from ),
494+ basename ( $ to )
495+ );
455496 }
456497
457498 if ( empty ( $ options ['username ' ] ) ) {
@@ -462,10 +503,11 @@ public static function rename( $from, $to, $options = array() ) {
462503
463504 $ esc_options = self ::parse_esc_parameters ( $ options );
464505
506+ $ esc_op = escapeshellarg ( $ svn_op );
465507 $ esc_from = escapeshellarg ( $ from );
466508 $ esc_to = escapeshellarg ( $ to );
467509
468- $ output = self ::shell_exec ( "svn mv $ esc_from $ esc_to $ esc_options 2>&1 " );
510+ $ output = self ::shell_exec ( "svn $ esc_op $ esc_from $ esc_to $ esc_options 2>&1 " );
469511 if ( $ is_url && preg_match ( '/Committed revision (?P<revision>\d+)[.]/i ' , $ output , $ m ) ) {
470512 $ revision = (int ) $ m ['revision ' ];
471513 $ result = true ;
0 commit comments