PHP Class GitWrapper\GitWorkingCopy

All commands executed via an instance of this class act on the working copy that is set through the constructor.
Datei anzeigen Open project: cpliakas/git-wrapper Class Usage Examples

Protected Properties

Property Type Description
$cloned If the variable is null, the a rudimentary check will be performed to see if the directory looks like it is a working copy.
$directory string Path to the directory containing the working copy.
$output string The output captured by the last run Git commnd(s).
$wrapper GitWrapper\GitWrapper The GitWrapper object that likely instantiated this class.

Public Methods

Method Description
__call ( $method, $args ) Hackish, allows us to use "clone" as a method name.
__construct ( gitwrapper\GitWrapper $wrapper, string $directory ) Constructs a GitWorkingCopy object.
__toString ( ) : string Gets the output captured by the last run Git commnd(s).
add ( string $filepattern, array $options = [] ) : GitWorkingCopy Executes a git add command.
addRemote ( string $name, string $url, array $options = [] ) : GitWorkingCopy Adds a remote to the repository.
apply ( ) : GitWorkingCopy Executes a git apply command.
archive ( ) : GitWorkingCopy Executes a git archive command.
bisect ( string $sub_command ) : GitWorkingCopy Executes a git bisect command.
branch ( ) : GitWorkingCopy Executes a git branch command.
checkout ( ) : GitWorkingCopy Executes a git checkout command.
checkoutNewBranch ( string $branch, array $options = [] ) Create a new branch and check it out.
clean ( ) : GitWorkingCopy Executes a git clean command.
clearOutput ( ) : GitWorkingCopy Clears the stored output captured by the last run Git command(s).
cloneRepository ( string $repository, array $options = [] ) : GitWorkingCopy Executes a git clone command.
commit ( ) : GitWorkingCopy Executes a git commit command.
config ( ) : GitWorkingCopy Executes a git config command.
diff ( ) : GitWorkingCopy Executes a git diff command.
fetch ( ) : GitWorkingCopy Executes a git fetch command.
fetchAll ( array $options = [] ) Fetches all remotes.
getBranches ( ) : gitwrapper\GitBranches Returns a GitBranches object containing information on the repository's branches.
getDirectory ( ) : string Gets the path to the directory containing the working copy.
getOutput ( ) : string Gets the output captured by the last run Git commnd(s).
getRemote ( string $name ) : array Returns the given remote.
getRemoteUrl ( string $remote, string $operation = 'fetch' ) : string Returns the fetch or push URL of a given remote.
getRemotes ( ) : array Returns all existing remotes.
getStatus ( ) : string Returns the output of a git status -s command.
getWrapper ( ) : GitWrapper\GitWrapper Returns the GitWrapper object that likely instantiated this class.
grep ( ) : GitWorkingCopy Executes a git grep command.
hasChanges ( ) : boolean Returns true if there are changes to commit.
hasRemote ( string $name ) : boolean Checks if the given remote exists.
init ( array $options = [] ) : GitWorkingCopy Executes a git init command.
isAhead ( ) : boolean Returns whether HEAD is ahead of its remote tracking branch.
isBehind ( ) : boolean Returns whether HEAD is behind its remote tracking branch.
isCloned ( ) : boolean Checks whether a repository has already been cloned to this directory.
isTracking ( ) : boolean Returns whether HEAD has a remote tracking branch.
isUpToDate ( ) : boolean Returns whether HEAD is up-to-date with its remote tracking branch.
log ( ) : GitWorkingCopy Executes a git log command.
merge ( ) : GitWorkingCopy Executes a git merge command.
mv ( string $source, string $destination, array $options = [] ) : GitWorkingCopy Executes a git mv command.
needsMerge ( ) : boolean Returns whether HEAD needs to be merged with its remote tracking branch.
pull ( ) : GitWorkingCopy Executes a git pull command.
push ( ) : GitWorkingCopy Executes a git push command.
pushTag ( string $tag, string $repository = 'origin', array $options = [] ) Helper method that pushes a tag to a repository.
pushTags ( string $repository = 'origin', array $options = [] ) Helper method that pushes all tags to a repository.
rebase ( ) : GitWorkingCopy Executes a git rebase command.
remote ( ) : GitWorkingCopy Executes a git remote command.
removeRemote ( string $name ) : GitWorkingCopy Removes the given remote.
reset ( ) : GitWorkingCopy Executes a git reset command.
rm ( string $filepattern, array $options = [] ) : GitWorkingCopy Executes a git rm command.
run ( array $args, boolean $setDirectory = true ) : GitWorkingCopy Runs a Git command and captures the output.
setCloned ( boolean $cloned ) : GitWorkingCopy Manually sets the cloned flag.
show ( string $object, array $options = [] ) : GitWorkingCopy Executes a git show command.
status ( ) : GitWorkingCopy Executes a git status command.
tag ( ) : GitWorkingCopy Executes a git tag command.

