Skip to content

Commit

Permalink
Merge pull request #19 from erikjwaxx/feature/bare-repos
Browse files Browse the repository at this point in the history
Add support for instantiation of a GitRepo from a bare repository path.
  • Loading branch information
kbjr committed Dec 3, 2013
2 parents c726acc + f8865a3 commit b4ea81d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public static function is_repo($var) {
class GitRepo {

protected $repo_path = null;
protected $bare = false;
protected $envopts = array();

/**
Expand Down Expand Up @@ -154,16 +155,25 @@ public function __construct($repo_path = null, $create_new = false, $_init = tru
* @access public
* @param string repository path
* @param bool create if not exists?
* @param bool initialize new Git repo if not exists?
* @return void
*/
public function set_repo_path($repo_path, $create_new = false, $_init = true) {
if (is_string($repo_path)) {
if ($new_path = realpath($repo_path)) {
$repo_path = $new_path;
if (is_dir($repo_path)) {
// Is this a work tree?
if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
$this->repo_path = $repo_path;
} else {
$this->bare = false;
// Is this a bare repo?
} else if (is_file($repo_path."/config")) {
if (parse_ini_file($repo_path."/config")['bare']) {
$this->repo_path = $repo_path;
$this->bare = true;
}
} else {
if ($create_new) {
$this->repo_path = $repo_path;
if ($_init) {
Expand Down

0 comments on commit b4ea81d

Please sign in to comment.