2011-03-14 30 views
5

我一直在嘗試使用git-p4 python腳本將git p4庫路徑導入git。 配置我的環境之後(GIT 1.7.1,Python 2.7版,在Windwos XP,P4 ENV變量),我試圖運行 git的-P4腳本,geetting以下ouptut:無法使用git-p4在windows上導入

F:\gitp4>c:\Python27\python.exe git-p4.py clone --destination=master //depot/quake/main/[email protected] 
Reading pipe: git config git-p4.syncFromOrigin 
Importing from //depot/quake/main/[email protected] into master 
Initialized empty Git repository in F:/gitp4/master/.git/ 
Traceback (most recent call last): 
    File "git-p4.py", line 1926, in <module> 
    main() 
    File "git-p4.py", line 1921, in main 
    if not cmd.run(args): 
    File "git-p4.py", line 1798, in run 
    if not P4Sync.run(self, depotPaths): 
    File "git-p4.py", line 1501, in run 
    self.hasOrigin = originP4BranchesExist() 
    File "git-p4.py", line 439, in originP4BranchesExist 
    return gitBranchExists("origin") or gitBranchExists("origin/p4") or gitBranchExists("origin/p4/master") 
    File "git-p4.py", line 332, in gitBranchExists 
    stderr=subprocess.PIPE, stdout=subprocess.PIPE); 
    File "c:\Python27\lib\subprocess.py", line 672, in __init__ 
    errread, errwrite) 
    File "c:\Python27\lib\subprocess.py", line 882, in _execute_child 
    startupinfo) 
WindowsError: [Error 2] The system cannot find the file specified 

有誰知道這是怎麼回事這裏?如果我嘗試從命令行shell運行第332行的git命令(git rev-parse origin),則該命令將被正確執行。

謝謝。

更新:似乎腳本無法啓動其exec文件不在執行路徑中的任何進程。 我認爲這是一個初始化問題在Windows蟒蛇...

+0

似乎subprocess.Popen([「git」] ...)的用法忽略PATH變量。我有一個解決方法,即調用一個全路徑批處理文件,該文件調用git exec文件 – Tate 2011-03-17 13:53:26

+0

謝謝,這對我很有用。 – Kevin 2011-04-21 22:44:53

+0

你能否澄清你到底做了什麼,我無法得到它的工作:( – Restuta 2011-12-19 06:35:20

回答

3

針對Restuta的評論:

  1. 我創建一個批處理文件來調用「git.cmd」 EXEC文件上的自定義路徑。我的批處理文件的內容:
    @ 「C:\ Program Files文件\的Git \ CMD \ git.cmd」 %*

  2. 我已經修改了git-p4.py文件來調用批處理文件,而不是隻「混帳」。例如:
    例如。 (線2237)原始行:INIT_CMD = [ 「GIT中」, 「初始化」]
    替換:INIT_CMD = [ 「PATH_TO_BATCH_FILE \ git.bat」, 「初始化」]
    例如:
    INIT_CMD = [「F:\ gitp4 \ git.bat」, 「初始化」]

  3. 執行相同的文件上的所有混帳電話(subprocess.Popen調用)(我一共6個變動)

希望能幫助到你!