Implement Blob, Tree and Lazy, add tests for Tree.
[phpgit.git] / library / Git / Repo.php
blob69181ae1c1d5e62613d2e52a541887ec14e2df4e
1 <?php
3 /**
4 * Represents a Git repository, and allows access to history, snapshots,
5 * commits, et cetera.
6 */
7 class Git_Repo {
9 const DAEMON_EXPORT_FILE = 'git-daemon-export-ok';
11 /**
12 * Path to this repository.
14 public $path;
16 /**
17 * Whether or not this is a bare repository.
19 public $bare;
21 /**
22 * Interface to Git itself.
24 public $git;
26 /**
27 * @param $path Path to the repository (either working copy or bare)
29 public function __construct($path) {
30 $path = realpath($path);
31 if (file_exists($p = $path . Git::S . '.git')) {
32 $this->path = $p;
33 $this->bare = false;
34 } elseif (file_exists($path) && strlen($path) >= 4 && substr($path, -4) == '.git') {
35 $this->path = $path;
36 $this->bare = true;
37 } elseif (!file_exists($path)) {
38 throw new Git_Exception_InvalidRepository();
40 $this->git = new Git($this->path);
43 // * means will implement soon
45 // public function description() {
46 // * public function heads() {
47 // * public function branches() {return $this->heads();}
48 // public function tags() {
49 // * public function commits($start, $max_count, $skip) {
50 // public function commitsBetween($frm, $to) {
51 // public function commitsSince($start = 'master', $since) {
52 // public function commitCount($start = 'master') {
53 // * public function commit($id) {
54 // public function commitDeltasFrom($other_repo, $ref = 'master', $other_ref = 'master') {
55 /**
56 * Returns the Git_Tree object for a given treeish reference.
57 * @param $treeish Reference to retrieve, can be branch name, or filename
58 * @param $paths Optional array of directory paths to restrict to.
59 * @return Git_Tree for that path.
61 public function tree($treeish = 'master', $paths = array()) {
62 return Git_Tree::construct($this, $treeish, $paths);
64 // * public function blob($id) {
66 /**
67 * Returns the commit log for a treeish entity.
68 * @param $commit Commit to get log of, or commit range like begin..end
69 * @param $path Path (or paths) to get logs for
70 * @param $kwargs Extra arguments, see Git->transformArgs()
72 public function log($commit = 'master', $path = null, $kwargs = array()) {
73 $options = array_merge(array('pretty' => 'raw'), $kwargs);
74 if ($path) {
75 $arg = array($commit, '--', $path);
76 } else {
77 $arg = array($commit);
79 $commits = $this->git->log($path, $options);
80 return Git_Commit::listFromString($this, $commits);
83 // public function diff($a, $b, $paths = array()) {
84 // public function commitDiff($commit) {
85 // public static function initBare($path, $kwargs) {
86 // public static function forkBare($path, $kwargs) {
87 // public function archiveTar($treeish = 'master', $prefix = null) {
88 // public function archiveTarGz($treeish = 'master', $prefix = null) {
89 // public function enableDaemonServe() {
90 // public function disableDaemonServe() {
91 // ? private function _getAlternates() {
92 // ? private function _setAlternates() {
94 public function __toString() {
95 return '(Git_Repo "'. $this->path .'")';