Skip to content

Commit 4849e9f

Browse files
phpfuiGrahamCampbell
authored andcommitted
Update documentation (#157)
1 parent a0bea92 commit 4849e9f

35 files changed

+1091
-1052
lines changed

README.md

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
Git lib for Gitonomy
2-
====================
1+
Gitlib for Gitonomy
2+
===================
33

44
[![Build Status](https://img.shields.io/travis/gitonomy/gitlib/master.svg?style=flat-square)](https://travis-ci.org/gitonomy/gitlib)
55
[![StyleCI](https://github.styleci.io/repos/5709354/shield?branch=master)](https://github.styleci.io/repos/5709354)
6-
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="Software License"></img></a>
6+
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT)
77

88
This library provides methods to access Git repository from PHP.
99

1010
It makes shell calls, which makes it less performant than any solution.
1111

1212
Anyway, it's convenient and don't need to build anything to use it. That's how we love it.
1313

14-
*Documentation*: http://gitonomy.com/doc/gitlib/master/
14+
## Documentation
15+
16+
* [Overview](doc/index.md)
17+
* [Debug](doc/debug.md)
18+
* [Development](doc/development.md)
19+
* [Installation](doc/installation.md)
20+
* API
21+
+ [Admin](doc/api/admin.md)
22+
+ [Blame](doc/api/blame.md)
23+
+ [Blob](doc/api/blob.md)
24+
+ [Branch](doc/api/branch.md)
25+
+ [Commit](doc/api/commit.md)
26+
+ [Diff](doc/api/diff.md)
27+
+ [Hooks](doc/api/hooks.md)
28+
+ [Log](doc/api/log.md)
29+
+ [References](doc/api/references.md)
30+
+ [Repository](doc/api/repository.md)
31+
+ [Revision](doc/api/revision.md)
32+
+ [Tree](doc/api/tree.md)
33+
+ [Working Copy](doc/api/workingcopy.md)
1534

1635
## Quick Start
1736

18-
You can install git lib using [Composer](https://getcomposer.org/). Simply require the version you need:
37+
You can install gitlib using [Composer](https://getcomposer.org/). Simply
38+
require the version you need:
1939

2040
```bash
2141
$ composer require gitonomy/gitlib
@@ -26,7 +46,7 @@ or edit your `composer.json` file by hand:
2646
```json
2747
{
2848
"require": {
29-
"gitonomy/gitlib": "^1.1"
49+
"gitonomy/gitlib": "^1.2"
3050
}
3151
}
3252
```

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"email": "[email protected]"
2121
}
2222
],
23-
"homepage": "http://gitonomy.com",
2423
"autoload": {
2524
"psr-4": {
2625
"Gitonomy\\Git\\": "src/Gitonomy/Git/"

doc/api/admin.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
Create and access git repositories
2+
==================================
3+
4+
gitlib provides methods to initialize new repositories.
5+
6+
Create a repository
7+
-------------------
8+
9+
To initialize a new repository, use method `Admin::init`.
10+
11+
```php
12+
// Initialize a bare repository
13+
$repository = Gitonomy\Git\Admin::init('/path/to/repository');
14+
15+
// Initialize a non-bare repository
16+
$repository = Gitonomy\Git\Admin::init('/path/to/repository', false);
17+
```
18+
19+
Default behavior is to create a bare repository. If you want to
20+
initialize a repository with a working copy,pass `false` as third
21+
argument of Repository constructor.
22+
23+
Cloning repositories
24+
--------------------
25+
26+
You can clone a repository from an URL by doing:
27+
28+
```php
29+
// Clone to a bare repository
30+
$repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git');
31+
32+
// Clone to a non-bare repository
33+
$repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', false);
34+
```
35+
36+
Default behavior is to clone in a bare repository.
37+
38+
You can also clone a repository and point it to a specific branch. In a
39+
non-bare repository, this branch will be checked out:
40+
41+
```php
42+
// Clone to a bare repository
43+
$repository = Gitonomy\Git\Admin::cloneBranchTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', 'a-branch');
44+
45+
// Clone to a non-bare repository
46+
$repository = Gitonomy\Git\Admin::cloneBranchTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', 'a-branch' false);
47+
```
48+
49+
Clone a Repository object
50+
-------------------------
51+
52+
If you already have a Repository instance and want to clone it, you can
53+
use this shortcut:
54+
55+
```php
56+
$new = $repository->cloneTo('/tmp/clone');
57+
```
58+
59+
Mirror a repository
60+
-------------------
61+
62+
If you want to mirror fully a repository and all references, use the
63+
`mirrorTo` method. This method takes only two arguments, where to mirror
64+
and what to mirror:
65+
66+
```php
67+
// Mirror to a bare repository
68+
$mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', 'https://github.com/gitonomy/gitlib.git');
69+
70+
// Mirror to a non-bare repository
71+
$mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', 'https://github.com/gitonomy/gitlib.git', false);
72+
```
73+
74+
### References
75+
76+
- <http://linux.die.net/man/1/git-init>
77+
- <http://linux.die.net/man/1/git-clone>

doc/api/admin.rst

-76
This file was deleted.

doc/api/blame.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Blaming files
2+
=============
3+
4+
Line-per-line iteration
5+
-----------------------
6+
7+
To iterate on lines of a blame:
8+
9+
```php
10+
$blame = $repository->getBlame('master', 'README.md');
11+
12+
foreach ($blame->getLines() as $lineNumber => $line) {
13+
$commit = $line->getCommit();
14+
echo $lineNumber.': '.$line->getContent()." - ".$commit->getAuthorName()."\n";
15+
}
16+
```
17+
18+
The *getLines* method returns an array indexed starting from 1.
19+
20+
As you can see, you can access the commit object related to the line you
21+
are iterating on.
22+
23+
If you want to access directly a line:
24+
25+
```php
26+
$line = $blame->getLine(32);
27+
```
28+
29+
The Line object
30+
---------------
31+
32+
LineObject represents an item of the blame file. It is composed of those
33+
informations:
34+
35+
```php
36+
$line->getCommit(); // returns a Commit
37+
$line->getContent(); // returns text
38+
39+
// you can access author from commmit:
40+
$author = $line->getCommit()->getAuthorName();
41+
```
42+
43+
Group reading by commit
44+
-----------------------
45+
46+
If you plan to display it, you'll probably need a version where lines
47+
from same commit are grouped.
48+
49+
To do so, use the *getGroupedLines* method that will return an array
50+
like this:
51+
52+
```php
53+
$blame = array(
54+
array(Commit, array(1 => Line, 2 => Line, 3 => Line)),
55+
array(Commit, array(4 => Line)),
56+
array(Commit, array(5 => Line, 6 => Line))
57+
)
58+
```

doc/api/blame.rst

-54
This file was deleted.

doc/api/blob.rst doc/api/blob.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@ Blob
22
====
33

44
In git, a blob represents a file content. You can't access the file name
5-
directly from the *Blob* object; the filename information is stored within
6-
the tree, not in the blob.
5+
directly from the *Blob* object; the filename information is stored
6+
within the tree, not in the blob.
77

8-
It means that for git, two files with different names but same content will
9-
have the same hash.
8+
It means that for git, two files with different names but same content
9+
will have the same hash.
1010

1111
To access a repository *Blob*, you need the hash identifier:
1212

13-
.. code-block:: php
14-
15-
$repository = new Gitonomy\Git\Repository('/path/to/repository');
16-
$blob = $repository->getBlob('a7c8d2b4');
13+
```php
14+
$repository = new Gitonomy\Git\Repository('/path/to/repository');
15+
$blob = $repository->getBlob('a7c8d2b4');
16+
```
1717

1818
Get content
1919
-----------
2020

2121
To get content from a *Blob* object:
2222

23-
.. code-block:: php
24-
25-
echo $blob->getContent();
23+
```php
24+
echo $blob->getContent();
25+
```
2626

2727
File informations
2828
-----------------
2929

3030
To get mimetype of a *Blob* object using finfo extension:
3131

32-
.. code-block:: php
33-
34-
echo $blob->getMimetype();
32+
```php
33+
echo $blob->getMimetype();
34+
```
3535

3636
You can also test if *Blob* is a text of a binary file:
3737

38-
.. code-block:: php
39-
40-
if ($blob->isText()) {
41-
echo $blob->getContent(), "\n";
42-
} elseif ($blob->isBinary()) {
43-
echo "File is binary\n";
44-
}
38+
```php
39+
if ($blob->isText()) {
40+
echo $blob->getContent(), "\n";
41+
} elseif ($blob->isBinary()) {
42+
echo "File is binary\n";
43+
}
44+
```

0 commit comments

Comments
 (0)