该包已废弃,不再维护。未建议替代包。

通过PHP访问Git SCM

v0.10.0 2013-02-17 22:52 UTC

This package is not auto-updated.

Last update: 2020-01-24 14:52:23 UTC


README

Build Status

Gihp是一组用于纯PHP操作git仓库的类。不执行任何一行shell代码。

最近进行了完整历史的重写 https://gist.github.com/vierbergenlars/5191906

安装

vierbergenlars/gihp添加到您的composer.json文件中,或者运行composer.phar require vierbergenlars/gihp

{
    "require": {
        "vierbergenlars/gihp": "*"
    }
}

API文档

只有最新版本的API文档在线可用。早期版本可以使用ApiGen从源代码生成。

基本使用

打开仓库并获取基本信息非常简单。

<?php

use gihp\Repository;
use gihp\IO\File;

$io = new File('.');
$repo = new Repository($io); // Load the repository that lives in the working directory

$branches = $repo->getBranches(); // Loads all branches in the repository

echo "Branches in this repo: \n";
foreach($branches as $name=>$branch) {
    // Branches have their name as key, and a gihp\Branch object as value.
    echo $name."\n";
}


$tags = $repo->getTags(); // Loads all tags in the repository
echo "Tags in this repo: \n";

foreach($tags as $name=>$tag) {
    echo $name."\n";
}

但如果你想了解更多关于标签的信息呢?

<?php

// ...

$tag = $repo->getTag('v0.1.0'); // Load the tag "v0.1.0", returns gihp\Tag

echo "About the 0.1.0 version: \n";

$tag->getName(); //returns "v0.1.0", obviously.

// Gihp automatically determines the type of the tag.
// When it is an annotated tag, functions are called on that annotated tag.
// When it's a normal tag, functions are called on the commit it refers to.

echo 'Message: '.$tag->getMessage()."\n"; // Gets the message associated with the tag.
echo 'Created by: '.$tag->getAuthor().' on '.$tag->getDate()."\n"; // Gets the person associated with the tag.
echo 'Commit '.$tag->getCommit()->getSHA1()."\n"; // But this will surely always fetch the commit object to act upon.

与分支进行操作也同样非常完美。

<?php

// ...

$branch = $repo->getBranch('master'); // Load the master branch, returns gihp\Branch

echo "About the master branch: \n";

$branch->getName(); // "master"

echo 'Last commit by:'.$branch->getHeadCommit()->getAuthor()."\n";

$tree = $branch->getTree(); // A gihp\Tree

echo 'Contents of readme.md:'."\n".$tree->getFile('readme.md');