Coding compliance change, tabs to spaces, fix typos.
authorDanny Lin <danny0838@gmail.com>
Sat, 19 Oct 2013 04:10:51 +0000 (12:10 +0800)
committerDanny Lin <danny0838@gmail.com>
Sat, 19 Oct 2013 04:12:29 +0000 (12:12 +0800)
action/editcommit.php
lib/Git.php

index e1480c7..1f3de50 100644 (file)
@@ -20,141 +20,141 @@ class action_plugin_gitbacked_editcommit extends DokuWiki_Action_Plugin {
 
     public function register(Doku_Event_Handler &$controller) {
 
-               $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_io_wikipage_write');
-               $controller->register_hook('MEDIA_UPLOAD_FINISH', 'AFTER', $this, 'handle_media_upload');
-               $controller->register_hook('MEDIA_DELETE_FILE', 'AFTER', $this, 'handle_media_deletion');
-               $controller->register_hook('DOKUWIKI_DONE', 'AFTER', $this, 'handle_periodic_pull');
+        $controller->register_hook('IO_WIKIPAGE_WRITE', 'AFTER', $this, 'handle_io_wikipage_write');
+        $controller->register_hook('MEDIA_UPLOAD_FINISH', 'AFTER', $this, 'handle_media_upload');
+        $controller->register_hook('MEDIA_DELETE_FILE', 'AFTER', $this, 'handle_media_deletion');
+        $controller->register_hook('DOKUWIKI_DONE', 'AFTER', $this, 'handle_periodic_pull');
     }
 
-       public function handle_periodic_pull(Doku_Event &$event, $param) {
-               if ($this->getConf('periodicPull')) {
-                       $lastPullFile = DOKU_PLUGIN.'gitbacked/action/lastpull.txt';
-                       //check if the lastPullFile exists
-                       if (is_file($lastPullFile)) {
-                               $lastPull = unserialize(file_get_contents($lastPullFile));
-                       } else {
-                               $lastPull = 0;
-                       }
-                       //calculate time between pulls in seconds
-                       $timeToWait = $this->getConf('periodicMinutes')*60;
-                       $now = time();
-
-                       //if it is time to run a pull request
-                       if ($lastPull+$timeToWait < $now) {
-                               $repo = $this->initRepo();
-
-                               //execute the pull request
-                               $repo->pull('origin',$repo->active_branch());
-
-                               //save the current time to the file to track the last pull execution
-                               file_put_contents($lastPullFile,serialize(time()));
-                       }
-               }
-       }
-
-       private function initRepo() {
-               //get path to the repo root (by default DokuWiki's savedir)
-               $repoPath = DOKU_INC.$this->getConf('repoPath');
-               //init the repo and create a new one if it is not present
-               $repo = new GitRepo($repoPath, true, true);
-
-               $params = $this->getConf('addParams');
-               if ($params) {
-                       $repo->git_path .= ' '.$params;
-               }
-               return $repo;
-       }
-
-       private function commitFile($filePath,$message) {
-
-               $repo = $this->initRepo();
-               
-               //add the changed file and set the commit message
-               $repo->add($filePath);
-               $repo->commit($message);
-
-               //if the push after Commit option is set we push the active branch to origin
-               if ($this->getConf('pushAfterCommit')) {
-                       $repo->push('origin',$repo->active_branch());
-               }
-
-       }
-
-       private function getAuthor() {
-               return $GLOBALS['USERINFO']['name'];
-       }
-
-       public function handle_media_deletion(Doku_Event &$event, $param) {
-               $mediaPath = $event->data['path'];
-               $mediaName = $event->data['name'];
-
-               $message = str_replace(
-                       array('%media%','%user%'),
-                       array($mediaName,$this->getAuthor()),
-                       $this->getConf('commitMediaMsgDel')
-               );
-
-               $this->commitFile($mediaPath,$message);
-
-       }
-
-       public function handle_media_upload(Doku_Event &$event, $param) {
-
-               $mediaPath = $event->data[1];
-               $mediaName = $event->data[2];
-
-               $message = str_replace(
-                       array('%media%','%user%'),
-                       array($mediaName,$this->getAuthor()),
-                       $this->getConf('commitMediaMsg')
-               );
-
-               $this->commitFile($mediaPath,$message);
-
-       }
+    public function handle_periodic_pull(Doku_Event &$event, $param) {
+        if ($this->getConf('periodicPull')) {
+            $lastPullFile = DOKU_PLUGIN.'gitbacked/action/lastpull.txt';
+            //check if the lastPullFile exists
+            if (is_file($lastPullFile)) {
+                $lastPull = unserialize(file_get_contents($lastPullFile));
+            } else {
+                $lastPull = 0;
+            }
+            //calculate time between pulls in seconds
+            $timeToWait = $this->getConf('periodicMinutes')*60;
+            $now = time();
+
+            //if it is time to run a pull request
+            if ($lastPull+$timeToWait < $now) {
+                $repo = $this->initRepo();
+
+                //execute the pull request
+                $repo->pull('origin',$repo->active_branch());
+
+                //save the current time to the file to track the last pull execution
+                file_put_contents($lastPullFile,serialize(time()));
+            }
+        }
+    }
+
+    private function initRepo() {
+        //get path to the repo root (by default DokuWiki's savedir)
+        $repoPath = DOKU_INC.$this->getConf('repoPath');
+        //init the repo and create a new one if it is not present
+        $repo = new GitRepo($repoPath, true, true);
+
+        $params = $this->getConf('addParams');
+        if ($params) {
+            $repo->git_path .= ' '.$params;
+        }
+        return $repo;
+    }
+
+    private function commitFile($filePath,$message) {
+
+        $repo = $this->initRepo();
+        
+        //add the changed file and set the commit message
+        $repo->add($filePath);
+        $repo->commit($message);
+
+        //if the push after Commit option is set we push the active branch to origin
+        if ($this->getConf('pushAfterCommit')) {
+            $repo->push('origin',$repo->active_branch());
+        }
+
+    }
+
+    private function getAuthor() {
+        return $GLOBALS['USERINFO']['name'];
+    }
+
+    public function handle_media_deletion(Doku_Event &$event, $param) {
+        $mediaPath = $event->data['path'];
+        $mediaName = $event->data['name'];
+
+        $message = str_replace(
+            array('%media%','%user%'),
+            array($mediaName,$this->getAuthor()),
+            $this->getConf('commitMediaMsgDel')
+        );
+
+        $this->commitFile($mediaPath,$message);
+
+    }
+
+    public function handle_media_upload(Doku_Event &$event, $param) {
+
+        $mediaPath = $event->data[1];
+        $mediaName = $event->data[2];
+
+        $message = str_replace(
+            array('%media%','%user%'),
+            array($mediaName,$this->getAuthor()),
+            $this->getConf('commitMediaMsg')
+        );
+
+        $this->commitFile($mediaPath,$message);
+
+    }
 
     public function handle_io_wikipage_write(Doku_Event &$event, $param) {
 
-               $rev = $event->data[3];
-               
-               /* On update to an existing page this event is called twice,
-               * once for the transfer of the old version to the attic (rev will have a value)
-               * and once to write the new version of the page into the wiki (rev is false) 
-               */
-               if (!$rev) {
-
-                       $pagePath = $event->data[0][0];
-                       $pageName = $event->data[2];
-                       $pageContent = $event->data[0][1];
-
-                       // get the summary directly from the form input
-                       // as the metadata hasn't updated yer
-                       $editSummary = $GLOBALS['INPUT']->str('summary');               
-
-                       // empty content indicates a page deletion
-                       if ($pageContent == '') {
-                               // get the commit text for deletions
-                               $msgTemplate = $this->getConf('commitPageMsgDel');
-
-                               // bad hack as DokuWiki deletes the file after this event
-                               // thus, let's delete the file by ourselves, so git can recognize the deletion
-                               // DokuWiki uses @unlink as well, so no error should be thrown if we delete it twice
-                               @unlink($pagePath);
-
-                       } else {
-                               //get the commit text for edits
-                               $msgTemplate = $this->getConf('commitPageMsg');
-                       }
-
-                       $message = str_replace(
-                               array('%page%','%summary%','%user%'),
-                               array($pageName,$editSummary,$this->getAuthor()),
-                               $msgTemplate
-                       );
-
-                       $this->commitFile($pagePath,$message);          
-
-               }
+        $rev = $event->data[3];
+        
+        /* On update to an existing page this event is called twice,
+         * once for the transfer of the old version to the attic (rev will have a value)
+         * and once to write the new version of the page into the wiki (rev is false) 
+         */
+        if (!$rev) {
+
+            $pagePath = $event->data[0][0];
+            $pageName = $event->data[2];
+            $pageContent = $event->data[0][1];
+
+            // get the summary directly from the form input
+            // as the metadata hasn't updated yet
+            $editSummary = $GLOBALS['INPUT']->str('summary');
+
+            // empty content indicates a page deletion
+            if ($pageContent == '') {
+                // get the commit text for deletions
+                $msgTemplate = $this->getConf('commitPageMsgDel');
+
+                // bad hack as DokuWiki deletes the file after this event
+                // thus, let's delete the file by ourselves, so git can recognize the deletion
+                // DokuWiki uses @unlink as well, so no error should be thrown if we delete it twice
+                @unlink($pagePath);
+
+            } else {
+                //get the commit text for edits
+                $msgTemplate = $this->getConf('commitPageMsg');
+            }
+
+            $message = str_replace(
+                array('%page%','%summary%','%user%'),
+                array($pageName,$editSummary,$this->getAuthor()),
+                $msgTemplate
+            );
+
+            $this->commitFile($pagePath,$message);        
+
+        }
 
     }
 
index 3e0b7fd..fd1ef3d 100644 (file)
@@ -27,45 +27,45 @@ if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) die('Bad load order');
  */
 class Git {
 
-       /**
-        * Create a new git repository
-        *
-        * Accepts a creation path, and, optionally, a source path
-        *
-        * @access  public
-        * @param   string  repository path
-        * @param   string  directory to source
-        * @return  GitRepo
-        */
-       public static function &create($repo_path, $source = null) {
-               return GitRepo::create_new($repo_path, $source);
-       }
-
-       /**
-        * Open an existing git repository
-        *
-        * Accepts a repository path
-        *
-        * @access  public
-        * @param   string  repository path
-        * @return  GitRepo
-        */
-       public static function open($repo_path) {
-               return new GitRepo($repo_path);
-       }
-
-       /**
-        * Checks if a variable is an instance of GitRepo
-        *
-        * Accepts a variable
-        *
-        * @access  public
-        * @param   mixed   variable
-        * @return  bool
-        */
-       public static function is_repo($var) {
-               return (get_class($var) == 'GitRepo');
-       }
+    /**
+     * Create a new git repository
+     *
+     * Accepts a creation path, and, optionally, a source path
+     *
+     * @access  public
+     * @param   string  repository path
+     * @param   string  directory to source
+     * @return  GitRepo
+     */
+    public static function &create($repo_path, $source = null) {
+        return GitRepo::create_new($repo_path, $source);
+    }
+
+    /**
+     * Open an existing git repository
+     *
+     * Accepts a repository path
+     *
+     * @access  public
+     * @param   string  repository path
+     * @return  GitRepo
+     */
+    public static function open($repo_path) {
+        return new GitRepo($repo_path);
+    }
+
+    /**
+     * Checks if a variable is an instance of GitRepo
+     *
+     * Accepts a variable
+     *
+     * @access  public
+     * @param   mixed   variable
+     * @return  bool
+     */
+    public static function is_repo($var) {
+        return (get_class($var) == 'GitRepo');
+    }
 
 }
 
