diff --git a/public_html/libgit/base.php b/public_html/libgit/base.php index d952cfd..f861d14 100644 --- a/public_html/libgit/base.php +++ b/public_html/libgit/base.php @@ -23,6 +23,8 @@ function sha1_from_bin($bin) return bin2hex($bin); } +class GitBranchNotFoundException extends Exception {} + require(dirname(__FILE__) . "/class.repository.php"); require(dirname(__FILE__) . "/class.branch.php"); require(dirname(__FILE__) . "/class.object.php"); diff --git a/public_html/libgit/class.branch.php b/public_html/libgit/class.branch.php new file mode 100644 index 0000000..5e4ace2 --- /dev/null +++ b/public_html/libgit/class.branch.php @@ -0,0 +1,17 @@ +repo = $repo; + $this->sha = $sha; + } + + function GetLastCommit() + { + return $this->repo->GetObject($this->sha); + } +} diff --git a/public_html/libgit/class.repository.php b/public_html/libgit/class.repository.php index 62596c3..6a8c981 100644 --- a/public_html/libgit/class.repository.php +++ b/public_html/libgit/class.repository.php @@ -54,6 +54,16 @@ class GitRepository function GetBranch($name) { - return new GitBranch($this, $sha); + $filename = "{$this->path}/refs/heads/{$name}"; + + if(file_exists($filename)) + { + $sha = trim(file_get_contents($filename)); + return new GitBranch($this, $sha); + } + else + { + throw new GitBranchNotFoundException("The {$name} branch does not exist."); + } } } diff --git a/public_html/test.php b/public_html/test.php index 7ab57ac..cef38a2 100644 --- a/public_html/test.php +++ b/public_html/test.php @@ -1,10 +1,12 @@ GetBranch("master")->GetLastCommit()); + /*pretty_dump($s->GetObject("54e03e490b1bee1c154c3545bf258cab0629ee02")); pretty_dump($s->GetObject("98d99489382a3541e6783bb2083554785f3eb72a")); pretty_dump($s->GetObject("9d8e0ba4a30f6a5d775a879c42c7de5aed4530c6")); -pretty_dump($s->GetObject("710bfee4440517255475bf7c5454c0bdbb3b3e56"));*/ +pretty_dump($s->GetObject("710bfee4440517255475bf7c5454c0bdbb3b3e56")); pretty_dump($s->GetObject("ab2d7159831970ca08f2c9fc5c0fa34b17d572e9")); -pretty_dump($s->GetObject("cdebafd9e7426d0243cfb0a4ea2116a8b97b01e7")); +pretty_dump($s->GetObject("cdebafd9e7426d0243cfb0a4ea2116a8b97b01e7"));*/