Method Details

__call() public method

$throws \BadMethodCallException
public __call ( $method, $args )

__construct() public method

Constructs a GitWorkingCopy object.
public __construct ( gitwrapper\GitWrapper $wrapper, string $directory )
$wrapper gitwrapper\GitWrapper The GitWrapper object that likely instantiated this class.
$directory string Path to the directory containing the working copy.

__toString() public method

Gets the output captured by the last run Git commnd(s).
See also: GitWorkingCopy::getOutput()
public __toString ( ) : string
return string

add() public method

Add file contents to the index.
public add ( string $filepattern, array $options = [] ) : GitWorkingCopy
$filepattern string Files to add content from. Fileglobs (e.g. *.c) can be given to add all matching files. Also a leading directory name (e.g. dir to add dir/file1 and dir/file2) can be given to add all files in the directory, recursively.
$options array An optional array of command line options.
return GitWorkingCopy

addRemote() public method

Adds a remote to the repository.
public addRemote ( string $name, string $url, array $options = [] ) : GitWorkingCopy
$name string The name of the remote to add.
$url string The URL of the remote to add.
$options array An associative array of options, with the following keys: - -f: Boolean, set to true to run git fetch immediately after the remote is set up. Defaults to false. - --tags: Boolean. By default only the tags from the fetched branches are imported when git fetch is run. Set this to true to import every tag from the remote repository. Defaults to false. - --no-tags: Boolean, when set to true, git fetch does not import tags from the remote repository. Defaults to false. - -t: Optional array of branch names to track. If left empty, all branches will be tracked. - -m: Optional name of the master branch to track. This will set up a symbolic ref 'refs/remotes//HEAD which points at the specified master branch on the remote. When omitted, no symbolic ref will be created.
return GitWorkingCopy

apply() public method

Apply a patch to files and/or to the index
public apply ( ) : GitWorkingCopy
return GitWorkingCopy

archive() public method

Create an archive of files from a named tree
public archive ( ) : GitWorkingCopy
return GitWorkingCopy

bisect() public method

Find by binary search the change that introduced a bug.
public bisect ( string $sub_command ) : GitWorkingCopy
$sub_command string The subcommand passed to `git bisect`.
return GitWorkingCopy

branch() public method

List, create, or delete branches.
public branch ( ) : GitWorkingCopy
return GitWorkingCopy

checkout() public method

Checkout a branch or paths to the working tree.
public checkout ( ) : GitWorkingCopy
return GitWorkingCopy

checkoutNewBranch() public method

This is synonymous with git checkout -b.
See also: GitWorkingCopy::checkout()
public checkoutNewBranch ( string $branch, array $options = [] )
$branch string The new branch being created.
$options array

clean() public method

Remove untracked files from the working tree
public clean ( ) : GitWorkingCopy
return GitWorkingCopy

clearOutput() public method

Clears the stored output captured by the last run Git command(s).
public clearOutput ( ) : GitWorkingCopy
return GitWorkingCopy

cloneRepository() public method

