Download the PHP package leapt/git-wrapper without Composer
On this page you can find all versions of the php package leapt/git-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leapt/git-wrapper
More information about leapt/git-wrapper
Files in leapt/git-wrapper
Package git-wrapper
Short Description An object oriented wrapper to run any Git command
License MIT
Homepage https://github.com/leapt/git-wrapper
Informations about the package git-wrapper
Leapt Git Wrapper
Allows to manage a Git repository with PHP. Provides an object-oriented wrapper to run any Git command.
Requirements
- PHP >= 8.2
- Git >= 1.5
Instantiate a Repository
It does NOT create a Git repo, but a PHP object to manipulate an existing Git repo.
Create a Git repository
If the Git repository does not exist yet on file system, Repository
can create it for you.
It runs git init
and returns a Repository
object.
Run git commands
git
commands can be run with the same syntax as in the CLI. Some examples:
There are no limitations, you can run any git commands.
The git()
method returns the output string:
The git()
method throws a GitRuntimeException
if the command is invalid:
Get branches information
Some shortcut methods are provided to deal with branches in a convenient way.
Get the branches list
Get the current branch
Know if the repo has a given branch
Get tags information
Get the tags list:
Get commits information
You can get an array of the last commits on the current branch.
Internally, this method runs git log
with formatted output. The return value should look like:
The first commit is the most recent one.
You can also retrieve the last commit by calling $repository->getLastCommit()
.
Debug mode
Repository
constructor's second parameter lets you enable debug mode.
When debug mode is on, commands and their output are displayed.
Configure
Repository
can be configured by passing an array of options to the constructor's third parameter.
Change git executable path
You may need to provide the path to the git executable.
On most Unix system, it's /usr/bin/git
. On Windows, it may be C:\Program Files\Git\bin
.
Change the command class
By default, the Repository
class will use the Command
class to implement Git commands.
By replacing this option, you can use your own command implementation
(which must implement the Leapt\GitWrapper\CommandInterface
):
Contributing
Feel free to contribute, like sending pull requests to add features/tests or creating issues :)
Note there are a few helpers to maintain code quality, that you can run using these commands:
PHPStan
PHP CS Fixer
PHPUnit
Note: tests rely on the default branch being main
. This can be updated using the following command:
History
This package is a maintained fork of the ornicar/php-git-repo package.