Skip to content

Commit fbc235a

Browse files
author
Tomáš Votruba
authored
Merge pull request #137 from cpliakas/release-prepare
Prepare 2.0 Release
2 parents d402504 + 8c6c58d commit fbc235a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2681
-3826
lines changed

.coveralls.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_name: travis-ci
2+
coverage_clover: coverage.xml
3+
json_path: coverage.json

.scrutinizer.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.travis.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
language: php
22

3-
php:
4-
- 7.2
5-
- 7.1
3+
matrix:
4+
include:
5+
- php: 7.1
6+
env: CODING_STANDARD=true
7+
- php: 7.1
8+
env: PHPSTAN=true
9+
- php: 7.1
10+
env: PHPUNIT_FLAGS="--coverage-clover coverage.xml"
11+
- php: 7.2
12+
13+
install:
14+
- composer install --prefer-dist
615

716
before_script:
817
- git --version
9-
- composer install --prefer-dist
1018

1119
script:
12-
- vendor/bin/phpunit --coverage-clover coverage.xml
20+
- vendor/bin/phpunit $PHPUNIT_FLAGS
21+
# disable xdebug
22+
- phpenv config-rm xdebug.ini || return 0
23+
- if [[ $CODING_STANDARD != "" ]]; then composer check-cs; fi
24+
- if [[ $PHPSTAN != "" ]]; then composer phpstan; fi
1325

1426
after_script:
15-
# upload coverage
16-
- wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
17-
- php coveralls.phar --verbose
27+
# upload coverage.xml to Coveralls
28+
- |
29+
if [[ $PHPUNIT_FLAGS != "" ]]; then
30+
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
31+
php coveralls.phar --verbose;
32+
fi
33+
34+
notifications:
35+
email: never

README.md

