|
3 | 3 | php-git2 is a PHP bindings to the libgit2 linkable C Git library.
|
4 | 4 | this extension are re-writing php-git as that code too dirty.
|
5 | 5 |
|
6 |
| -# Important Notice |
7 |
| - |
8 |
| -php-git changed it's API drastically. this changes doesn't care about compatibility between old one. |
9 |
| -please check tests cases. |
10 |
| - |
11 |
| -# Installing And Running |
12 |
| - |
13 |
| -you need to install libgit2 before make php-git. |
14 |
| - |
15 |
| -```` |
16 |
| -git clone https://github.com/libgit2/php-git.git --recursive |
17 |
| -cd libgit2 |
18 |
| -mkdir build && cd build |
19 |
| -cmake .. |
20 |
| -cmake -DBUILD_SHARED_LIBS=OFF -build . |
21 |
| -make |
22 |
| -cd ../../ |
23 |
| -phpize |
24 |
| -./configure |
25 |
| -make |
26 |
| -make install |
27 |
| -sudo make install |
28 |
| -# add `extension=git2.so` to your php.ini |
29 |
| -```` |
30 |
| - |
31 |
| -new php-git features almost tested. |
32 |
| - |
33 |
| -# API |
34 |
| - |
35 |
| -## Repository Access |
36 |
| - |
37 |
| -````php |
38 |
| -$repo = new Git2\Repository($path); |
39 |
| -/* |
40 |
| - bool = $repo->exists(string sha1) |
41 |
| - Git2\Object = $repo->lookup(string sha1) |
42 |
| - string sha1 = $repo->hash(string content, long type) |
43 |
| - string sha1 = $repo->write(string content, long type) |
44 |
| - bool = $repo->isBare() |
45 |
| - bool = $repo->isEmpty() |
46 |
| - bool = $repo->headDetached() |
47 |
| - bool = $repo->headOrphan() |
48 |
| - string path = Git2\Repository::discover("/Users/chobie/projects/work/repo/lib/subdir"); |
49 |
| - // => /Users/chobie/projects/work/repo/.git |
50 |
| - |
51 |
| - Git2\Repository = Git2\Repository::init(string $path, bool isBare) |
52 |
| -*/ |
53 |
| -```` |
54 |
| - |
55 |
| -## Object Access |
56 |
| - |
57 |
| -### create new blob |
58 |
| - |
59 |
| -```` |
60 |
| -$oid = Git2\Blob::create($repo, "Hello World"); |
61 |
| -/* |
62 |
| - $blob = $repo->lookup($oid); |
63 |
| - int $blob->getSize(); |
64 |
| - string $blob->getContent(); |
65 |
| -*/ |
66 |
| -```` |
67 |
| - |
68 |
| -## Tree Access |
69 |
| - |
70 |
| -```` |
71 |
| -$repo = new Git2\Repository($path); |
72 |
| -$tree = $repo->lookup(tree sha); // specify tree sha |
73 |
| -foreach ($tree as $oid => $entry) { |
74 |
| -/* |
75 |
| - bool $entry->isTree(); |
76 |
| - bool $entry->isBlob(); |
77 |
| - bool $entry->isSubmodule(); |
78 |
| -*/ |
79 |
| - var_dump($entry); |
80 |
| -} |
81 |
| -```` |
82 |
| - |
83 |
| -## Ref Management |
84 |
| - |
85 |
| -```` |
86 |
| -$ref = Git2\Reference::lookup($repo, "refs/heads/master"); |
87 |
| - sha = $ref->getTarget(); |
88 |
| - str = $ref->getName(); |
89 |
| -```` |
90 |
| - |
91 |
| -```` |
92 |
| -foreach (Git2\Reference::each($repo) as $ref) { |
93 |
| - echo $ref->getName() . PHP_EOL; |
94 |
| -} |
95 |
| -```` |
96 |
| - |
97 |
| - |
98 |
| -## Commit |
99 |
| - |
100 |
| -```` |
101 |
| -<?php |
102 |
| -date_default_timezone_set('Asia/Tokyo'); |
103 |
| -$repo = Git2\Repository::init("/path/to/repo",true); |
104 |
| -
|
105 |
| -$author = new Git2\Signature("Shuhei Tanuma","[email protected]",new DateTime()); |
106 |
| -
|
107 |
| -$bld = new Git2\TreeBuilder(); |
108 |
| -$bld->insert(new Git2\TreeEntry(array( |
109 |
| - "name" => "README.txt", |
110 |
| - "oid" => "63542fbea05732b78711479a31557bd1b0aa2116", |
111 |
| - "attributes" => octdec('100644'), |
112 |
| -))); |
113 |
| -$tree = $bld->write($repo); |
114 |
| -
|
115 |
| -$parent = ""; |
116 |
| -$parents = array(); |
117 |
| -$parent = Git2\Commit::create($repo, array( |
118 |
| - "author" => $author, |
119 |
| - "committer" => $author, |
120 |
| - "message" => "Hello World", |
121 |
| - "tree" => $tree, |
122 |
| - "parents" => $parents, |
123 |
| -)); |
124 |
| -```` |
125 |
| - |
126 |
| -## Revision Walking |
127 |
| - |
128 |
| -```` |
129 |
| -$repo = new Git2\Repository($path); |
130 |
| -$walker = new Git2\Walker($repo); |
131 |
| -/* specify HEAD oid */ |
132 |
| -$walker->push("6e20138dc38f9f626107f1cd3ef0f9838c43defe"); |
133 |
| -
|
134 |
| -foreach ($walker as $oid => $commit) { |
135 |
| - printf("oid: %s\n", $oid); |
136 |
| - printf("message: %s\n", $commit->getMessage()); |
137 |
| -} |
138 |
| -```` |
139 |
| - |
140 |
| -## Config access |
141 |
| - |
142 |
| -```` |
143 |
| -$config = new Git2\Config("path/to/git/config"); |
144 |
| -$config->get("core.bare"); |
145 |
| -$config->store("core.bare","1"); |
146 |
| -
|
147 |
| -// Git2\Config supports read / write dimension. |
148 |
| -$config['core.bare'] |
149 |
| -$config['core.bare'] = 1; |
150 |
| -```` |
151 |
| - |
152 |
| -## ODB operation |
153 |
| - |
154 |
| -```` |
155 |
| -$repo = Git2\Repository::init("/path/to/repo",true); |
156 |
| -$odb = $repo->odb // read only property |
157 |
| -Git\OdbObject $odb->read(sha1) // returns uncompressed git raw data. |
158 |
| -string $odb->hash(string contents, int type)// same as Git2\Repository::hash |
159 |
| -string $odb->write(string contents, int type)// same as Git2\Repository::write |
160 |
| -bool $odb->exists(sha1)// same as Git2\Repository::exists |
161 |
| -```` |
162 |
| - |
163 |
| -## Reflog |
164 |
| -will be add. |
165 |
| - |
166 |
| -## Remote access (Experimental) |
167 |
| - |
168 |
| -this API will be change. |
169 |
| - |
170 |
| -```` |
171 |
| -$repo = new Git2\Repository("/path/to/.git"); |
172 |
| -$remote = new Git2\Remote($repo,"http://github.com/libgit2/php-git.git"); |
173 |
| -// for now, remote can fetch files only. that does not update references. |
174 |
| -$remote->fetch(); |
175 |
| -```` |
176 |
| - |
177 |
| -## Author |
178 |
| -* Shuhei Tanuma |
179 |
| - |
180 |
| -## Contributors |
181 |
| - |
182 |
| -* Anthony Van de Gejuchte |
183 |
| -* Cameron Eagans |
184 |
| -* Graham Weldon |
185 |
| -* James Titcumb |
186 |
| -* Matthieu Moquet |
187 |
| -* Ryusuke SEKIYAMA |
188 |
| -* Shuhei Tanuma |
189 |
| -* Vasileios Georgitzikis |
190 |
| -* tsteiner |
191 |
| - |
192 | 6 | ## LICENSE
|
193 | 7 |
|
194 | 8 | MIT License
|
0 commit comments