Clone a repository into a new directory. Use GitWorkingCopy::clone() instead for more readable code.
public cloneRepository ( string $repository, array $options = [] ) : GitWorkingCopy
$repository string The Git URL of the repository being cloned.
$options array (optional) An associative array of command line options.
return GitWorkingCopy

commit() public method

Record changes to the repository. If only one argument is passed, it is assumed to be the commit message. Therefore $git->commit('Message'); yields a git commit -am "Message" command.
public commit ( ) : GitWorkingCopy
return GitWorkingCopy

config() public method

Get and set repository options.
public config ( ) : GitWorkingCopy
return GitWorkingCopy

diff() public method

Show changes between commits, commit and working tree, etc.
public diff ( ) : GitWorkingCopy
return GitWorkingCopy

fetch() public method

Download objects and refs from another repository.
public fetch ( ) : GitWorkingCopy
return GitWorkingCopy

fetchAll() public method

This is synonymous with git fetch --all.
See also: GitWorkingCopy::fetch()
public fetchAll ( array $options = [] )
$options array (optional) An associative array of command line options.

getBranches() public method

Returns a GitBranches object containing information on the repository's branches.
public getBranches ( ) : gitwrapper\GitBranches
return gitwrapper\GitBranches

getDirectory() public method

Gets the path to the directory containing the working copy.
public getDirectory ( ) : string
return string

getOutput() public method

Gets the output captured by the last run Git commnd(s).
public getOutput ( ) : string
return string

getRemote() public method

Returns the given remote.
public getRemote ( string $name ) : array
$name string The name of the remote.
return array An associative array with the following keys: - fetch: the fetch URL. - push: the push URL.

getRemoteUrl() public method

Returns the fetch or push URL of a given remote.
public getRemoteUrl ( string $remote, string $operation = 'fetch' ) : string
$remote string The name of the remote for which to return the fetch or push URL.
$operation string The operation for which to return the remote. Can be either 'fetch' or 'push'. Defaults to 'fetch'.
return string The URL.

getRemotes() public method

Returns all existing remotes.
public getRemotes ( ) : array
return array An associative array, keyed by remote name, containing an associative array with the following keys: - fetch: the fetch URL. - push: the push URL.

getStatus() public method

Returns the output of a git status -s command.
public getStatus ( ) : string
return string

getWrapper() public method

Returns the GitWrapper object that likely instantiated this class.
public getWrapper ( ) : GitWrapper\GitWrapper
return GitWrapper\GitWrapper

grep() public method

Print lines matching a pattern.
public grep ( ) : GitWorkingCopy
return GitWorkingCopy

hasChanges() public method

Returns true if there are changes to commit.
public hasChanges ( ) : boolean
return boolean

hasRemote() public method

Checks if the given remote exists.
public hasRemote ( string $name ) : boolean
$name string The name of the remote to check.
return boolean

init() public method

Create an empty git repository or reinitialize an existing one.
public init ( array $options = [] ) : GitWorkingCopy
$options array (optional) An associative array of command line options.
return GitWorkingCopy

isAhead() public method

If this returns true it means that commits are present locally which have not yet been pushed to the remote.
public isAhead ( ) : boolean
return boolean

isBehind() public method

If this returns true it means that a pull is needed to bring the branch up-to-date with the remote.
public isBehind ( ) : boolean
return boolean

isCloned() public method

If the flag is not set, test if it looks like we're at a git directory.
public isCloned ( ) : boolean
return boolean

isTracking() public method

Returns whether HEAD has a remote tracking branch.
public isTracking ( ) : boolean
return boolean

isUpToDate() public method

Returns whether HEAD is up-to-date with its remote tracking branch.
public isUpToDate ( ) : boolean
return boolean

log() public method

Show commit logs.
public log ( ) : GitWorkingCopy
return GitWorkingCopy

merge() public method

Join two or more development histories together.
public merge ( ) : GitWorkingCopy
return GitWorkingCopy

mv() public method

