technodelight/php-git

一个小型库,通过shell执行git命令

1.0.6 2020-01-06 13:32 UTC

This package is auto-updated.

Last update: 2024-09-07 00:02:27 UTC


README

围绕 git shell 的小型PHP包装库。

安装

通过composer。

composer require technodelight/php-git

依赖关系

此工具通过当前活动的shell执行 git。还使用了依赖于 sedheadgrep 的方法。

用法

<?php

$git = new Technodelight\GitShell\Api(
    new Technodelight\ShellExec\Exec('/usr/bin/env git')
);

// read git log entries
foreach ($git->log('develop', 'head') as $logEntry) {
    // $logEntry is an instance of Technodelight\GitShell\LogEntry here
}

// create a branch
$git->createBranch('my-precious-branch'); // return is void, but will throw exception on error

// switch to a branch
$git->switchBranch('develop');

// list remotes, optionally verbose mode
$git->remotes(); // runs git remote, returns 'origin' for example
$git->remotes(true); // runs git remote -v, returns a Technodelight\GitShell\Remote instance

// show branches, with optional filter, optionally with remotes
$git->branches();
$git->branches('feature/'); // this uses grep command in the background
$git->branches('', true); // each call will return a Technodelight\GitShell\Branch instance with remote

// retrieve the current branch
$git->currentBranch(); // instance of Technodelight\GitShell\Branch will be returned

// find the top level directory for current directory
$git->topLevelDirectory(); // returns false if not in a git dir, a path (string) otherwise

// show git diff
$git->diff(); // Technodelight\GitShell\DiffEntry object for current changes
$git->diff('develop'); // changes since last commit on develop

许可协议

MIT许可协议(MIT)

版权所有(c)2018 Zsolt Gál

特此授予任何获得此软件及其相关文档副本(以下简称“软件”)的人免费使用该软件的权利,不受限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许获得软件的人为此目的进行操作,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任承担责任,无论这些责任是根据合同、侵权或其他方式产生的,也不论这些责任是否与软件或其使用或其他方式有关。