在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cpliakas/git-wrapper开源软件地址:https://github.com/cpliakas/git-wrapper开源编程语言:PHP 99.9%开源软件介绍:PHP Wrapper around GITGit Wrapper provides a readable API that abstracts challenges of executing Git commands from within a PHP process for you.
Installcomposer require cpliakas/git-wrapper Usageuse GitWrapper\GitWrapper;
// Initialize the library. If the path to the Git binary is not passed as
// the first argument when instantiating GitWrapper, it is auto-discovered.
require_once __DIR__ . '/vendor/autoload.php';
$gitWrapper = new GitWrapper();
// Optionally specify a private key other than one of the defaults
$gitWrapper->setPrivateKey('/path/to/private/key');
// Clone a repo into `/path/to/working/copy`, get a working copy object
$git = $gitWrapper->cloneRepository('git://github.com/cpliakas/git-wrapper.git', '/path/to/working/copy');
// Create a file in the working copy
touch('/path/to/working/copy/text.txt');
// Add it, commit it, and push the change
$git->add('test.txt');
$git->commit('Added the test.txt file as per the examples.');
$git->push();
// Render the output for operation
echo $git->push();
// Stream output of subsequent Git commands in real time to STDOUT and STDERR.
$gitWrapper->streamOutput();
// Execute an arbitrary git command.
// The following is synonymous with `git config -l`
$gitWrapper->git('config -l'); All command methods adhere to the following paradigm: $git->command($arg1, $arg2, ..., $options); Replace $options = [
'verbose' => true, // Passes the "--verbose" flag.
't' => 'my-branch', // Passes the "-t my-branch" option.
]; LoggingUse the logger listener with PSR-3 compatible loggers such as Monolog to log commands that are executed. <?php
use GitWrapper\EventSubscriber\GitLoggerEventSubscriber;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Log to a file named "git.log"
$logger = new Logger('git');
$logger->pushHandler(new StreamHandler('git.log', Logger::DEBUG));
// Instantiate the subscriber, add the logger to it, and register it.
$gitWrapper->addLoggerEventSubscriber(new GitLoggerEventSubscriber($logger));
$git = $gitWrapper->cloneRepository('git://github.com/cpliakas/git-wrapper.git', '/path/to/working/copy');
// The "git.log" file now has info about the command that was executed above. GotchasThere 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. Missing HOME Environment VariableSometimes the $gitWrapper->setEnvVar('HOME', '/path/to/a/private/writable/dir'); It is important that the storage is persistent as the Missing Identity And ConfigurationsMany repositories require that a name and email address are specified. This data is set by running // Set configuration options globally.
$gitWrapper->git('config --global user.name "User name"');
$gitWrapper->git('config --global user.email [email protected]');
// Set configuration options per repository.
$git->config('user.name', 'User name');
$git->config('user.email', '[email protected]'); Commits To Repositories With No ChangesRunning if ($git->hasChanges()) {
$git->commit('Committed the changes.');
} Permissions Of The GIT_SSH Wrapper ScriptOn checkout, the bin/git-ssh-wrapper.sh script should be executable. If it is not, git commands will fail if a non-default private key is specified. $ chmod +x ./bin/git-ssh-wrapper.sh TimeoutThere is a default timeout of 60 seconds. This might cause "issues" when you use the clone feature of bigger projects or with slow internet. $this->gitWrapper = new GitWrapper();
$this->gitWrapper->setTimeout(120); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论