@@ -81,314 +81,314 @@ class Git {
  */
 class GitRepo {
 
-       protected $repo_path = null;
-
-       public $git_path = '/usr/bin/git';
-
-       /**
-        * Create a new git repository
-        *
-        * Accepts a creation path, and, optionally, a source path
-        *
-        * @access  public
-        * @param   string  repository path
-        * @param   string  directory to source
-        * @return  GitRepo
-        */
-       public static function &create_new($repo_path, $source = null) {
-               if (is_dir($repo_path) && file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
-                       throw new Exception('"'.$repo_path.'" is already a git repository');
-               } else {
-                       $repo = new self($repo_path, true, false);
-                       if (is_string($source))
-                               $repo->clone_from($source);
-                       else $repo->run('init');
-                       return $repo;
-               }
-       }
-
-       /**
-        * Constructor
-        *
-        * Accepts a repository path
-        *
-        * @access  public
-        * @param   string  repository path
-        * @param   bool    create if not exists?
-        * @return  void
-        */
-       public function __construct($repo_path = null, $create_new = false, $_init = true) {
-               if (is_string($repo_path))
-                       $this->set_repo_path($repo_path, $create_new, $_init);
-       }
-
-       /**
-        * Set the repository's path
-        *
-        * Accepts the repository path
-        *
-        * @access  public
-        * @param   string  repository path
-        * @param   bool    create if not exists?
-        * @return  void
-        */
-       public function set_repo_path($repo_path, $create_new = false, $_init = true) {
-               if (is_string($repo_path)) {
-                       if ($new_path = realpath($repo_path)) {
-                               $repo_path = $new_path;
-                               if (is_dir($repo_path)) {
-                                       if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
-                                               $this->repo_path = $repo_path;
-                                       } else {
-                                               if ($create_new) {
-                                                       $this->repo_path = $repo_path;
-                                                       if ($_init) $this->run('init');
-                                               } else {
-                                                       throw new Exception('"'.$repo_path.'" is not a git repository');
-                                               }
-                                       }
-                               } else {
-                                       throw new Exception('"'.$repo_path.'" is not a directory');
-                               }
-                       } else {
-                               if ($create_new) {
-                                       if ($parent = realpath(dirname($repo_path))) {
-                                               mkdir($repo_path);
-                                               $this->repo_path = $repo_path;
-                                               if ($_init) $this->run('init');
-                                       } else {
-                                               throw new Exception('cannot create repository in non-existent directory');
-                                       }
-                               } else {
-                                       throw new Exception('"'.$repo_path.'" does not exist');
-                               }
-                       }
-               }
-       }
-
-       /**
-        * Tests if git is installed
-        *
-        * @access  public
-        * @return  bool
-        */
-       public function test_git() {
-               $descriptorspec = array(
-                       1 => array('pipe', 'w'),
-                       2 => array('pipe', 'w'),
-               );
-               $pipes = array();
-               $resource = proc_open($this->git_path, $descriptorspec, $pipes);
-
-               $stdout = stream_get_contents($pipes[1]);
-               $stderr = stream_get_contents($pipes[2]);
-               foreach ($pipes as $pipe) {
-                       fclose($pipe);
-               }
-
-               $status = trim(proc_close($resource));
-               return ($status != 127);
-       }
-
-       /**
-        * Run a command in the git repository
-        *
-        * Accepts a shell command to run
-        *
-        * @access  protected
-        * @param   string  command to run
-        * @return  string
-        */
-       protected function run_command($command) {
-
-               $descriptorspec = array(
-                       1 => array('pipe', 'w'),
-                       2 => array('pipe', 'w'),
-               );
-               $pipes = array();
-               $resource = proc_open($command, $descriptorspec, $pipes, $this->repo_path);
-
-               $stdout = stream_get_contents($pipes[1]);
-               $stderr = stream_get_contents($pipes[2]);
-               foreach ($pipes as $pipe) {
-                       fclose($pipe);
-               }
-
-               $status = trim(proc_close($resource));
-               if ($status) throw new Exception($stderr);
-
-               return $stdout;
-       }
-
-       /**
-        * Run a git command in the git repository
-        *
-        * Accepts a git command to run
-        *
-        * @access  public
-        * @param   string  command to run
-        * @return  string
-        */
-       public function run($command) {
-               return $this->run_command($this->git_path." ".$command);
-       }
-
-       /**
-        * Runs a `git add` call
-        *
-        * Accepts a list of files to add
-        *
-        * @access  public
-        * @param   mixed   files to add
-        * @return  string
-        */
-       public function add($files = "*") {
-               if (is_array($files)) $files = '"'.implode('" "', $files).'"';
-               return $this->run("add $files -v");
-       }
-
-       /**
-        * Runs a `git commit` call
-        *
-        * Accepts a commit message string
-        *
-        * @access  public
-        * @param   string  commit message
-        * @return  string
-        */
-       public function commit($message = "") {
-               return $this->run("commit -av -m ".escapeshellarg($message));
-       }
-
-       /**
-        * Runs a `git clone` call to clone the current repository
-        * into a different directory
-        *
-        * Accepts a target directory
-        *
-        * @access  public
-        * @param   string  target directory
-        * @return  string
-        */
-       public function clone_to($target) {
-               return $this->run("clone --local ".$this->repo_path." $target");
-       }
-
-       /**
-        * Runs a `git clone` call to clone a different repository
-        * into the current repository
-        *
-        * Accepts a source directory
-        *
-        * @access  public
-        * @param   string  source directory
-        * @return  string
-        */
-       public function clone_from($source) {
-               return $this->run("clone --local $source ".$this->repo_path);
-       }
-
-       /**
-        * Runs a `git clone` call to clone a remote repository
-        * into the current repository
-        *
-        * Accepts a source url
-        *
-        * @access  public
-        * @param   string  source url
-        * @return  string
-        */
-       public function clone_remote($source) {
-               return $this->run("clone $source ".$this->repo_path);
-       }
-
-       /**
-        * Runs a `git clean` call
-        *
-        * Accepts a remove directories flag
-        *
-        * @access  public
-        * @param   bool    delete directories?
-        * @return  string
-        */
-       public function clean($dirs = false) {
-               return $this->run("clean".(($dirs) ? " -d" : ""));
-       }
-
-       /**
-        * Runs a `git branch` call
-        *
-        * Accepts a name for the branch
-        *
-        * @access  public
-        * @param   string  branch name
-        * @return  string
-        */
-       public function create_branch($branch) {
-               return $this->run("branch $branch");
-       }
-
-       /**
-        * Runs a `git branch -[d|D]` call
-        *
-        * Accepts a name for the branch
-        *
-        * @access  public
-        * @param   string  branch name
-        * @return  string
-        */
-       public function delete_branch($branch, $force = false) {
-               return $this->run("branch ".(($force) ? '-D' : '-d')." $branch");
-       }
-
-       /**
-        * Runs a `git branch` call
-        *
-        * @access  public
-        * @param   bool    keep asterisk mark on active branch
-        * @return  array
-        */
-       public function list_branches($keep_asterisk = false) {
-               $branchArray = explode("\n", $this->run("branch"));
-               foreach($branchArray as $i => &$branch) {
-                       $branch = trim($branch);
-                       if (! $keep_asterisk)
-                               $branch = str_replace("* ", "", $branch);
-                       if ($branch == "")
-                               unset($branchArray[$i]);
-               }
-               return $branchArray;
-       }
-
-       /**
-        * Returns name of active branch
-        *
-        * @access  public
-        * @param   bool    keep asterisk mark on branch name
-        * @return  string
-        */
-       public function active_branch($keep_asterisk = false) {
-               $branchArray = $this->list_branches(true);
-               $active_branch = preg_grep("/^\*/", $branchArray);
-               reset($active_branch);
-               if ($keep_asterisk)
-                       return current($active_branch);
-               else
-                       return str_replace("* ", "", current($active_branch));
-       }
-
-       /**
-        * Runs a `git checkout` call
-        *
-        * Accepts a name for the branch
-        *
-        * @access  public
-        * @param   string  branch name
-        * @return  string
-        */
-       public function checkout($branch) {
-               return $this->run("checkout $branch");
-       }
+    protected $repo_path = null;
+
+    public $git_path = '/usr/bin/git';
+
+    /**
+     * Create a new git repository
+     *
+     * Accepts a creation path, and, optionally, a source path
+     *
+     * @access  public
+     * @param   string  repository path
+     * @param   string  directory to source
+     * @return  GitRepo
+     */
+    public static function &create_new($repo_path, $source = null) {
+        if (is_dir($repo_path) && file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
+            throw new Exception('"'.$repo_path.'" is already a git repository');
+        } else {
+            $repo = new self($repo_path, true, false);
+            if (is_string($source))
+                $repo->clone_from($source);
+            else $repo->run('init');
+            return $repo;
+        }
+    }
+
+    /**
+     * Constructor
+     *
+     * Accepts a repository path
+     *
+     * @access  public
+     * @param   string  repository path
+     * @param   bool    create if not exists?
+     * @return  void
+     */
+    public function __construct($repo_path = null, $create_new = false, $_init = true) {
+        if (is_string($repo_path))
+            $this->set_repo_path($repo_path, $create_new, $_init);
+    }
+
+    /**
+     * Set the repository's path
+     *
+     * Accepts the repository path
+     *
+     * @access  public
+     * @param   string  repository path
+     * @param   bool    create if not exists?
+     * @return  void
+     */
+    public function set_repo_path($repo_path, $create_new = false, $_init = true) {
+        if (is_string($repo_path)) {
+            if ($new_path = realpath($repo_path)) {
+                $repo_path = $new_path;
+                if (is_dir($repo_path)) {
+                    if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
+                        $this->repo_path = $repo_path;
+                    } else {
+                        if ($create_new) {
+                            $this->repo_path = $repo_path;
+                            if ($_init) $this->run('init');
+                        } else {
+                            throw new Exception('"'.$repo_path.'" is not a git repository');
+                        }
+                    }
+                } else {
+                    throw new Exception('"'.$repo_path.'" is not a directory');
+                }
+            } else {
+                if ($create_new) {
+                    if ($parent = realpath(dirname($repo_path))) {
+                        mkdir($repo_path);
+                        $this->repo_path = $repo_path;
+                        if ($_init) $this->run('init');
+                    } else {
+                        throw new Exception('cannot create repository in non-existent directory');
+                    }
+                } else {
+                    throw new Exception('"'.$repo_path.'" does not exist');
+                }
+            }
+        }
+    }
+
+    /**
+     * Tests if git is installed
+     *
+     * @access  public
+     * @return  bool
+     */
+    public function test_git() {
+        $descriptorspec = array(
+            1 => array('pipe', 'w'),
+            2 => array('pipe', 'w'),
+        );
+        $pipes = array();
+        $resource = proc_open($this->git_path, $descriptorspec, $pipes);
+
+        $stdout = stream_get_contents($pipes[1]);
+        $stderr = stream_get_contents($pipes[2]);
+        foreach ($pipes as $pipe) {
+            fclose($pipe);
+        }
+
+        $status = trim(proc_close($resource));
+        return ($status != 127);
+    }
+
+    /**
+     * Run a command in the git repository
+     *
+     * Accepts a shell command to run
+     *
+     * @access  protected
+     * @param   string  command to run
+     * @return  string
+     */
+    protected function run_command($command) {
+
+        $descriptorspec = array(
+            1 => array('pipe', 'w'),
+            2 => array('pipe', 'w'),
+        );
+        $pipes = array();
+        $resource = proc_open($command, $descriptorspec, $pipes, $this->repo_path);
+
+        $stdout = stream_get_contents($pipes[1]);
+        $stderr = stream_get_contents($pipes[2]);
+        foreach ($pipes as $pipe) {
+            fclose($pipe);
+        }
+
+        $status = trim(proc_close($resource));
+        if ($status) throw new Exception($stderr);
+
+        return $stdout;
+    }
+
+    /**
+     * Run a git command in the git repository
+     *
+     * Accepts a git command to run
+     *
+     * @access  public
+     * @param   string  command to run
+     * @return  string
+     */
+    public function run($command) {
+        return $this->run_command($this->git_path." ".$command);
+    }
+
+    /**
+     * Runs a `git add` call
+     *
+     * Accepts a list of files to add
+     *
+     * @access  public
+     * @param   mixed   files to add
+     * @return  string
+     */
+    public function add($files = "*") {
+        if (is_array($files)) $files = '"'.implode('" "', $files).'"';
+        return $this->run("add $files -v");
+    }
+
+    /**
+     * Runs a `git commit` call
+     *
+     * Accepts a commit message string
+     *
+     * @access  public
+     * @param   string  commit message
+     * @return  string
+     */
+    public function commit($message = "") {
+        return $this->run("commit -av -m ".escapeshellarg($message));
+    }
+
+    /**
+     * Runs a `git clone` call to clone the current repository
+     * into a different directory
+     *
+     * Accepts a target directory
+     *
+     * @access  public
+     * @param   string  target directory
+     * @return  string
+     */
+    public function clone_to($target) {
+        return $this->run("clone --local ".$this->repo_path." $target");
+    }
+
+    /**
+     * Runs a `git clone` call to clone a different repository
+     * into the current repository
+     *
+     * Accepts a source directory
+     *
+     * @access  public
+     * @param   string  source directory
+     * @return  string
+     */
+    public function clone_from($source) {
+        return $this->run("clone --local $source ".$this->repo_path);
+    }
+
+    /**
+     * Runs a `git clone` call to clone a remote repository
+     * into the current repository
+     *
+     * Accepts a source url
+     *
+     * @access  public
+     * @param   string  source url
+     * @return  string
+     */
+    public function clone_remote($source) {
+        return $this->run("clone $source ".$this->repo_path);
+    }
+
+    /**
+     * Runs a `git clean` call
+     *
+     * Accepts a remove directories flag
+     *
+     * @access  public
+     * @param   bool    delete directories?
+     * @return  string
+     */
+    public function clean($dirs = false) {
+        return $this->run("clean".(($dirs) ? " -d" : ""));
+    }
+
+    /**
+     * Runs a `git branch` call
+     *
+     * Accepts a name for the branch
+     *
+     * @access  public
+     * @param   string  branch name
+     * @return  string
+     */
+    public function create_branch($branch) {
+        return $this->run("branch $branch");
+    }
+
+    /**
+     * Runs a `git branch -[d|D]` call
+     *
+     * Accepts a name for the branch
+     *
+     * @access  public
+     * @param   string  branch name
+     * @return  string
+     */
+    public function delete_branch($branch, $force = false) {
+        return $this->run("branch ".(($force) ? '-D' : '-d')." $branch");
+    }
+
+    /**
+     * Runs a `git branch` call
+     *
+     * @access  public
+     * @param   bool    keep asterisk mark on active branch
+     * @return  array
+     */
+    public function list_branches($keep_asterisk = false) {
+        $branchArray = explode("\n", $this->run("branch"));
+        foreach($branchArray as $i => &$branch) {
+            $branch = trim($branch);
+            if (! $keep_asterisk)
+                $branch = str_replace("* ", "", $branch);
+            if ($branch == "")
+                unset($branchArray[$i]);
+        }
+        return $branchArray;
+    }
+
+    /**
+     * Returns name of active branch
+     *
+     * @access  public
+     * @param   bool    keep asterisk mark on branch name
+     * @return  string
+     */
+    public function active_branch($keep_asterisk = false) {
+        $branchArray = $this->list_branches(true);
+        $active_branch = preg_grep("/^\*/", $branchArray);
+        reset($active_branch);
+        if ($keep_asterisk)
+            return current($active_branch);
+        else
+            return str_replace("* ", "", current($active_branch));
+    }
+
+    /**
+     * Runs a `git checkout` call
+     *
+     * Accepts a name for the branch
+     *
+     * @access  public
+     * @param   string  branch name
+     * @return  string
+     */
+    public function checkout($branch) {
+        return $this->run("checkout $branch");
+    }
 
 
     /**