@@ -143,7 +143,7 @@ class GitRepo {
143143 * @return GitRepo
144144 */
145145 public static function &create_new ($ repo_path , $ source = null , $ remote_source = false , $ reference = null ) {
146- if (is_dir ($ repo_path ) && file_exists ($ repo_path ."/.git " ) && is_dir ( $ repo_path . " /.git " ) ) {
146+ if (is_dir ($ repo_path ) && file_exists ($ repo_path ."/.git " )) {
147147 throw new Exception ('" ' .$ repo_path .'" is already a git repository ' );
148148 } else {
149149 $ repo = new self ($ repo_path , true , false );
@@ -201,7 +201,7 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
201201 $ repo_path = $ new_path ;
202202 if (is_dir ($ repo_path )) {
203203 // Is this a work tree?
204- if (file_exists ($ repo_path ."/.git " ) && is_dir ( $ repo_path . " /.git " ) ) {
204+ if (file_exists ($ repo_path ."/.git " )) {
205205 $ this ->repo_path = $ repo_path ;
206206 $ this ->bare = false ;
207207 // Is this a bare repo?
@@ -247,7 +247,20 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
247247 * @return string
248248 */
249249 public function git_directory_path () {
250- return ($ this ->bare ) ? $ this ->repo_path : $ this ->repo_path ."/.git " ;
250+ if ($ this ->bare ) {
251+ return $ this ->repo_path ;
252+ } else if (is_dir ($ this ->repo_path ."/.git " )) {
253+ return $ this ->repo_path ."/.git " ;
254+ } else if (is_file ($ this ->repo_path ."/.git " )) {
255+ $ git_file = file_get_contents ($ this ->repo_path ."/.git " );
256+ if (mb_ereg ("^gitdir: (.+)$ " , $ git_file , $ matches )){
257+ if ($ matches [1 ]) {
258+ $ rel_git_path = $ matches [1 ];
259+ return $ this ->repo_path ."/ " .$ rel_git_path ;
260+ }
261+ }
262+ }
263+ throw new Exception ('could not find git dir for ' .$ this ->repo_path .'. ' );
251264 }
252265
253266 /**
0 commit comments