2017 © Pedro Peláez
 

library git

PHP git wrapper

image

sebastianfeldmann/git

PHP git wrapper

  • Tuesday, October 3, 2017
  • by sebastianfeldmann
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5,624 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 9 Versions
  • 54 % Grown

The README.md

git - a handy git wrapper

Latest Stable Version Minimum PHP Version Downloads License Build Status Scrutinizer Code Quality Code Coverage, (*1)

This lib is used to execute git commands directly from PHP via a defined api. All you have to do is setup a Repository object, retrieve a command Operator and fire away. Each git command like git config or git log is handled by a separate Operator. Follow the next steps to give it a try., (*2)

Installation

The git package is installable via composer. Just run the following command., (*3)

$ composer require sebastianfeldmann/git

Usage

Setup the Repository, (*4)

$repoRootPath  = '/var/www/my-project';
$gitRepository = new Git\Repository($repoRootPath);

Retrieve the needed Operator, (*5)

$log = $gitRepository->getLogOperator();

Get files and commits since some tag, (*6)

$files   = $log->getChangedFilesSince('1.0.0');
$commits = $log->getCommitsSince('1.0.0');

Copy Paste Example

use SebastianFeldmann\Git;

require __DIR__ . '/../vendor/autoload.php';

// path to repository without .git
$repoRootPath  = '/path/to/repo';
$gitRepository = new Git\Repository($repoRootPath);

// get files and commits since hash or tag
$log     = $gitRepository->getLogOperator();
$files   = $log->getChangedFilesSince('1.0.0');
$commits = $log->getCommitsSince('1.0.0');

// check the index status
$index = $gitRepository->getIndexOperator();
$files = $index->getStagedFiles();

Available operators

  • Config - Access all git settings e.g. line break settings.
  • Diff - Compare two versions.
  • Index - Check the staging area.
  • Info - Access the current state like branch name or commit hash.
  • Log - Returns list of changed files and other git log information.

Example commands

Get the current tag:, (*7)

// git describe --tag
$tag = $infoOperator->getCurrentTag();

Get tags for a given commit:, (*8)

// git tag --points-at HEAD
$tags = $infoOperator->getTagsPointingTo('HEAD');

Get the current branch:, (*9)

// git rev-parse --abbrev-ref HEAD
$branch = $infoOperator->getCurrentBranch();

Get a list of staged files:, (*10)

// git diff-index --cached --name-status HEAD
$files = $indexOperator->getStagedFiles();

Get all current git settings:, (*11)

// git config --list
$config = $configOperator->getSettings();

Get all changed files since a given commit or tag:, (*12)

// git log --format='' --name-only $HASH
$files = $logOperator->changedFilesSince('1.0.0');

Get differences between two versions, (*13)

// git diff '1.0.0' '1.1.0'
$changes = $diffOperator->compare('1.0.0', '1.1.0');

The Versions

03/10 2017

dev-master

9999999-dev https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

03/10 2017

1.0.7

1.0.7.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

21/07 2017

1.0.6

1.0.6.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

24/05 2017

1.0.5

1.0.5.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

25/04 2017

1.0.4

1.0.4.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

22/04 2017

1.0.3

1.0.3.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

21/04 2017

1.0.2

1.0.2.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

29/01 2017

1.0.1

1.0.1.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git

23/01 2017

1.0.0

1.0.0.0 https://github.com/sebastianfeldmann/git

PHP git wrapper

  Sources   Download

MIT

The Requires

 

by Sebastian Feldmann

git