GitPython克隆存储库错误

时间:2015-08-05 09:18:57

标签: python git gitpython

我想使用参数(-b <branch>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) )克隆git存储库,但是我收到以下错误。

#!/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.clone

如果我将git.Repo.clone_from替换为Route::get('/post/{post}', ['middleware' => 'owner:post', 'as' => 'post', 'uses' => 'PostController@showPost']); 它的工作正常,但此命令不接受我的参数。

1 个答案:

答案 0 :(得分:2)

尝试:

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

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

相关问题