Download the PHP package craftpip/git-wrapper without Composer
On this page you can find all versions of the php package craftpip/git-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download craftpip/git-wrapper
More information about craftpip/git-wrapper
Files in craftpip/git-wrapper
Package git-wrapper
Short Description A PHP wrapper around the Git command line utility.
License MIT
Homepage https://github.com/craftpip/git-wrapper
Informations about the package git-wrapper
Overview
This library is a PHP wrapper around the Git command line tool.
Its purpose is to provide a readable API that abstracts some of the challenges of executing Git commands from within a PHP process. Specifically, this library builds upon the Symfony framework's Process component to execute the Git command in a way that works across platforms and uses the best-in-breed techniques available to PHP. This library also provides an SSH wrapper script and API method for developers to easily specify a private key other than one of the defaults by using the technique in this thread on StackOverflow. Finally, various commands are expected to be executed in the directory containing the working copy. Although this a fairly simple challenge to overcome, the library handles this transparently so the developer doesn't have to think about it.
Usage
All command methods adhere to the following paradigm:
Replace command
with the Git command being executed, e.g. checkout
, push
,
etc. The $arg*
parameters are a variable number of arguments as they would be
passed to the Git command line tool. $options
is an optional array of command
line options in the following format:
Logging
Use the logger listener with PSR-3 compatible loggers such as Monolog to log commands that are executed.
Installation
Git Wrapper can be installed with Composer by adding the library as a dependency to your composer.json file.
Please refer to Composer's documentation for installation and usage instructions.
Gotchas
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. The following is an incomplete list of challenges that are often encountered when executing Git from PHP.
Missing HOME Environment Variable
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.
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.
Missing Identity And Configurations
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.
Commits To Repositories With No Changes
Running git commit
on a repository with no changes returns no output but exits
with a status of 1. Therefore the library will throw a GitException
since it
correctly detected an error. It is advisable to check whether a working copy has
any changes prior to running the commit operation in order to prevent unwanted
exceptions.
Permissions Of The GIT_SSH Wrapper Script
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.
$> chmod 0755 ./bin/git-ssh-wrapper.sh
For Developers
Refer to PHP Project Starter's documentation for the Apache Ant targets supported by this project.