/**
  * Callback for a successful commit.
  * @access public
  */
 public function success_commit($output = '', $args = '')
 {
     $id = get_the_ID();
     $view_link = get_admin_url() . "post.php?post={$id}&action=edit";
     $commit_hash = $this->current_commit();
     $commit_msg = $_REQUEST['post_title'];
     add_post_meta($id, 'commit_hash', $commit_hash);
     add_post_meta($id, 'branch', $this->branch);
     // Backup the database if necessary
     if (isset($_REQUEST['backup_db']) && $_REQUEST['backup_db'] == 'on') {
         $db = new Revisr_DB();
         $db->backup();
         $db_hash = $this->run("log --pretty=format:'%h' -n 1");
         add_post_meta($id, 'db_hash', $db_hash[0]);
         add_post_meta($id, 'backup_method', 'tables');
     }
     // Log the event.
     $msg = sprintf(__('Commmitted <a href="%s">#%s</a> to the local repository.', 'revisr'), $view_link, $commit_hash);
     Revisr_Admin::log($msg, 'commit');
     // Notify the admin.
     $email_msg = sprintf(__('A new commit was made to the repository: <br> #%s - %s', 'revisr'), $commit_hash, $commit_msg);
     Revisr_Admin::notify(get_bloginfo() . __(' - New Commit', 'revisr'), $email_msg);
     // Add a tag if necessary.
     if (isset($_REQUEST['tag_name'])) {
         $this->tag($_POST['tag_name']);
         add_post_meta($id, 'git_tag', $_POST['tag_name']);
     }
     // Push if necessary.
     $this->auto_push();
     return $commit_hash;
 }
 /**
  * Checks out an existing branch.
  * @access public
  * @param string  $args 			The branch to checkout.
  * @param boolean $new_branch 	Whether the branch being checked out is a new branch.
  */
 public function checkout($args, $new_branch = false)
 {
     if (isset($this->options['reset_db'])) {
         $db = new Revisr_DB();
         $db->backup();
     }
     if ($args == '') {
         $branch = escapeshellarg($_REQUEST['branch']);
     } else {
         $branch = $args;
     }
     Revisr_Git::run('reset --hard HEAD');
     Revisr_Git::run("checkout {$branch}");
     if (isset($this->options['reset_db']) && $new_branch === false) {
         $db->restore(true);
     }
     $msg = sprintf(__('Checked out branch: %s.', 'revisr'), $branch);
     $email_msg = sprintf(__('%s was switched to branch %s.', 'revisr'), get_bloginfo(), $branch);
     Revisr_Admin::log($msg, "branch");
     Revisr_Admin::notify(get_bloginfo() . __(' - Branch Changed', 'revisr'), $email_msg);
     $url = get_admin_url() . "admin.php?page=revisr&branch={$branch}&checkout=success";
     wp_redirect($url);
 }