A git wrapper for Yii, allows access to all git commands programatically
PHP
Pull request Compare This branch is 4 commits behind phpnode:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
tests
AGitBranch.php
AGitCommit.php
AGitException.php
AGitRemote.php
AGitRepository.php
AGitTag.php
README.md
package.json

README.md

Introduction

A Yii wrapper for the git command line executable. Allows access to all git commands via a simple object oriented interface.

Usage examples

Add some files and folders to git

$repository = new AGitRepository("path/to/your/git/repo");
$repository->add("somefile.txt");
$repository->add("somedirectory");

Commit some files with git

$repository->commit("Added some files");

Checkout an existing branch

$repository->checkout("some-existing-branch");
echo $repository->activeBranch->name; // some-existing-branch

Checkout a new branch

$repository->checkout("some-new-branch", true);
echo $repository->activeBranch->name; // some-new-branch

List all branches

foreach($repository->branches as $branch) {
    echo $branch->name."\n";
}

List all tags with metadata

foreach($repository->tags as $tag) {
    echo $tag->name"\n";
    echo $tag->authorName"\n";
    echo $tag->authorEmail"\n";
    echo $tag->message"\n";
}

List all the commits on the current branch

foreach($repository->activeBranch->commits as $commit) {
    echo $commit->authorName." at ".$commit->time."\n";
    echo $commit->message."\n";
    echo str_repeat("-",50)."\n";
}

List all the files affected by the latest commit

foreach($repository->activeBranch->latestCommit->files as $file) {
    echo $file."\n";
}

Check if a tag exists on the default remote ('origin')

$repository->remote->hasTag('myTag');

List all branches on a remote repository called 'upstream'

foreach($repository->getRemote('upstream')->getBranches() as $branch) {
    echo $branch."\n";
}

API

AGitRepository

setPath($path, $createIfEmpty = false, $initialize = false)
getPath()
run($command)
add($file)
rm($file, $force = false)
commit($message = null, $addFiles = false, $amend = false)
status()
describe($options = '')
checkout($branchName, $create = false, $force = false)
clean($deleteDirectories = false, $force = false)
cloneTo($targetDirectory)
cloneFrom($targetDirectory)
cloneRemote($sourceUrl)
push($remote, $branch = "master", $force = false)
fetch($repository)
getActiveBranch()
getBranches()
hasBranch($branch)
createBranch($branchName)
deleteBranch($branchName, $force = false)
getCommit($hash)
getTags()
getTag($name)
hasTag($tag)
addTag($name, $message, $hash = null)
removeTag($tag)
getRemotes()
getRemote($remote = null)
hasCommit($hash)

AGitCommit

getAuthorName()
getAuthorEmail()
getTime()
getSubject()
getMessage()
getNotes()
getParents()
getFiles()

AGitBranch

getCommits()
getCommit($hash)
getLastCommit()

AGitTag

push($remote = null)
getAuthorName()
getAuthorEmail()
getMessage()
getCommit()

AGitRemote

getBranches()
hasBranch($branch)
deleteBranch($branchName)
getTags()
hasTag($tag)