在Windows上无法使用git-p4导入

5 投票
1 回答
1670 浏览
提问于 2025-04-16 13:39

我一直在尝试用一个叫做 git-p4 的 Python 脚本把 p4 的仓库路径导入到 git 中。配置好我的环境后(包括 git 1.7.1、python 2.7、Windows XP 以及 p4 的环境变量),我运行了 git-p4 脚本,结果得到了以下输出:

F:\gitp4>c:\Python27\python.exe git-p4.py clone --destination=master //depot/quake/main/...@all
Reading pipe: git config git-p4.syncFromOrigin
Importing from //depot/quake/main/...@all 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

有没有人知道这是怎么回事?如果我在命令行中直接运行第332行提到的 git 命令(git rev-parse origin),这个命令是可以正常执行的。

谢谢。

更新:看起来这个脚本无法启动任何执行文件不在执行路径中的进程。我觉得这可能是 Windows 上 Python 的初始化问题...

1 个回答

3

针对Restuta的评论,我做了以下几点:

  1. 我创建了一个批处理文件,用来在自定义路径下调用“git.cmd”这个执行文件。我的批处理文件内容是:
    @"C:\Program Files\Git\cmd\git.cmd" %*

  2. 我修改了git-p4.py文件,让它调用这个批处理文件,而不是直接调用“git”。
    比如(第2237行)原来的代码是:init_cmd = [ "git", "init" ]
    我把它替换成:init_cmd = [ "PATH_TO_BATCH_FILE\git.bat", "init" ]
    例如:
    init_cmd = [ "f:\gitp4\git.bat", "init" ]

  3. 对文件中的所有git调用(subprocess.Popen调用)都做同样的修改(我总共做了6处更改)

希望这能帮到你!

撰写回答