diff --git a/public_html/libgit/base.php b/public_html/libgit/base.php
index 1524b66..52f974c 100644
--- a/public_html/libgit/base.php
+++ b/public_html/libgit/base.php
@@ -25,6 +25,9 @@ function sha1_from_bin($bin)
class GitBranchNotFoundException extends Exception {}
class GitTagNotFoundException extends Exception {}
+class GitInvalidOriginException extends Exception {}
+class GitInvalidElementException extends Exception {}
+class GitPathNotFoundException extends Exception {}
require(dirname(__FILE__) . "/class.repository.php");
require(dirname(__FILE__) . "/class.branch.php");
diff --git a/public_html/libgit/class.repository.php b/public_html/libgit/class.repository.php
index b35c032..2ba563e 100644
--- a/public_html/libgit/class.repository.php
+++ b/public_html/libgit/class.repository.php
@@ -81,4 +81,52 @@ class GitRepository
throw new GitTagNotFoundException("The '{$name}' tag does not exist.");
}
}
+
+ function GetObjectForPath($origin, $path)
+ {
+ $path_parts = explode("/", $path);
+ $total_parts = count($path_parts);
+ $current_part = 0;
+
+ if(!($origin instanceof GitTree))
+ {
+ $origin = $this->GetObject($origin);
+ }
+
+ if($origin instanceof GitTree)
+ {
+ $current_tree = $origin;
+
+ for($i = 0; $i < $total_parts; $i++)
+ {
+ foreach($current_tree->elements as $element)
+ {
+ if($element->filename == $path_parts[$current_part])
+ {
+ $current_tree = $this->GetObject($element->hash);
+ pretty_dump($current_tree);
+
+ if($current_part != ($total_parts - 1) && !($current_tree instanceof GitTree))
+ {
+ throw new GitInvalidElementException("Encountered a non-GitTree object while walking the specified path.");
+ }
+
+ $current_part += 1;
+
+ continue 2;
+ }
+
+ }
+ pretty_dump($path_parts[$current_part]);
+ pretty_dump($current_tree);
+ throw new GitPathNotFoundException("The specified path was not found in the specified origin.");
+ }
+
+ return $current_tree;
+ }
+ else
+ {
+ throw new GitInvalidOriginException("You can only use a GitTree hash as origin.");
+ }
+ }
}
diff --git a/public_html/test.php b/public_html/test.php
index 479fb25..7def26f 100644
--- a/public_html/test.php
+++ b/public_html/test.php
@@ -2,4 +2,4 @@
require("libgit/base.php");
$repo = new GitRepository("/home/occupy/testrepo.git");
-pretty_dump($repo->GetBranch("master")->GetTree());
+pretty_dump($repo->GetObjectForPath($repo->GetBranch("master")->GetTree(), "public_html/css/images/derp"));