Get tags and trees

master
Sven Slootweg 12 years ago
parent 9a10d6716b
commit 76602755be

@ -24,6 +24,7 @@ function sha1_from_bin($bin)
} }
class GitBranchNotFoundException extends Exception {} class GitBranchNotFoundException extends Exception {}
class GitTagNotFoundException extends Exception {}
require(dirname(__FILE__) . "/class.repository.php"); require(dirname(__FILE__) . "/class.repository.php");
require(dirname(__FILE__) . "/class.branch.php"); require(dirname(__FILE__) . "/class.branch.php");

@ -14,4 +14,9 @@ class GitBranch
{ {
return $this->repo->GetObject($this->sha); return $this->repo->GetObject($this->sha);
} }
function GetTree()
{
return $this->GetCommit()->GetTree();
}
} }

@ -54,4 +54,9 @@ class GitCommit extends GitObject
$this->message = implode("\n", $message_parts); $this->message = implode("\n", $message_parts);
} }
function GetTree()
{
return $this->repo->GetObject($this->tree);
}
} }

@ -63,7 +63,22 @@ class GitRepository
} }
else else
{ {
throw new GitBranchNotFoundException("The {$name} branch does not exist."); throw new GitBranchNotFoundException("The '{$name}' branch does not exist.");
}
}
function GetTag($name)
{
$filename = "{$this->path}/refs/tags/{$name}";
if(file_exists($filename))
{
$sha = trim(file_get_contents($filename));
return $this->GetObject($sha);
}
else
{
throw new GitTagNotFoundException("The '{$name}' tag does not exist.");
} }
} }
} }

@ -54,4 +54,14 @@ class GitTag extends GitObject
$this->message = implode("\n", $message_parts); $this->message = implode("\n", $message_parts);
} }
function GetCommit()
{
return $this->repo->GetObject($this->target);
}
function GetTree()
{
return $this->GetCommit()->GetTree();
}
} }

@ -2,7 +2,7 @@
require("libgit/base.php"); require("libgit/base.php");
$repo = new GitRepository("/home/occupy/testrepo.git"); $repo = new GitRepository("/home/occupy/testrepo.git");
pretty_dump($repo->GetBranch("master")->GetLastCommit()); pretty_dump($repo->GetTag("1.0")->GetCommit());
/*pretty_dump($s->GetObject("54e03e490b1bee1c154c3545bf258cab0629ee02")); /*pretty_dump($s->GetObject("54e03e490b1bee1c154c3545bf258cab0629ee02"));
pretty_dump($s->GetObject("98d99489382a3541e6783bb2083554785f3eb72a")); pretty_dump($s->GetObject("98d99489382a3541e6783bb2083554785f3eb72a"));

Loading…
Cancel
Save