Move or rename a file, a directory, or a symlink.
public mv ( string $source, string $destination, array $options = [] ) : GitWorkingCopy
$source string The file / directory being moved.
$destination string The target file / directory that the source is being move to.
$options array (optional) An associative array of command line options.
return GitWorkingCopy

needsMerge() public method

If this returns true it means that HEAD has diverged from its remote tracking branch; new commits are present locally as well as on the remote.
public needsMerge ( ) : boolean
return boolean true if HEAD needs to be merged with the remote, false otherwise.

pull() public method

Fetch from and merge with another repository or a local branch.
public pull ( ) : GitWorkingCopy
return GitWorkingCopy

push() public method

Update remote refs along with associated objects.
public push ( ) : GitWorkingCopy
return GitWorkingCopy

pushTag() public method

This is synonymous with git push origin tag v1.2.3.
See also: GitWorkingCopy::push()
public pushTag ( string $tag, string $repository = 'origin', array $options = [] )
$tag string The tag being pushed.
$repository string The destination of the push operation, which is either a URL or name of the remote. Defaults to "origin".
$options array (optional) An associative array of command line options.

pushTags() public method

This is synonymous with git push --tags origin.
See also: GitWorkingCopy::push()
public pushTags ( string $repository = 'origin', array $options = [] )
$repository string The destination of the push operation, which is either a URL or name of the remote. Defaults to "origin".
$options array (optional) An associative array of command line options.

rebase() public method

Forward-port local commits to the updated upstream head.
public rebase ( ) : GitWorkingCopy
return GitWorkingCopy

remote() public method

Manage the set of repositories ("remotes") whose branches you track.
public remote ( ) : GitWorkingCopy
return GitWorkingCopy

removeRemote() public method

Removes the given remote.
public removeRemote ( string $name ) : GitWorkingCopy
$name string The name of the remote to remove.
return GitWorkingCopy

reset() public method

Reset current HEAD to the specified state.
public reset ( ) : GitWorkingCopy
return GitWorkingCopy

rm() public method

Remove files from the working tree and from the index.
public rm ( string $filepattern, array $options = [] ) : GitWorkingCopy
$filepattern string Files to remove from version control. Fileglobs (e.g. *.c) can be given to add all matching files. Also a leading directory name (e.g. dir to add dir/file1 and dir/file2) can be given to add all files in the directory, recursively.
$options array (optional) An associative array of command line options.
return GitWorkingCopy

run() public method

Runs a Git command and captures the output.
See also: GitWrapper::run()
public run ( array $args, boolean $setDirectory = true ) : GitWorkingCopy
$args array The arguments passed to the command method.
$setDirectory boolean Set the working directory, defaults to true.
return GitWorkingCopy

setCloned() public method

Manually sets the cloned flag.
public setCloned ( boolean $cloned ) : GitWorkingCopy
$cloned boolean Whether the repository is cloned into the directory or not.
return GitWorkingCopy

show() public method

Show various types of objects.
public show ( string $object, array $options = [] ) : GitWorkingCopy
$object string The names of objects to show. For a more complete list of ways to spell object names, see "SPECIFYING REVISIONS" section in gitrevisions(7).
$options array (optional) An associative array of command line options.
return GitWorkingCopy

status() public method

Show the working tree status.
public status ( ) : GitWorkingCopy
return GitWorkingCopy

tag() public method

Create, list, delete or verify a tag object signed with GPG.
public tag ( ) : GitWorkingCopy
return GitWorkingCopy

Property Details

$cloned protected_oe property

If the variable is null, the a rudimentary check will be performed to see if the directory looks like it is a working copy.
protected $cloned

$directory protected_oe property

Path to the directory containing the working copy.
protected string $directory
return string

$output protected_oe property

The output captured by the last run Git commnd(s).
protected string $output
return string

$wrapper protected_oe property

The GitWrapper object that likely instantiated this class.
protected GitWrapper,GitWrapper $wrapper
return GitWrapper\GitWrapper