1

我想使用参数(--recursive-b <branch>)克隆 git 存储库,但出现以下错误。

Traceback (most recent call last):
  File "./git-clone.py", line 15, in <module>
    r = git.Repo.clone(repo_dir, b=branch, recursive=git_url)
TypeError: unbound method clone() must be called with Repo instance as first argument (got str instance instead)

这是我的代码:

#!/usr/bin/env python

import git
import os
import shutil


git_url = "<url>..."
repo_dir = "/home_local/user/git-repository"
branch = "branch"

if os.path.exists(repo_dir):
    shutil.rmtree(repo_dir)

r = git.Repo.clone(repo_dir, b=branch, recursive=git_url)

如果我git.Repo.clonegit.Repo.clone_from它的工作正常替换,但这个命令不接受我的参数。

4

1 回答 1

3

尝试:

r = git.Repo.clone_from(git_url, repo_dir, branch=branch, recursive=True)

第一个参数是您从中克隆的位置(远程存储库)。第二个参数是您要存储克隆的位置。所有其他参数都传递给git-clone命令。例如--branch="branch"--recursive。您可能应该坚持使用长参数名称而不是缩写。由于递归标志存在或不存在,因此它的值只能是 True 或 False。

于 2015-08-05T09:37:44.007 回答