/** * Tests the get_status() method. */ function test_get_status() { $test_modified = Revisr_Git::get_status('MM'); $test_deleted = Revisr_Git::get_status('DD'); $test_added = Revisr_Git::get_status('AA'); $test_renamed = Revisr_Git::get_status('RR'); $test_untracked = Revisr_Git::get_status('??'); $test_invalid = Revisr_Git::get_status('$$'); $this->assertEquals('Modified', $test_modified); $this->assertEquals('Deleted', $test_deleted); $this->assertEquals('Added', $test_added); $this->assertEquals('Renamed', $test_renamed); $this->assertEquals('Untracked', $test_untracked); $this->assertFalse($test_invalid); }
/** * Shows the files that were added in a given commit. * @access public */ public function committed_files_meta() { // Get details about the commit. $commit_hash = isset($_GET['commit']) ? esc_attr($_GET['commit']) : ''; $commit = Revisr_Git::get_commit_details($commit_hash); // Start outputting the metabox. echo '<div id="message"></div><div id="committed_files_result">'; // Files were included in this commit. if (0 !== count($commit['committed_files'])) { printf(__('<br><strong>%s</strong> files were included in this commit. Double-click files marked as "Modified" to view the changes in a diff.', 'revisr'), $commit['files_changed']); echo '<input id="commit_hash" name="commit_hash" value="' . $commit['hash'] . '" type="hidden" />'; echo '<br><br><select id="committed" multiple="multiple" size="6">'; // Display the files that were included in the commit. foreach ($commit['committed_files'] as $result) { $result = str_replace('"', '', $result); $short_status = substr($result, 0, 3); $file = substr($result, 2); $status = Revisr_Git::get_status($short_status); printf('<option class="committed" value="%s">%s [%s]</option>', $result, $file, $status); } echo '</select>'; } else { printf('<p>%s</p>', __('No files were included in this commit.', 'revisr')); } echo '</div>'; }
/** * Stages the array of files passed through the New Commit screen. * @access public * @param array $staged_files The files to add/remove */ public function stage_files($staged_files) { $errors = array(); foreach ($staged_files as $result) { $file = substr($result, 3); $status = Revisr_Git::get_status(substr($result, 0, 2)); if ($status == __('Deleted', 'revisr')) { if ($this->run("rm {$file}") === false) { $errors[] = $file; } } else { if ($this->run("add {$file}") === false) { $errors[] = $file; } } } if (!empty($errors)) { $msg = __('There was an error staging the files. Please check the settings and try again.', 'revisr'); Revisr_Admin::alert($msg, true); Revisr_Admin::log(__('Error staging files.', 'revisr'), 'error'); } }
/** * Shows the files that were added in a given commit. * @access public */ public function committed_files_meta() { $commit = Revisr_Admin::get_commit_details(get_the_ID()); if (count($commit['committed_files']) !== 0) { foreach ($commit['committed_files'] as $file) { $output = maybe_unserialize($file); } } echo '<div id="message"></div><div id="committed_files_result">'; if (isset($output)) { printf(__('<br><strong>%s</strong> files were included in this commit. Double-click files marked as "Modified" to view the changes in a diff.', 'revisr'), $commit['files_changed']); echo '<input id="commit_hash" name="commit_hash" value="' . $commit['commit_hash'] . '" type="hidden" />'; echo '<br><br><select id="committed" multiple="multiple" size="6">'; // Display the files that were included in the commit. foreach ($output as $result) { $result = str_replace('"', '', $result); $short_status = substr($result, 0, 3); $file = substr($result, 2); $status = Revisr_Git::get_status($short_status); printf('<option class="committed" value="%s">%s [%s]</option>', $result, $file, $status); } echo '</select>'; } else { _e('No files were included in this commit.', 'revisr'); } echo '</div>'; }
/** * Shows the files that were added in a given commit. * @access public */ public function committed_files() { if (get_post_type($_POST['id']) != 'revisr_commits') { exit; } check_ajax_referer('committed_nonce', 'security'); $committed_files = get_post_custom_values('committed_files', $_POST['id']); $commit_hash = get_post_custom_values('commit_hash', $_POST['id']); if (is_array($committed_files)) { foreach ($committed_files as $file) { $output = maybe_unserialize($file); } } if (isset($output)) { printf(__('<br><strong>%s</strong> files were included in this commit. Double-click files marked as "Modified" to view the changes in a diff.', 'revisr'), count($output)); echo "<input id='commit_hash' name='commit_hash' value='{$commit_hash[0]}' type='hidden' />"; echo '<br><br><select id="committed" multiple="multiple" size="6">'; foreach ($output as $result) { $short_status = substr($result, 0, 3); $file = substr($result, 2); $status = Revisr_Git::get_status($short_status); printf('<option class="committed" value="%s">%s [%s]</option>', $result, $file, $status); } echo '</select>'; } else { _e('No files were included in this commit.', 'revisr'); } exit; }