Skip to content

Commit acd7970

Browse files
Updated docs (#158)
1 parent 4849e9f commit acd7970

19 files changed

+75
-175
lines changed

.github/CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ Then run [PHPUnit](https://phpunit.de/):
2727
$ vendor/bin/phpunit
2828
```
2929

30+
* A script `test-git-version.sh` is available in repository to test gitlib against many git versions.
3031
* The tests will be automatically run by [Travis CI](https://travis-ci.org/) against pull requests.
3132
* We also have [StyleCI](https://styleci.io/) setup to automatically fix any code style issues.

README.md

+41-27
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,16 @@ Gitlib for Gitonomy
55
[![StyleCI](https://github.styleci.io/repos/5709354/shield?branch=master)](https://github.styleci.io/repos/5709354)
66
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT)
77

8-
This library provides methods to access Git repository from PHP.
8+
This library provides methods to access Git repository from PHP 5.6 or 7.
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
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)
34-
35-
## Quick Start
36-
37-
You can install gitlib using [Composer](https://getcomposer.org/). Simply
38-
require the version you need:
14+
Quick Start
15+
-----------
16+
17+
You can install gitlib using [Composer](https://getcomposer.org/). Simply require the version you need:
3918

4019
```bash
4120
$ composer require gitonomy/gitlib
@@ -51,7 +30,42 @@ or edit your `composer.json` file by hand:
5130
}
5231
```
5332

54-
## For Enterprise
33+
Example Usage
34+
-------------
35+
36+
```php
37+
<?php
38+
39+
use Gitonomy\Git\Repository;
40+
41+
$repository = new Repository('/path/to/repository');
42+
43+
foreach ($repository->getReferences()->getBranches() as $branch) {
44+
echo "- ".$branch->getName().PHP_EOL;
45+
}
46+
47+
$repository->run('fetch', ['--all']);
48+
```
49+
50+
API Documentation
51+
-----------------
52+
53+
+ [Admin](doc/admin.md)
54+
+ [Blame](doc/blame.md)
55+
+ [Blob](doc/blob.md)
56+
+ [Branch](doc/branch.md)
57+
+ [Commit](doc/commit.md)
58+
+ [Diff](doc/diff.md)
59+
+ [Hooks](doc/hooks.md)
60+
+ [Log](doc/log.md)
61+
+ [References](doc/references.md)
62+
+ [Repository](doc/repository.md)
63+
+ [Revision](doc/revision.md)
64+
+ [Tree](doc/tree.md)
65+
+ [Working Copy](doc/workingcopy.md)
66+
67+
For Enterprise
68+
--------------
5569

5670
Available as part of the Tidelift Subscription
5771

doc/api/admin.md doc/admin.md

File renamed without changes.

doc/api/blame.md doc/blame.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $blame = $repository->getBlame('master', 'README.md');
1111

1212
foreach ($blame->getLines() as $lineNumber => $line) {
1313
$commit = $line->getCommit();
14-
echo $lineNumber.': '.$line->getContent()." - ".$commit->getAuthorName()."\n";
14+
echo $lineNumber.': '.$line->getContent().' - '.$commit->getAuthorName().PHP_EOL;
1515
}
1616
```
1717

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ You can also test if *Blob* is a text of a binary file:
3737

3838
```php
3939
if ($blob->isText()) {
40-
echo $blob->getContent(), "\n";
40+
echo $blob->getContent(), PHP_EOL;
4141
} elseif ($blob->isBinary()) {
42-
echo "File is binary\n";
42+
echo 'File is binary', PHP_EOL;
4343
}
4444
```

doc/api/branch.md doc/branch.md

File renamed without changes.

doc/api/commit.md doc/commit.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For example, if you want to display all parents, starting from a commit:
3131

3232
```php
3333
function displayLog(Gitonomy\Git\Commit $commit) {
34-
echo '- '.$commit->getShortMessage()."\n";
34+
echo '- '.$commit->getShortMessage().PHP_EOL;
3535
foreach ($commit->getParents() as $parent) {
3636
displayLog($parent);
3737
}
@@ -155,10 +155,10 @@ Here is a very straightforward example:
155155
```php
156156
$last = $commit->getLastModification('README');
157157

158-
echo "Last README modification:\n";
159-
echo" Author: ".$last->getAuthorName()."\n";
160-
echo" Date: ".$last->getAuthorDate()->format('d/m/Y')."\n";
161-
echo" Message: ".$last->getMessage();
158+
echo 'Last README modification'.PHP_EOL;
159+
echo ' Author: '.$last->getAuthorName().PHP_EOL;
160+
echo ' Date: '.$last->getAuthorDate()->format('d/m/Y').PHP_EOL;
161+
echo ' Message: '.$last->getMessage();
162162
```
163163

164164
Find every branches containing a commit

doc/debug.md

-24
This file was deleted.

doc/development.md

-18
This file was deleted.

doc/api/diff.md doc/diff.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ represents the modifications for a single file.
3232

3333
```php
3434
$files = $diff->getFiles();
35-
echo sprintf("%s files modified", count($files));
35+
echo sprintf('%s files modified%s', count($files), PHP_EOL);
3636

3737
foreach ($files as $fileDiff) {
38-
echo sprintf("Old name: (%s) %s\n", $fileDiff->getOldMode(), $fileDiff->getOldName());
39-
echo sprintf("New name: (%s) %s\n", $fileDiff->getNewMode(), $fileDiff->getNewName());
38+
echo sprintf('Old name: (%s) %s%s', $fileDiff->getOldMode(), $fileDiff->getOldName(), PHP_EOL);
39+
echo sprintf('New name: (%s) %s%s', $fileDiff->getNewMode(), $fileDiff->getNewName(), PHP_EOL);
4040
}
4141
```
4242

@@ -86,11 +86,11 @@ foreach ($changes as $change) {
8686
foreach ($lines as $data) {
8787
list ($type, $line) = $data;
8888
if ($type === FileChange::LINE_CONTEXT) {
89-
echo ' '.$line."\n";
89+
echo ' '.$line.PHP_EOL;
9090
} elseif ($type === FileChange::LINE_ADD) {
91-
echo '+'.$line."\n";
91+
echo '+'.$line.PHP_EOL;
9292
} else {
93-
echo '-'.$line."\n";
93+
echo '-'.$line.PHP_EOL;
9494
}
9595
}
9696
}
@@ -99,6 +99,6 @@ foreach ($changes as $change) {
9999
To get line numbers, use the range methods:
100100

101101
```php
102-
echo sprintf("Previously from line %s to %s\n", $change->getOldRangeStart(), $change->getOldRangeEnd());
103-
echo sprintf("Now from line %s to %s\n", $change->getNewRangeStart(), $change->getNewRangeEnd());
102+
echo sprintf('Previously from line %s to %s%s', $change->getOldRangeStart(), $change->getOldRangeEnd(), PHP_EOL);
103+
echo sprintf('Now from line %s to %s%s', $change->getNewRangeStart(), $change->getNewRangeEnd(), PHP_EOL);
104104
```

doc/api/hooks.md doc/hooks.md

File renamed without changes.

doc/index.md

-46
This file was deleted.

doc/installation.md

-27
This file was deleted.

doc/api/log.md doc/log.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $log = $repository->getLog('master');
2424
$log = $repository->getLog('master', 'README', 0, 10);
2525

2626
// Returns last 10 commits on README or UPGRADE files
27-
$log = $repository->getLog('master', array('README', 'UPGRADE'), 0, 10);
27+
$log = $repository->getLog('master', ['README', 'UPGRADE'], 0, 10);
2828
```
2929

3030
Counting
@@ -34,10 +34,10 @@ If you want to count overall commits, without offset or limit, use the
3434
*countCommits* method:
3535

3636
```php
37-
echo sprintf("This log contains %s commits\n", $log->countCommits());
37+
echo sprintf('This log contains %s commits%s', $log->countCommits(), PHP_EOL);
3838

3939
// Countable interface
40-
echo sprintf("This log contains %s commits\n", count($log));
40+
echo sprintf('This log contains %s commits%s', count($log), PHP_EOL);
4141
```
4242

4343
Offset and limit

doc/api/references.md doc/references.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ First, you can test existence of tags and branches like this:
1515

1616
```php
1717
if ($references->hasBranch('master') && $references->hasTag('0.1')) {
18-
echo "Good start!";
18+
echo 'Good start!'.PHP_EOL;
1919
}
2020
```
2121

0 commit comments

Comments
 (0)