2011-08-17 64 views
8

我需要在純PHP中進行git簽出。 我已經使用HTTP和SASL嘗試了這個(http://www.phpclasses.org/package/5310-PHP-Retrieve-project-files-from-GIT-repositories.html),但我沒有真正的工作。 然後我看了一下GLIP(https://github.com/patrikf/glip),但似乎沒有任何這樣的功能。 基本上我需要在純PHP中籤出git倉庫

-replicate /克隆一個遠程的Git倉庫

- 「提取」主分支文件到指定的目錄

與PHP GIT的主要問題是,它只是沒有支持您在提交中可以做的所有可能的更改。只有新文件,不移動文件。它也無法提取文件。

/編輯: Git是沒有安裝,我也無法安裝混帳

+0

這是一個幾乎相同的問題。 [執行-git-pull-in-pure-php](http://stackoverflow.com/questions/6994773/performing-a-git-pull-in-pure-php) – Andy

回答

4

您可以

的Git Streamwrapper for PHP是一個PHP庫允許PHP代碼與應用程序內的一個或多個Git存儲庫進行交互。該庫包含一個Git存儲庫抽象,可用於以編程方式訪問Git存儲庫和一個可封裝到PHP流基礎結構中的流包裝器,以允許開發人員直接在Git存儲庫中的文件上使用文件和目錄訪問功能。該庫提供了訪問Git存儲庫上狀態信息的方法,例如日誌,當前存儲庫狀態或提交信息。

它需要將Git安裝在機器上,儘管如此,在撰寫本文時仍處於測試階段。

+2

對不起,我忘了提及它但 - git沒有安裝,我無法安裝它(共享webspace):( – dom0

+0

我有完全相同的難度,有人建議我使用FTPloy,對我來說不夠好,但也許值得去看看 – Tony

3

我已經開發了相當不錯的PHP庫來操縱git倉庫,你應該考慮一下:http://gitonomy.com/doc/gitlib/master/

是這樣的:

$repository = new Gitonomy\Git\Repository('/path/to/repository'); 
$master  = $repository->getReferences()->getBranch('master'); 

$author = $master->getCommit()->getAuthorName(); 

echo "Last modification on master made by ".$author; 
+0

不這也需要在系統上安裝'git'? – Potherca

+0

@ Alexandre Salume我曾經試過你的庫並且無法使它工作,這個想法集中在本地操作我的倉庫。使用git初始化wamp www文件夾是否可以使用你的庫來操作這個版本庫,而不是使用BitBucket或Github作爲源路徑? – Maximum86

-3
<?php 
    /** 
    * This function handles the pull/init/clone of a git repo 
    * 
    * @param $git_url 
    * Example of git clone url git://github.com/someuser/somerepo.git 
    * 
    * @return bool true 
    */ 
    public static function pullOrCloneRepo($git_url) { 
    if (!isset($git_url)) { 
     return false; 
    } 
    // validate contains git://github.com/ 
    if (strpos($git_url, 'git://github.com/') !== FALSE) { 
     // create a directory and change permissions 
     $uri = 'public://somedir'; // change this if not in drupal 
     //check the dir 
     $file_path = drupal_realpath($uri); // change this if not in drupal 
     if (isset($file_path)) { 
     $first_dir = getcwd(); 
     // change dir to the new path 
     $new_dir = chdir($file_path); 
     // Git init 
     $git_init = shell_exec('git init'); 
     // Git clone 
     $git_clone = shell_exec('git clone '. $git_url); 
     // Git pull 
     $git_pull = shell_exec('git pull'); 
     // change dir back 
     $change_dir_back = chdir($first_dir); 
     return true; 
     } 
    } 
    else { 
     return false; 
    } 
    } 
?> 
+0

如果你安裝了git,那麼去堅果 – taggartJ