@@ -143,7 +143,7 @@ class GitRepo {
143
143
* @return GitRepo
144
144
*/
145
145
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 " )) {
147
147
throw new Exception ('" ' .$ repo_path .'" is already a git repository ' );
148
148
} else {
149
149
$ repo = new self ($ repo_path , true , false );
@@ -201,7 +201,7 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
201
201
$ repo_path = $ new_path ;
202
202
if (is_dir ($ repo_path )) {
203
203
// Is this a work tree?
204
- if (file_exists ($ repo_path ."/.git " ) && is_dir ( $ repo_path . " /.git " ) ) {
204
+ if (file_exists ($ repo_path ."/.git " )) {
205
205
$ this ->repo_path = $ repo_path ;
206
206
$ this ->bare = false ;
207
207
// Is this a bare repo?
@@ -247,7 +247,20 @@ public function set_repo_path($repo_path, $create_new = false, $_init = true) {
247
247
* @return string
248
248
*/
249
249
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 .'. ' );
251
264
}
252
265
253
266
/**
0 commit comments