1

--recursiveパラメータ ( 、 )を使用して git リポジトリのクローンを作成したいのです-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)

これが私のコードです:

#!/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、このコマンドは私のパラメーターを受け入れません。

4

1 に答える 1

3

試す:

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

最初の引数は、どこからクローンを作成するか (リモート リポジトリ) です。2 番目の引数は、クローンを保存する場所です。他のすべての引数はコマンドに渡されgit-cloneます。例えば--branch="branch"​​と--recursive. 省略形ではなく、長い引数名に固執する必要があります。再帰フラグが存在するかどうかに関係なく、その値は True または False のみになります。

于 2015-08-05T09:37:44.007 に答える