@@ -92,10 +92,11 @@ public static function open($repo_path) {
9292 * @access public
9393 * @param string repository path
9494 * @param string remote source
95+ * @param string reference path
9596 * @return GitRepo
9697 **/
97- public static function &clone_remote ($ repo_path , $ remote ) {
98- return GitRepo::create_new ($ repo_path , $ remote , true );
98+ public static function &clone_remote ($ repo_path , $ remote, $ reference = null ) {
99+ return GitRepo::create_new ($ repo_path , $ remote , true , $ reference );
99100 }
100101
101102 /**
@@ -137,16 +138,23 @@ class GitRepo {
137138 * @access public
138139 * @param string repository path
139140 * @param string directory to source
141+ * @param string reference path
140142 * @return GitRepo
141143 */
142- public static function &create_new ($ repo_path , $ source = null , $ remote_source = false ) {
144+ public static function &create_new ($ repo_path , $ source = null , $ remote_source = false , $ reference = null ) {
143145 if (is_dir ($ repo_path ) && file_exists ($ repo_path ."/.git " ) && is_dir ($ repo_path ."/.git " )) {
144146 throw new Exception ('" ' .$ repo_path .'" is already a git repository ' );
145147 } else {
146148 $ repo = new self ($ repo_path , true , false );
147149 if (is_string ($ source )) {
148150 if ($ remote_source ) {
149- $ repo ->clone_remote ($ source );
151+ if (!is_dir ($ reference ) || !is_dir ($ reference .'/.git ' )) {
152+ throw new Exception ('" ' .$ reference .'" is not a git repository. Cannot use as reference. ' );
153+ } else if (strlen ($ reference )) {
154+ $ reference = realpath ($ reference );
155+ $ reference = "--reference $ reference " ;
156+ }
157+ $ repo ->clone_remote ($ source , $ reference );
150158 } else {
151159 $ repo ->clone_from ($ source );
152160 }
@@ -426,10 +434,11 @@ public function clone_from($source) {
426434 *
427435 * @access public
428436 * @param string source url
437+ * @param string reference path
429438 * @return string
430439 */
431- public function clone_remote ($ source ) {
432- return $ this ->run ("clone $ source " .$ this ->repo_path );
440+ public function clone_remote ($ source, $ reference ) {
441+ return $ this ->run ("clone $ reference $ source " .$ this ->repo_path );
433442 }
434443
435444 /**
0 commit comments