class GitRepo

Git Repository Interface Class

This class enables the creating, reading, and manipulation of a git repository

Properties

protected $repo_path
protected $bare
protected $envopts

Methods

static GitRepo
create_new($repo_path, $source = null, $remote_source = false, $reference = null)

Create a new git repository

void
__construct($repo_path = null, $create_new = false, $_init = true)

Constructor

void
set_repo_path(string $repo_path, bool $create_new = false, bool $_init = true)

Set the repository's path

string
git_directory_path()

Get the path to the git repo directory (eg. the ".git" directory)

bool
test_git()

Tests if git is installed

string
run_command(string $command)

Run a command in the git repository

string
run(string $command)

Run a git command in the git repository

string
status(bool $html = false)

Runs a 'git status' call

string
add(mixed $files = "*")

Runs a git add call

string
rm(mixed $files = "*", Boolean $cached = false)

Runs a git rm call

string
commit(string $message = "", boolean $commit_all = true)

Runs a git commit call

string
clone_to(string $target)

Runs a git clone call to clone the current repository into a different directory

string
clone_from(string $source)

Runs a git clone call to clone a different repository into the current repository

string
clone_remote(string $source, string $reference)

Runs a git clone call to clone a remote repository into the current repository

string
clean(bool $dirs = false, bool $force = false)

Runs a git clean call

string
create_branch(string $branch)

Runs a git branch call

string
delete_branch($branch, $force = false)

Runs a git branch -[d|D] call

array
list_branches(bool $keep_asterisk = false)

Runs a git branch call

array
list_remote_branches()

Lists remote branches (using git branch -r).

string
active_branch(bool $keep_asterisk = false)

Returns name of active branch

string
checkout(string $branch)

Runs a git checkout call

string
merge(string $branch)

Runs a git merge call

string
fetch()

Runs a git fetch on the current branch

string
add_tag(string $tag, string $message = null)

Add a new tag on the current position

array
list_tags(string $pattern = null)

List all the available repository tags.

string
push(string $remote, string $branch)

Push specific branch to a remote

string
pull(string $remote, string $branch)

Pull specific branch from remote

string
log(strgin $format = null)

List log entries.

set_description(string $new)

Sets the project description.

string
get_description()

Gets the project description.

setenv(string $key, string $value)

Sets custom environment options for calling Git

Details

at line 46
static GitRepo create_new($repo_path, $source = null, $remote_source = false, $reference = null)

Create a new git repository

Accepts a creation path, and, optionally, a source path

Parameters

$repo_path
$source
$remote_source
$reference

Return Value

GitRepo

at line 80
void __construct($repo_path = null, $create_new = false, $_init = true)

Constructor

Accepts a repository path

Parameters

$repo_path
$create_new
$_init

Return Value

void

at line 97
void set_repo_path(string $repo_path, bool $create_new = false, bool $_init = true)

Set the repository's path

Accepts the repository path

Parameters

string $repo_path repository path
bool $create_new create if not exists?
bool $_init initialize new Git repo if not exists?

Return Value

void

at line 148
string git_directory_path()

Get the path to the git repo directory (eg. the ".git" directory)

Return Value

string

at line 158
bool test_git()

Tests if git is installed

Return Value

bool

at line 185
protected string run_command(string $command)

Run a command in the git repository

Accepts a shell command to run

Parameters

string $command command to run

Return Value

string

at line 233
string run(string $command)

Run a git command in the git repository

Accepts a git command to run

Parameters

string $command command to run

Return Value

string

at line 246
string status(bool $html = false)

Runs a 'git status' call

Accept a convert to HTML bool

Parameters

bool $html return string with

Return Value

string

at line 263
string add(mixed $files = "*")

Runs a git add call

Accepts a list of files to add

Parameters

mixed $files files to add

Return Value

string

at line 280
string rm(mixed $files = "*", Boolean $cached = false)

Runs a git rm call

Accepts a list of files to remove

Parameters

mixed $files files to remove
Boolean $cached use the --cached flag?

Return Value

string

at line 298
string commit(string $message = "", boolean $commit_all = true)

Runs a git commit call

Accepts a commit message string

Parameters

string $message commit message
boolean $commit_all should all files be committed automatically (-a flag)

Return Value

string

at line 313
string clone_to(string $target)

Runs a git clone call to clone the current repository into a different directory

Accepts a target directory

Parameters

string $target target directory

Return Value

string

at line 327
string clone_from(string $source)

Runs a git clone call to clone a different repository into the current repository

Accepts a source directory

Parameters

string $source source directory

Return Value

string

at line 342
string clone_remote(string $source, string $reference)

Runs a git clone call to clone a remote repository into the current repository

Accepts a source url

Parameters

string $source source url
string $reference reference path

Return Value

string

at line 356
string clean(bool $dirs = false, bool $force = false)

Runs a git clean call

Accepts a remove directories flag

Parameters

bool $dirs delete directories?
bool $force force clean?

Return Value

string

at line 369
string create_branch(string $branch)

Runs a git branch call

Accepts a name for the branch

Parameters

string $branch branch name

Return Value

string

at line 382
string delete_branch($branch, $force = false)

Runs a git branch -[d|D] call

Accepts a name for the branch

Parameters

$branch
$force

Return Value

string

at line 393
array list_branches(bool $keep_asterisk = false)

Runs a git branch call

Parameters

bool $keep_asterisk keep asterisk mark on active branch

Return Value

array

at line 415
array list_remote_branches()

Lists remote branches (using git branch -r).

Also strips out the HEAD reference (e.g. "origin/HEAD -> origin/master").

Return Value

array

at line 433
string active_branch(bool $keep_asterisk = false)

Returns name of active branch

Parameters

bool $keep_asterisk keep asterisk mark on branch name

Return Value

string

at line 453
string checkout(string $branch)

Runs a git checkout call

Accepts a name for the branch

Parameters

string $branch branch name

Return Value

string

at line 467
string merge(string $branch)

Runs a git merge call

Accepts a name for the branch to be merged

Parameters

string $branch

Return Value

string

at line 478
string fetch()

Runs a git fetch on the current branch

Return Value

string

at line 491
string add_tag(string $tag, string $message = null)

Add a new tag on the current position

Accepts the name for the tag and the message

Parameters

string $tag
string $message

Return Value

string

at line 507
array list_tags(string $pattern = null)

List all the available repository tags.

Optionally, accept a shell wildcard pattern and return only tags matching it.

Parameters

string $pattern Shell wildcard pattern to match tags against.

Return Value

array Available repository tags.

at line 528
string push(string $remote, string $branch)

Push specific branch to a remote

Accepts the name of the remote and local branch

Parameters

string $remote
string $branch

Return Value

string

at line 541
string pull(string $remote, string $branch)

Pull specific branch from remote

Accepts the name of the remote and local branch

Parameters

string $remote
string $branch

Return Value

string

at line 551
string log(strgin $format = null)

List log entries.

Parameters

strgin $format

Return Value

string

at line 563
set_description(string $new)

Sets the project description.

Parameters

string $new

at line 573
string get_description()

Gets the project description.

Return Value

string

at line 584
setenv(string $key, string $value)

Sets custom environment options for calling Git

Parameters

string $key key
string $value value