微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 GitPython 进行浅克隆 过滤器规格可以作为列表传递

如何解决如何使用 GitPython 进行浅克隆 过滤器规格可以作为列表传递

我正在尝试使用 gitpython 对存储库进行浅层/部分克隆

这是 git CLI 命令:

$ git clone -v --filter=tree:0 --filter=blob:none --sparse git@gitlab.com:gitlab-org/gitlab-docs.git ./Projects/ 
cloning into './Projects'...
remote: Enumerating objects: 4145,done.
remote: Counting objects: 100% (71/71),done.
remote: Compressing objects: 100% (64/64),done.
remote: Total 4145 (delta 7),reused 64 (delta 7),pack-reused 4074
Receiving objects: 100% (4145/4145),1.30 MiB | 2.89 MiB/s,done.
Resolving deltas: 100% (424/424),done.
remote: Enumerating objects: 57,done.
remote: Counting objects: 100% (14/14),done.
remote: Compressing objects: 100% (14/14),done.
remote: Total 57 (delta 0),reused 5 (delta 0),pack-reused 43
Receiving objects: 100% (57/57),10.41 KiB | 5.20 MiB/s,done.
remote: Enumerating objects: 31,done.
remote: Counting objects: 100% (12/12),done.
remote: Compressing objects: 100% (12/12),done.
remote: Total 31 (delta 0),reused 3 (delta 0),pack-reused 19
Receiving objects: 100% (31/31),182.70 KiB | 2.31 MiB/s,done.
Updating files: 100% (31/31),done.

尝试使用 gitpython 包通过 python 运行相同的命令:

代码

from git import Repo


print('cloning ....')
repo = Repo.clone_from(
        'git@gitlab.com:gitlab-org/gitlab-docs.git','./Projects/',filter='{tree:0,blob:none}',sparse=True
        )   
print(repo)

输出

% python test.py 
cloning ....
Traceback (most recent call last):
  File "/partial_clone_fetch/test.py",line 5,in <module>
    repo = Repo.clone_from(
  File "/partial_clone_fetch/.env/lib/python3.9/site-packages/git/repo/base.py",line 1083,in clone_from
    return cls._clone(git,url,to_path,GitCmdobjectdb,progress,multi_options,**kwargs)
  File "/partial_clone_fetch/.env/lib/python3.9/site-packages/git/repo/base.py",line 1021,in _clone
    finalize_process(proc,stderr=stderr)
  File "/partial_clone_fetch/.env/lib/python3.9/site-packages/git/util.py",line 369,in finalize_process
    proc.wait(**kwargs)
  File "/partial_clone_fetch/.env/lib/python3.9/site-packages/git/cmd.py",line 450,in wait
    raise GitCommandError(remove_password_if_present(self.args),status,errstr)
git.exc.GitCommandError: Cmd('git') Failed due to: exit code(128)
  cmdline: git clone -v --filter={tree:0,blob:none} --sparse git@gitlab.com:gitlab-org/gitlab-docs.git ./Projects/
  stderr: 'fatal: invalid filter-spec '{tree:0,blob:none}'

不知道如何在 gitpython 中准确传递多个过滤器,并且没有足够的可用文档。

解决方法

过滤器规格可以作为列表传递。

以下是问题的解决方案:

ID
1
2
3
4
.
.
.
100

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。