Skip to content

Commit b4ea81d

Browse files
committed
Merge pull request kbjr#19 from erikjwaxx/feature/bare-repos
Add support for instantiation of a GitRepo from a bare repository path.
2 parents c726acc + f8865a3 commit b4ea81d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Git.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public static function is_repo($var) {
104104
class GitRepo {
105105

106106
protected $repo_path = null;
107+
protected $bare = false;
107108
protected $envopts = array();
108109

109110
/**
@@ -154,16 +155,25 @@ public function __construct($repo_path = null, $create_new = false, $_init = tru
154155
* @access public
155156
* @param string repository path
156157
* @param bool create if not exists?
158+
* @param bool initialize new Git repo if not exists?
157159
* @return void
158160
*/
159161
public function set_repo_path($repo_path, $create_new = false, $_init = true) {
160162
if (is_string($repo_path)) {
161163
if ($new_path = realpath($repo_path)) {
162164
$repo_path = $new_path;
163165
if (is_dir($repo_path)) {
166+
// Is this a work tree?
164167
if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
165168
$this->repo_path = $repo_path;
166-
} else {
169+
$this->bare = false;
170+
// Is this a bare repo?
171+
} else if (is_file($repo_path."/config")) {
172+
if (parse_ini_file($repo_path."/config")['bare']) {
173+
$this->repo_path = $repo_path;
174+
$this->bare = true;
175+
}
176+
} else {
167177
if ($create_new) {
168178
$this->repo_path = $repo_path;
169179
if ($_init) {

0 commit comments

Comments
 (0)