Lines changed: 47 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,56 @@
1-
# Overview
2-
3-
[![Build Status](https://travis-ci.org/cpliakas/git-wrapper.svg?branch=master)](https://travis-ci.org/cpliakas/git-wrapper)
4-
[![Code Coverage](https://scrutinizer-ci.com/g/cpliakas/git-wrapper/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/cpliakas/git-wrapper/?branch=master)
5-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cpliakas/git-wrapper/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/cpliakas/git-wrapper/?branch=master)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/cpliakas/git-wrapper.svg)](https://packagist.org/packages/cpliakas/git-wrapper)
7-
[![Latest Stable Version](https://img.shields.io/packagist/v/cpliakas/git-wrapper.svg)](https://packagist.org/packages/cpliakas/git-wrapper)
8-
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/cpliakas/git-wrapper/master/LICENSE)
9-
10-
This library is a PHP wrapper around the Git command line tool.
11-
12-
Its purpose is to provide a readable API that abstracts some of the challenges
13-
of executing Git commands from within a PHP process. Specifically, this library
14-
builds upon the Symfony framework's Process component to execute the Git command
15-
in a way that works across platforms and uses the best-in-breed techniques
16-
available to PHP. This library also provides an SSH wrapper script and API
17-
method for developers to easily specify a private key other than one of the
18-
defaults by using the technique in [this thread on StackOverflow](http://stackoverflow.com/a/3500308/870667).
19-
Finally, various commands are expected to be executed in the directory
20-
containing the working copy. Although this a fairly simple challenge to
21-
overcome, the library handles this transparently so the developer doesn't have
22-
to think about it.
1+
# PHP Wrapper around GIT
2+
3+
[![Build Status](https://img.shields.io/travis/cpliakas/git-wrapper/master.svg?style=flat-square)](https://travis-ci.org/cpliakas/git-wrapper)
4+
[![Coverage Status](https://img.shields.io/coveralls/cpliakas/git-wrapper/master.svg?style=flat-square)](https://coveralls.io/github/cpliakas/git-wrapper?branch=master)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/cpliakas/git-wrapper.svg?style=flat-square)](https://packagist.org/packages/cpliakas/git-wrapper)
6+
[![Latest Stable Version](https://img.shields.io/packagist/v/cpliakas/git-wrapper.svg?style=flat-square))](https://packagist.org/packages/cpliakas/git-wrapper)
7+
8+
Git Wrapper provides a **readable API that abstracts challenges of executing Git commands from within a PHP process** for you.
9+
10+
- It's built upon the [`Symfony\Process`](https://symfony.com/doc/current/components/process.html) to execute the Git command with **cross-platform support** and uses the best-in-breed techniques available to PHP.
11+
- This library also provides an SSH wrapper script and API method for developers to **easily specify a private key other than default** by using [the technique from StackOverflow](http://stackoverflow.com/a/3500308/870667).
12+
- Finally, various commands are expected to be executed in the directory containing the working copy. **The library handles this transparently** so the developer doesn't have to think about it.
13+
14+
## Install
15+
16+
```json
17+
composer require cpliakas/git-wrapper
18+
```
2319

2420
## Usage
2521

2622
```php
2723
use GitWrapper\GitWrapper;
2824

29-
// Initialize the library. If the path to the Git binary is not passed as
25+
// Initialize the library. If the path to the Git binary is not passed as
3026
// the first argument when instantiating GitWrapper, it is auto-discovered.
31-
require_once 'vendor/autoload.php';
32-
$wrapper = new GitWrapper();
27+
require_once __DIR__ . '/vendor/autoload.php';
3328

34-
// Optionally specify a private key other than one of the defaults.
35-
$wrapper->setPrivateKey('/path/to/private/key');
29+
$gitWrapper = new GitWrapper();
3630

37-
// Clone a repo into `/path/to/working/copy`, get a working copy object.
38-
$git = $wrapper->cloneRepository('git://github.com/cpliakas/git-wrapper.git', '/path/to/working/copy');
31+
// Optionally specify a private key other than one of the defaults
32+
$gitWrapper->setPrivateKey('/path/to/private/key');
3933

40-
// Create a file in the working copy.
34+
// Clone a repo into `/path/to/working/copy`, get a working copy object
35+
$git = $gitWrapper->cloneRepository('git://github.com/cpliakas/git-wrapper.git', '/path/to/working/copy');
36+
37+
// Create a file in the working copy
4138
touch('/path/to/working/copy/text.txt');
4239

43-
// Add it, commit it, and push the change.
44-
$git
45-
->add('test.txt')
46-
->commit('Added the test.txt file as per the examples.')
47-
->push();
40+
// Add it, commit it, and push the change
41+
$git->add('test.txt');
42+
$git->commit('Added the test.txt file as per the examples.');
43+
$git->push();
4844

49-
// Render the output.
45+
// Render the output
5046
print $git->getOutput();
5147

5248
// Stream output of subsequent Git commands in real time to STDOUT and STDERR.
53-
$wrapper->streamOutput();
49+
$gitWrapper->streamOutput();
5450

5551
// Execute an arbitrary git command.
5652
// The following is synonymous with `git config -l`
57-
$wrapper->git('config -l');
53+
$gitWrapper->git('config -l');
5854
```
5955

6056
All command methods adhere to the following paradigm:
@@ -69,20 +65,17 @@ passed to the Git command line tool. `$options` is an optional array of command
6965
line options in the following format:
7066

7167
```php
72-
$options = array(
68+
$options = [
7369
'verbose' => true, // Passes the "--verbose" flag.
7470
't' => 'my-branch', // Passes the "-t my-branch" option.
75-
);
71+
];
7672
```
7773

7874
#### Logging
7975

80-
Use the logger listener with [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)
81-
compatible loggers such as [Monolog](https://github.com/Seldaek/monolog) to log
82-
commands that are executed.
76+
Use the logger listener with [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) compatible loggers such as [Monolog](https://github.com/Seldaek/monolog) to log commands that are executed.
8377

8478
```php
85-
8679
use GitWrapper\Event\GitLoggerListener;
8780
use Monolog\Logger;
8881
use Monolog\Handler\StreamHandler;
@@ -98,63 +91,40 @@ $wrapper->addLoggerListener($listener);
9891
$git = $wrapper->cloneRepository('git://github.com/cpliakas/git-wrapper.git', '/path/to/working/copy');
9992

10093
// The "git.log" file now has info about the command that was executed above.
101-
10294
```
10395

104-
## Install via Composer
105-
106-
```json
107-
composer require cpliakas/git-wrapper
108-
```
10996

11097
## Gotchas
11198

112-
There are a few "gotchas" that are out of scope for this library to solve but
113-
might prevent a successful implementation of running Git via PHP. The following
114-
is an incomplete list of challenges that are often encountered when executing
115-
Git from PHP.
99+
There are a few "gotchas" that are out of scope for this library to solve but might prevent a successful implementation of running Git via PHP.
116100

117101
### Missing HOME Environment Variable
118102

119-
Sometimes the `HOME` environment variable is not set in the Git process that is
120-
spawned by PHP. This will cause many Git operations to fail. It is advisable to
121-
set the `HOME` environment variable to a path outside of the document root that
122-
the web server has write access to. Note that this environment variable is only
123-
set for the process running Git and NOT the PHP process that is spawns it.
103+
Sometimes the `HOME` environment variable is not set in the Git process that is spawned by PHP. This will cause many Git operations to fail. It is advisable to set the `HOME` environment variable to a path outside of the document root that the web server has write access to. Note that this environment variable is only set for the process running Git and NOT the PHP process that is spawns it.
124104

125105
```php
126-
$wrapper->setEnvVar('HOME', '/path/to/a/private/writable/dir');
106+
$gitWrapper->setEnvVar('HOME', '/path/to/a/private/writable/dir');
127107
```
128108

129-
It is important that the storage is persistent as the ~/.gitconfig file will be
130-
written to this location. See the following "gotcha" for why this is important.
109+
It is important that the storage is persistent as the `~/.gitconfig` file will be written to this location. See the following "gotcha" for why this is important.
131110

132111
### Missing Identity And Configurations
133112

134-
Many repositories require that a name and email address are specified. This data
135-
is set by running `git config [name] [value]` on the command line, and the
136-
configurations are usually stored in the `~/.gitconfig file`. When executing Git
137-
via PHP, however, the process might have a different home directory than the
138-
user who normally runs git via the command line. Therefore no identity is sent
139-
to the repository, and it will likely throw an error.
113+
Many repositories require that a name and email address are specified. This data is set by running `git config [name] [value]` on the command line, and the configurations are usually stored in the `~/.gitconfig file`. When executing Git via PHP, however, the process might have a different home directory than the user who normally runs git via the command line. Therefore no identity is sent to the repository, and it will likely throw an error.
140114

141115
```php
142116
// Set configuration options globally.
143-
$wrapper->git('config --global user.name "User name"');
144-
$wrapper->git('config --global user.email [email protected]');
117+
$gitWrapper->git('config --global user.name "User name"');
118+
$gitWrapper->git('config --global user.email [email protected]');
145119

146120
// Set configuration options per repository.
147121
$git->config('user.name', 'User name')
148-
->config('user.email', '[email protected]');
122+
$git->config('user.email', '[email protected]');
149123
```
150124

151125
### Commits To Repositories With No Changes
152126

153-
Running `git commit` on a repository with no changes returns no output but exits
154-
with a status of 1. Therefore the library will throw a `GitException` since it
155-
correctly detected an error. It is advisable to check whether a working copy has
156-
any changes prior to running the commit operation in order to prevent unwanted
157-
exceptions.
127+
Running `git commit` on a repository *with no changes* fails with exception. To prevent that, check changes like:
158128

159129
```php
160130
if ($git->hasChanges()) {
@@ -167,9 +137,5 @@ if ($git->hasChanges()) {
167137
On checkout, the bin/git-ssh-wrapper.sh script should be executable. If it is not, git commands with fail if a non-default private key is specified.
168138

169139
```bash
170-
$ chmod 0755 ./bin/git-ssh-wrapper.sh
140+
$ chmod +x ./bin/git-ssh-wrapper.sh
171141
```
172-
173-
## For Developers
174-
175-
Refer to [PHP Project Starter's documentation](https://github.com/cpliakas/php-project-starter#using-apache-ant) for the Apache Ant targets supported by this project.

composer.json

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"name": "cpliakas/git-wrapper",
3-
"type": "library",
43
"description": "A PHP wrapper around the Git command line utility.",
5-
"keywords": ["git"],
6-
"homepage": "https://github.com/cpliakas/git-wrapper",
4+
"keywords": ["git", "git wrapper", "cli"],
75
"license": "MIT",
86
"authors": [
97
{
@@ -17,21 +15,30 @@
1715
"symfony/event-dispatcher": "^4.0"
1816
},
1917
"require-dev": {
20-
"phpunit/phpunit": "^6.4",
18+
"phpunit/phpunit": "^6.5",
2119
"symfony/filesystem": "^4.0",
22-
"psr/log": "1.0"
23-
},
24-
"suggest": {
25-
"monolog/monolog": "Enables logging of executed git commands"
20+
"psr/log": "1.0",
21+
"symplify/easy-coding-standard": "^3.0",
22+
"slam/php-cs-fixer-extensions": "^1.10",
23+
"nette/utils": "^2.4",
24+
"phpstan/phpstan": "^0.9"
2625
},
2726
"autoload": {
2827
"psr-4": {
29-
"GitWrapper\\": "src/GitWrapper"
28+
"GitWrapper\\": "src"
3029
}
3130
},
3231
"autoload-dev": {
3332
"psr-4": {
34-
"GitWrapper\\Test\\": "test/GitWrapper/Test"
33+
"GitWrapper\\Test\\": "tests"
3534
}
35+
},
36+
"suggest": {
37+
"monolog/monolog": "Enables logging of executed git commands"
38+
},
39+
"scripts": {
40+
"check-cs": "vendor/bin/ecs check src tests",
41+
"fix-cs": "vendor/bin/ecs check src tests --fix",
42+
"phpstan": "vendor/bin/phpstan analyse src tests --level max --configuration phpstan.neon"
3643
}
3744
}

easy-coding-standard.neon

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
includes:
2+
- vendor/symplify/easy-coding-standard/config/psr2.neon
3+
- vendor/symplify/easy-coding-standard/config/php71.neon
4+
- vendor/symplify/easy-coding-standard/config/common.neon
5+
- vendor/symplify/easy-coding-standard/config/clean-code.neon
6+
7+
checkers:
8+
- SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff
9+
10+
# Symplify set
11+
- Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer
12+
- Symplify\CodingStandard\Sniffs\Naming\AbstractClassNameSniff
13+
- Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer
14+
- Symplify\CodingStandard\Fixer\Import\ImportNamespacedNameFixer
15+
- Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer
16+
- Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer
17+
18+
# Metrics
19+
PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff:
20+
absoluteLineLimit: 120
21+
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\CyclomaticComplexitySniff:
22+
absoluteComplexity: 6
23+
PHP_CodeSniffer\Standards\Generic\Sniffs\Metrics\NestingLevelSniff:
24+
absoluteNestingLevel: 4
25+
26+
# Class should be Final or Abstract
27+
- SlamCsFixer\FinalInternalClassFixer
28+
29+
parameters:
30+
exclude_checkers:
31+
- PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff
32+
33+
skip:
34+
SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff:
35+
- tests/TestLogger.php
36+
37+
SlamCsFixer\FinalInternalClassFixer:
38+
# class with children
39+
- src/Event/GitEvent.php

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#Call to an undefined method GitWrapper\\Event\\GitEvent::getName\(\)#'

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<phpunit
33
bootstrap="vendor/autoload.php"
44
colors="true"
5+
verbose="true"
56
>
6-
77
<testsuite>
8-
<directory suffix="Test.php">test</directory>
8+
<directory suffix="Test.php">tests</directory>
99
</testsuite>
1010

1111
<filter>

0 commit comments

Comments
 (0)