diff --git a/assets/js/revisr-staging.js b/assets/js/revisr-staging.js index c91b85f9..b4cfad70 100755 --- a/assets/js/revisr-staging.js +++ b/assets/js/revisr-staging.js @@ -45,6 +45,10 @@ jQuery(document).ready(function($) { $.post(ajaxurl, data, function(response) { document.getElementById('pending_files_result').innerHTML = response; + old_title = document.getElementById('title'); + new_title = document.getElementById('title-tmp'); + document.getElementById('titlewrap').replaceChild(new_title, old_title); + new_title.id = 'title'; }); } diff --git a/classes/class-revisr-admin-pages.php b/classes/class-revisr-admin-pages.php index e6e77e84..d07a996f 100644 --- a/classes/class-revisr-admin-pages.php +++ b/classes/class-revisr-admin-pages.php @@ -34,16 +34,16 @@ public function menus() { $this->page_hooks['menu'] = add_menu_page( __( 'Dashboard', 'revisr' ), __( 'Revisr', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ), $icon_svg ); $this->page_hooks['dashboard'] = add_submenu_page( 'revisr', __( 'Revisr - Dashboard', 'revisr' ), __( 'Dashboard', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ) ); $this->page_hooks['commits'] = add_submenu_page( 'revisr', __( 'Revisr - Commits', 'revisr' ), __( 'Commits', 'revisr' ), $cap, 'revisr_commits', array( $this, 'include_page' ) ); - $this->page_hooks['new_commit'] = add_submenu_page( NULL, __( 'Revisr - New Commit', 'revisr' ), __( 'New Commit', 'revisr' ), $cap, 'revisr_new_commit', array( $this, 'include_page' ) ); - $this->page_hooks['view_commit'] = add_submenu_page( NULL, __( 'Revisr - View Commit', 'revisr' ), __( 'View Commit', 'revisr' ), $cap, 'revisr_view_commit', array( $this, 'include_page' ) ); + $this->page_hooks['new_commit'] = add_submenu_page( 'admin', __( 'Revisr - New Commit', 'revisr' ), __( 'New Commit', 'revisr' ), $cap, 'revisr_new_commit', array( $this, 'include_page' ) ); + $this->page_hooks['view_commit'] = add_submenu_page( 'admin', __( 'Revisr - View Commit', 'revisr' ), __( 'View Commit', 'revisr' ), $cap, 'revisr_view_commit', array( $this, 'include_page' ) ); $this->page_hooks['branches'] = add_submenu_page( 'revisr', __( 'Revisr - Branches', 'revisr' ), __( 'Branches', 'revisr' ), $cap, 'revisr_branches', array( $this, 'include_page' ) ); $this->page_hooks['settings'] = add_submenu_page( 'revisr', __( 'Revisr - Settings', 'revisr' ), __( 'Settings', 'revisr' ), $cap, 'revisr_settings', array( $this, 'include_page' ) ); - $this->page_hooks['setup'] = add_submenu_page( NULL, __( 'Revisr - Setup', 'revisr' ), 'Revisr', $cap, 'revisr_setup', array( $this, 'include_page' ) ); + $this->page_hooks['setup'] = add_submenu_page( 'admin', __( 'Revisr - Setup', 'revisr' ), 'Revisr', $cap, 'revisr_setup', array( $this, 'include_page' ) ); } else { $this->page_hooks['setup'] = add_menu_page( __( 'Revisr Setup', 'revisr' ), __( 'Revisr', 'revisr' ), $cap, 'revisr_setup', array( $this, 'include_page' ), $icon_svg ); - $this->page_hooks['dashboard'] = add_submenu_page( null, __( 'Revisr - Dashboard', 'revisr' ), __( 'Dashboard', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ) ); - $this->page_hooks['branches'] = add_submenu_page( NULL, __( 'Revisr - Branches', 'revisr' ), __( 'Branches', 'revisr' ), $cap, 'revisr_branches', array( $this, 'include_page' ) ); - $this->page_hooks['settings'] = add_submenu_page( NULL, __( 'Revisr - Settings', 'revisr' ), __( 'Settings', 'revisr' ), $cap, 'revisr_settings', array( $this, 'include_page' ) ); + $this->page_hooks['dashboard'] = add_submenu_page( 'admin', __( 'Revisr - Dashboard', 'revisr' ), __( 'Dashboard', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ) ); + $this->page_hooks['branches'] = add_submenu_page( 'admin', __( 'Revisr - Branches', 'revisr' ), __( 'Branches', 'revisr' ), $cap, 'revisr_branches', array( $this, 'include_page' ) ); + $this->page_hooks['settings'] = add_submenu_page( 'admin', __( 'Revisr - Settings', 'revisr' ), __( 'Settings', 'revisr' ), $cap, 'revisr_settings', array( $this, 'include_page' ) ); } } @@ -277,6 +277,19 @@ public function site5_notice() { + + git_dir" ); $work_tree = Revisr_Admin::escapeshellarg( "--work-tree=$this->work_tree" ); + // Check for the special SSH key + exec( "stat ~/.ssh/id_github", $stat_output, $stat_return_code ); + $ssh_key = $stat_return_code === 0 ? "GIT_SSH_COMMAND='ssh -i ~/.ssh/id_github' " : ""; + // Run the command. chdir( $this->work_tree ); - exec( "$safe_path $git_dir $work_tree $safe_cmd $safe_args 2>&1", $output, $return_code ); + exec( "$ssh_key$safe_path $git_dir $work_tree $safe_cmd $safe_args 2>&1", $output, $return_code ); chdir( $this->current_dir ); // Process the response. @@ -355,6 +359,13 @@ public function count_unpushed( $ajax_btn = true ) { */ public function count_untracked() { $untracked = $this->run( 'status', array( '--short', '--untracked-files=all' ) ); + + foreach ( $untracked as $k => $v ) { + if ( stripos( $v, 'warning: ' ) === 0 ) { + unset( $untracked[$k] ); + } + } + return count( $untracked ); } @@ -622,7 +633,7 @@ public function merge( $branch ) { * @param array $commits The commits we're pulling (used in callback). */ public function pull( $commits = array() ) { - $this->reset(); + //$this->reset(); $pull = $this->run( 'pull', array( '-Xtheirs', '--quiet', $this->remote, $this->branch ), __FUNCTION__, $commits ); return $pull; } diff --git a/classes/class-revisr-meta-boxes.php b/classes/class-revisr-meta-boxes.php index 15fe0669..00cf7237 100644 --- a/classes/class-revisr-meta-boxes.php +++ b/classes/class-revisr-meta-boxes.php @@ -21,10 +21,13 @@ class Revisr_Meta_Boxes { */ public function add_meta_box_actions() { - do_action( 'add_meta_boxes_admin_page_revisr_new_commit', null ); - do_action( 'add_meta_boxes', 'admin_page_revisr_new_commit', null ); - do_action( 'add_meta_boxes_admin_page_revisr_view_commit', null ); - do_action( 'add_meta_boxes', 'admin_page_revisr_view_commit', null ); + $no_post = new stdClass(); + $no_post->ID = 0; + + do_action( 'add_meta_boxes_admin_page_revisr_new_commit', $no_post ); + do_action( 'add_meta_boxes', 'admin_page_revisr_new_commit', $no_post ); + do_action( 'add_meta_boxes_admin_page_revisr_view_commit', $no_post ); + do_action( 'add_meta_boxes', 'admin_page_revisr_view_commit', $no_post ); wp_enqueue_script( 'postbox' ); @@ -61,7 +64,10 @@ public function pending_files() { check_ajax_referer( 'staging_nonce', 'security' ); $output = revisr()->git->status(); $total_pending = count( $output ); - $text = sprintf( __( 'There are %s untracked files that can be added to this commit.', 'revisr' ), $total_pending, revisr()->git->branch ); + $commit_items = array(); // Categorize the changed files into categories for automated commit message creation + $unstaged = array(); // Store changes that do not match wp-content/plugins/plugin-name/ or wp-content/plugins/plugin-name.php + $warnings = array(); + $text = sprintf( __( 'There are %s untracked files that can be added to this commit.', 'revisr' ), $total_pending, revisr()->git->branch ); echo "
" . $text . "

"; _e( 'Use the boxes below to select the files to include in this commit. Only files in the "Staged Files" section will be included.
Double-click files marked as "Modified" to view the changes to the file.

', 'revisr' ); if ( is_array( $output ) ) { @@ -69,15 +75,43 @@ public function pending_files() {

- {$file} [{$status}]"; + $status = Revisr_Git::get_status( $short_status ); + $item = ""; + + if ( preg_match('/wp-content\/plugins\/((.*?)\/|(.*?)\.php)/', $file, $match) ) { // Match plugin name, example : wp-content/plugins/plugin-name/ or wp-content/plugins/plugin-name.php + $plugin_matched = !empty($match[2]) ? $match[2] : $match[3]; + + if( $status == 'Untracked' && isset($commit_items['Modified']) ) { // New file or folder created in existing plugin is not added to commit_items if plugin name is in modified + if(in_array($plugin_matched, $commit_items['Modified'])) { + echo $item; + continue; + } + } + + if( !isset($commit_items[$status]) ) { // No status yet + $commit_items[$status][] = $plugin_matched; + } else if( !in_array($plugin_matched, $commit_items[$status]) ) { // Prevent duplicates + $commit_items[$status][] = $plugin_matched; + } + + echo $item; + } else { // No plugin matched, move to unstaged + $unstaged[] = $item; + } + } ?> @@ -92,7 +126,15 @@ public function pending_files() {

- +
@@ -101,6 +143,36 @@ public function pending_files() {
+ $plugins ) { + switch($status) { + case 'Modified': + $commit_msg .=" Plugin updates"; + break; + case 'Untracked': + $commit_msg .=" New plugins"; + break; + case 'Deleted': + $commit_msg .=" Deleted plugins"; + break; + default: + $commit_msg .=" " . $status; + } + $commit_msg .= " - " . implode(", ", $plugins); // Build commit message from plugin names and statuses + } + $commit_msg = trim($commit_msg); + ?> + + + + + +

+ ', $warnings ); ?> + + git->reset(); + //revisr()->git->reset(); revisr()->git->fetch(); - + // Build an array of the commits we don't have locally. $commits_since = revisr()->git->run( 'log', array( revisr()->git->branch . '..' . revisr()->git->remote . '/' . revisr()->git->branch, '--pretty=oneline' ) ); // Maybe backup database. - if ( revisr()->git->get_config( 'revisr', 'import-pulls' ) === 'true' ) { - revisr()->db->backup(); - $undo_hash = revisr()->git->current_commit(); - revisr()->git->set_config( 'revisr', 'last-db-backup', $undo_hash ); - } + // if ( revisr()->git->get_config( 'revisr', 'import-pulls' ) === 'true' ) { + // revisr()->db->backup(); + // $undo_hash = revisr()->git->current_commit(); + // revisr()->git->set_config( 'revisr', 'last-db-backup', $undo_hash ); + // } // Fires before the changes are pulled. do_action( 'revisr_pre_pull', $commits_since ); @@ -352,9 +352,9 @@ public function view_diff() { Revisr_Admin::verify_nonce( $_GET['security'], 'staging_nonce' ); if ( isset( $_REQUEST['commit'] ) ) { - $diff = revisr()->git->run( 'show', array( $_REQUEST['commit'], $_REQUEST['file'] ) ); + $diff = revisr()->git->run( 'show', array( $_REQUEST['commit'], '--ignore-all-space', $_REQUEST['file'] ) ); } else { - $diff = revisr()->git->run( 'diff', array( $_REQUEST['file'] ) ); + $diff = revisr()->git->run( 'diff', array( '--ignore-all-space', $_REQUEST['file'] ) ); } if ( is_array( $diff ) ) { diff --git a/classes/class-revisr-settings-fields.php b/classes/class-revisr-settings-fields.php index bda178cb..c58978cb 100644 --- a/classes/class-revisr-settings-fields.php +++ b/classes/class-revisr-settings-fields.php @@ -299,6 +299,15 @@ public function remote_url_callback() { $remote, __( 'Useful if you need to authenticate over "https://" instead of SSH, or if the remote has not already been set through Git.', 'revisr' ) ); + + if( stripos($remote,'git@') === 0 ) { + exec( "stat ~/.ssh/id_github", $stat_output, $stat_return_code ); + if( $stat_return_code === 0 ) { + echo 'Found the SSH key in ~/.ssh/id_github'; + } else { + echo '
Error: SSH key for Github in ~/.ssh/id_github not found!'; + } + } } /** diff --git a/revisr.php b/revisr.php index 7c7409ba..c8b232c1 100644 --- a/revisr.php +++ b/revisr.php @@ -7,8 +7,8 @@ * * Plugin Name: Revisr * Plugin URI: https://revisr.io/ - * Description: A plugin that allows users to manage WordPress websites with Git repositories. - * Version: 2.0.2 + * Description: A plugin that allows users to manage WordPress websites with Git repositories. FV: Removing the db backup from pull function and improving the admin UI a bit + * Version: 100.2.0.2.fv * Author: Expanded Fronts, LLC * Author URI: http://expandedfronts.com/ * License: GPL-3.0+ @@ -110,7 +110,7 @@ private function __clone() { * Prevent direct unserialization by making the method private. * @access private */ - private function __wakeup() { + public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'revisr' ), '1.8' ); } @@ -228,7 +228,7 @@ private function define_constants() { define( 'REVISR_URL', plugin_dir_url( REVISR_FILE ) ); // The current version of the plugin. - define( 'REVISR_VERSION', '2.0.2' ); + define( 'REVISR_VERSION', '2.0.3' ); } /**