2012-08-08 59 views
1

我試圖從PHP文件中讀取git pull,但好像配置沒有被使用。通過PHP文件通過git pull時不使用git config

git config --global user.namegit config --global user.email被設置,git pull從命令行工作。

現在,當我試圖執行這個腳本:

<?php 

header('Content-type: text/plain'); 
system('git pull 2>&1'); 
echo "\nCompleted!"; 

我得到以下輸出:

*請告訴我你是誰。

運行

混帳配置--global user.email 「[email protected]」 混帳配置 --global user.name 「你的名字」

設置您的帳戶的默認身份。省略--global僅在此存儲庫中設置 標識。

致命:空識別碼不允許

已完成!

這可能是因爲git config是用戶specfic而PHP是從另一個用戶運行?

回答

2

只需使用-c標誌上的git本身:

-c <name>=<value> 
Pass a configuration parameter to the command. The value given will override values from configuration files. The <name> is expected in the same format 
as listed by git config (subkeys separated by dots). 

因此,像:

git -c user.name=apache pull 

應該讓你那裏。添加你需要的任何參數。如果要指定一個特定的文件,然後可以添加相關的配置選項,用戶執行該腳本,或通過exporting a different HOME env variable first.

+0

謝謝。我正在使用'system('/ usr/bin/env -i HOME =/home/myself git pull 2> &1');''。 – EsTeGe 2012-08-08 13:32:05

0

即使您沒有登錄,您也希望您的網絡服務器能夠正常工作,不是嗎?這意味着它由另一個用戶比你運行(除非你另有指定)。除非通過CLI運行腳本,否則該腳本由apache,www-data或您配置的任何用戶運行。

0

我設法讓它工作,但它不是一個理想的解決方案。我需要找到一種方法來爲apache用戶設置git config一次,而不是每次。我在共享主機上,所以我不知道它是否可能。

<?php 

header('Content-type: text/plain'); 
system('git config user.name "Server"'); 
system('git config user.email "[email protected]"'); 
system('git pull 2>&1'); 
echo "\nCompleted!"; 
0

周圍破解這有點雜牌組裝電腦,但你還可以設置系統混帳配置:

git config --system user.name <user> 
git config --system user.email <user>@<domain> 

這有一個相當不幸的副作用,作爲服務器的所有用戶的默認配置,所以它確實不是很好。