Skip to content

Commit

Permalink
Plugin Directory: SVN: Add SVN::copy().
Browse files Browse the repository at this point in the history
See #343.
See #407.


git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14314 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
dd32 committed Dec 18, 2024
1 parent a25e1d9 commit 74a0578
Showing 1 changed file with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,54 @@ public static function log( $url, $revision = 'HEAD', $options = array() ) {
* }
*/
public static function rename( $from, $to, $options = array() ) {
return SVN::_copy_rename_helper( 'mv', $from, $to, $options );
}

/**
* Copy a file or folder in a SVN checkout.
*
* @static
*
* @param string $source The path of the file to copy. May be a URL.
* @param string $destination The path to copy the file to. May be a URL.
* @param array $options Optional. A list of options to pass to SVN. Default: empty array.
* @return array {
* @type bool $result The result of the operation.
* @type int $revision The revision.
* @type false|array $errors Whether any errors or warnings were encountered.
* }
*/
public static function copy( $from, $to, $options = array() ) {
return SVN::_copy_rename_helper( 'cp', $from, $to, $options = array() );
}

/**
* Helper function for copy and rename operations.
*
* @static
* @param string $svn_op The SVN operation to perform. 'cp' or 'mv'.
* @param string $from The path of the SVN folder to rename. May be a URL.
* @param string $to The new path of the SVN folder. May be a URL.
* @param array $options Optional. A list of options to pass to SVN. Default: empty array.
* @return array {
* @type bool $result The result of the operation.
* @type int $revision The revision.
* @type false|array $errors Whether any errors or warnings were encountered.
* }
*/
public static function _copy_rename_helper( $svn_op, $from, $to, $options = array() ) {
$options[] = 'non-interactive';
$is_url = ( preg_match( '#https?://#i', $from ) && preg_match( '#https?://#i', $to ) );

if ( $is_url ) {
// Set the message if not provided.
if ( ! isset( $options['message'] ) && ! isset( $options['m'] ) ) {
$options['message'] = sprintf( "Rename %s to %s.", basename( $from ), basename( $to ) );
$options['message'] = sprintf(
"%s %s to %s.",
'mv' === $svn_op ? 'Rename' : 'Copy',
basename( $from ),
basename( $to )
);
}

if ( empty( $options['username'] ) ) {
Expand All @@ -462,10 +503,11 @@ public static function rename( $from, $to, $options = array() ) {

$esc_options = self::parse_esc_parameters( $options );

$esc_op = escapeshellarg( $svn_op );
$esc_from = escapeshellarg( $from );
$esc_to = escapeshellarg( $to );

$output = self::shell_exec( "svn mv $esc_from $esc_to $esc_options 2>&1" );
$output = self::shell_exec( "svn $esc_op $esc_from $esc_to $esc_options 2>&1" );
if ( $is_url && preg_match( '/Committed revision (?P<revision>\d+)[.]/i', $output, $m ) ) {
$revision = (int) $m['revision'];
$result = true;
Expand Down

0 comments on commit 74a0578

Please sign in to comment.