Skip to content

Commit 110cd42

Browse files
authored
Merge pull request kbjr#52 from squiddle/master
support .git files with relative gitdir location
2 parents 4de6d73 + 4ca3727 commit 110cd42

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Git.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)