Skip to content

Commit

Permalink
Updated docs (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored Dec 13, 2019
1 parent 4849e9f commit acd7970
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 175 deletions.
1 change: 1 addition & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ Then run [PHPUnit](https://phpunit.de/):
$ vendor/bin/phpunit
```

* A script `test-git-version.sh` is available in repository to test gitlib against many git versions.
* The tests will be automatically run by [Travis CI](https://travis-ci.org/) against pull requests.
* We also have [StyleCI](https://styleci.io/) setup to automatically fix any code style issues.
68 changes: 41 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,16 @@ Gitlib for Gitonomy
[![StyleCI](https://github.styleci.io/repos/5709354/shield?branch=master)](https://github.styleci.io/repos/5709354)
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT)

This library provides methods to access Git repository from PHP.
This library provides methods to access Git repository from PHP 5.6 or 7.

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

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

## Documentation

* [Overview](doc/index.md)
* [Debug](doc/debug.md)
* [Development](doc/development.md)
* [Installation](doc/installation.md)
* API
+ [Admin](doc/api/admin.md)
+ [Blame](doc/api/blame.md)
+ [Blob](doc/api/blob.md)
+ [Branch](doc/api/branch.md)
+ [Commit](doc/api/commit.md)
+ [Diff](doc/api/diff.md)
+ [Hooks](doc/api/hooks.md)
+ [Log](doc/api/log.md)
+ [References](doc/api/references.md)
+ [Repository](doc/api/repository.md)
+ [Revision](doc/api/revision.md)
+ [Tree](doc/api/tree.md)
+ [Working Copy](doc/api/workingcopy.md)

## Quick Start

You can install gitlib using [Composer](https://getcomposer.org/). Simply
require the version you need:
Quick Start
-----------

You can install gitlib using [Composer](https://getcomposer.org/). Simply require the version you need:

```bash
$ composer require gitonomy/gitlib
Expand All @@ -51,7 +30,42 @@ or edit your `composer.json` file by hand:
}
```

## For Enterprise
Example Usage
-------------

```php
<?php

use Gitonomy\Git\Repository;

$repository = new Repository('/path/to/repository');

foreach ($repository->getReferences()->getBranches() as $branch) {
echo "- ".$branch->getName().PHP_EOL;
}

$repository->run('fetch', ['--all']);
```

API Documentation
-----------------

+ [Admin](doc/admin.md)
+ [Blame](doc/blame.md)
+ [Blob](doc/blob.md)
+ [Branch](doc/branch.md)
+ [Commit](doc/commit.md)
+ [Diff](doc/diff.md)
+ [Hooks](doc/hooks.md)
+ [Log](doc/log.md)
+ [References](doc/references.md)
+ [Repository](doc/repository.md)
+ [Revision](doc/revision.md)
+ [Tree](doc/tree.md)
+ [Working Copy](doc/workingcopy.md)

For Enterprise
--------------

Available as part of the Tidelift Subscription

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion doc/api/blame.md → doc/blame.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $blame = $repository->getBlame('master', 'README.md');

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

Expand Down
4 changes: 2 additions & 2 deletions doc/api/blob.md → doc/blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ You can also test if *Blob* is a text of a binary file:

```php
if ($blob->isText()) {
echo $blob->getContent(), "\n";
echo $blob->getContent(), PHP_EOL;
} elseif ($blob->isBinary()) {
echo "File is binary\n";
echo 'File is binary', PHP_EOL;
}
```
File renamed without changes.
10 changes: 5 additions & 5 deletions doc/api/commit.md → doc/commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ For example, if you want to display all parents, starting from a commit:

```php
function displayLog(Gitonomy\Git\Commit $commit) {
echo '- '.$commit->getShortMessage()."\n";
echo '- '.$commit->getShortMessage().PHP_EOL;
foreach ($commit->getParents() as $parent) {
displayLog($parent);
}
Expand Down Expand Up @@ -155,10 +155,10 @@ Here is a very straightforward example:
```php
$last = $commit->getLastModification('README');

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

Find every branches containing a commit
Expand Down
24 changes: 0 additions & 24 deletions doc/debug.md

This file was deleted.

18 changes: 0 additions & 18 deletions doc/development.md

This file was deleted.

16 changes: 8 additions & 8 deletions doc/api/diff.md → doc/diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ represents the modifications for a single file.

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

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

Expand Down Expand Up @@ -86,11 +86,11 @@ foreach ($changes as $change) {
foreach ($lines as $data) {
list ($type, $line) = $data;
if ($type === FileChange::LINE_CONTEXT) {
echo ' '.$line."\n";
echo ' '.$line.PHP_EOL;
} elseif ($type === FileChange::LINE_ADD) {
echo '+'.$line."\n";
echo '+'.$line.PHP_EOL;
} else {
echo '-'.$line."\n";
echo '-'.$line.PHP_EOL;
}
}
}
Expand All @@ -99,6 +99,6 @@ foreach ($changes as $change) {
To get line numbers, use the range methods:

```php
echo sprintf("Previously from line %s to %s\n", $change->getOldRangeStart(), $change->getOldRangeEnd());
echo sprintf("Now from line %s to %s\n", $change->getNewRangeStart(), $change->getNewRangeEnd());
echo sprintf('Previously from line %s to %s%s', $change->getOldRangeStart(), $change->getOldRangeEnd(), PHP_EOL);
echo sprintf('Now from line %s to %s%s', $change->getNewRangeStart(), $change->getNewRangeEnd(), PHP_EOL);
```
File renamed without changes.
46 changes: 0 additions & 46 deletions doc/index.md

This file was deleted.

27 changes: 0 additions & 27 deletions doc/installation.md

This file was deleted.

6 changes: 3 additions & 3 deletions doc/api/log.md → doc/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $log = $repository->getLog('master');
$log = $repository->getLog('master', 'README', 0, 10);

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

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

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

// Countable interface
echo sprintf("This log contains %s commits\n", count($log));
echo sprintf('This log contains %s commits%s', count($log), PHP_EOL);
```

Offset and limit
Expand Down
2 changes: 1 addition & 1 deletion doc/api/references.md → doc/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ First, you can test existence of tags and branches like this:

```php
if ($references->hasBranch('master') && $references->hasTag('0.1')) {
echo "Good start!";
echo 'Good start!'.PHP_EOL;
}
```

Expand Down
Loading

0 comments on commit acd7970

Please sign in to comment.