Merge pull request #33 from ElliottLandsborough/patch-1 master
Merge pull request #33 from ElliottLandsborough/patch-1

Ability to specify reference directory

file:a/Git.php -> file:b/Git.php
--- a/Git.php
+++ b/Git.php
@@ -92,10 +92,11 @@
 	 * @access  public
 	 * @param   string  repository path
 	 * @param   string  remote source
+	 * @param   string  reference path
 	 * @return  GitRepo
 	 **/
-	public static function &clone_remote($repo_path, $remote) {
-		return GitRepo::create_new($repo_path, $remote, true);
+	public static function &clone_remote($repo_path, $remote, $reference = null) {
+		return GitRepo::create_new($repo_path, $remote, true, $reference);
 	}
 
 	/**
@@ -137,16 +138,23 @@
 	 * @access  public
 	 * @param   string  repository path
 	 * @param   string  directory to source
+	 * @param   string  reference path
 	 * @return  GitRepo
 	 */
-	public static function &create_new($repo_path, $source = null, $remote_source = false) {
+	public static function &create_new($repo_path, $source = null, $remote_source = false, $reference = 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)) {
 				if ($remote_source) {
-					$repo->clone_remote($source);
+					if (!is_dir($reference) || !is_dir($reference.'/.git')) {
+						throw new Exception('"'.$reference.'" is not a git repository. Cannot use as reference.');
+					} else if (strlen($reference)) {
+						$reference = realpath($reference);
+						$reference = "--reference $reference";
+					}
+					$repo->clone_remote($source, $reference);
 				} else {
 					$repo->clone_from($source);
 				}
@@ -426,10 +434,11 @@
 	 *
 	 * @access  public
 	 * @param   string  source url
-	 * @return  string
-	 */
-	public function clone_remote($source) {
-		return $this->run("clone $source ".$this->repo_path);
+	 * @param   string  reference path
+	 * @return  string
+	 */
+	public function clone_remote($source, $reference) {
+		return $this->run("clone $reference $source ".$this->repo_path);
 	}
 
 	/**