Browse Source

Get tags and trees

master
Sven Slootweg 10 years ago
parent
commit
76602755be
  1. 1
      public_html/libgit/base.php
  2. 5
      public_html/libgit/class.branch.php
  3. 5
      public_html/libgit/class.commit.php
  4. 17
      public_html/libgit/class.repository.php
  5. 10
      public_html/libgit/class.tag.php
  6. 2
      public_html/test.php

1
public_html/libgit/base.php

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

5
public_html/libgit/class.branch.php

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

5
public_html/libgit/class.commit.php

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

17
public_html/libgit/class.repository.php

@ -63,7 +63,22 @@ class GitRepository
}
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.");
}
}
}

10
public_html/libgit/class.tag.php

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

2
public_html/test.php

@ -2,7 +2,7 @@
require("libgit/base.php");
$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("98d99489382a3541e6783bb2083554785f3eb72a"));

Loading…
Cancel
Save