@@ -142,7 +142,7 @@ class GitRepo {
142142 * @return GitRepo
143143 */
144144 public static function &create_new ($ repo_path , $ source = null , $ remote_source = false , $ reference = null ) {
145- if (is_dir ($ repo_path ) && file_exists ($ repo_path ."/.git " ) && is_dir ( $ repo_path . " /.git " ) ) {
145+ if (is_dir ($ repo_path ) && file_exists ($ repo_path ."/.git " )) {
146146 throw new Exception ('" ' .$ repo_path .'" is already a git repository ' );
147147 } else {
148148 $ repo = new self ($ repo_path , true , false );
@@ -198,7 +198,7 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
198198 $ repo_path = $ new_path ;
199199 if (is_dir ($ repo_path )) {
200200 // Is this a work tree?
201- if (file_exists ($ repo_path ."/.git " ) && is_dir ( $ repo_path . " /.git " ) ) {
201+ if (file_exists ($ repo_path ."/.git " )) {
202202 $ this ->repo_path = $ repo_path ;
203203 $ this ->bare = false ;
204204 // Is this a bare repo?
@@ -244,7 +244,20 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
244244 * @return string
245245 */
246246 public function git_directory_path () {
247- return ($ this ->bare ) ? $ this ->repo_path : $ this ->repo_path ."/.git " ;
247+ if ($ this ->bare ) {
248+ return $ this ->repo_path ;
249+ } else if (is_dir ($ this ->repo_path ."/.git " )) {
250+ return $ this ->repo_path ."/.git " ;
251+ } else if (is_file ($ this ->repo_path ."/.git " )) {
252+ $ git_file = file_get_contents ($ this ->repo_path ."/.git " );
253+ if (mb_ereg ("^gitdir: (.+)$ " , $ git_file , $ matches )){
254+ if ($ matches [1 ]) {
255+ $ rel_git_path = $ matches [1 ];
256+ return $ this ->repo_path ."/ " .$ rel_git_path ;
257+ }
258+ }
259+ }
260+ throw new Exception ('could not find git dir for ' .$ this ->repo_path .'. ' );
248261 }
249262
250263 /**
0 commit comments