如何使用 libgit2 正确克隆 Git-LFS 存储库?

问题描述 投票:0回答:1

初始问题:

我使用 libgit2 的克隆不检查克隆存储库中的 LFS 跟踪文件。尽管 .gitattributes 文件在那里并且安装了 git-lfs。

如何让 libgit2 正确检出那些 LFS 跟踪的文件? 提前致谢!

我正在克隆存储库如下:


#include <git2.h>

...

git_repository *cloned_repository = nullptr;
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
clone_opts.checkout_branch = "master";
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;

// Set up options
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
clone_opts.checkout_opts = checkout_opts;

// Do the clone
GIT_CHECK_ERROR(git_clone(&cloned_repository, url.c_str(), path.string().c_str(), &clone_opts));

git_repository_free(cloned_repository);

更新:

根据lrm29的回答,我必须定义自己的过滤器。 关于这个SO答案我想我有事情要做:

// Set-up LFS filter
git_filter *lfs_process = new git_filter{
    GIT_FILTER_VERSION,
    "git-lfs filter-process",
    NULL,
    git_filter_free
};
git_filter *lfs_smudge = new git_filter{
    GIT_FILTER_VERSION,
    "git-lfs smudge -- %f",
    NULL,
    git_filter_free
};
git_filter *lfs_clean = new git_filter{
    GIT_FILTER_VERSION,
    "git-lfs clean -- %f",
    NULL,
    git_filter_free
};

我想之后我必须将这些过滤器添加到过滤器列表并定义模式。但是我有点困惑,因为我必须在过滤器列表而不是过滤器上设置过滤器模式 (GIT_FILTER_SMUDGE/GIT_FILTER_CLEAN)。然后我每个列表只有一个过滤器吗?为什么模式没有直接在过滤器上设置,或者我这里有问题。过程过滤器呢? 不幸的是,libgit2 的 API 文档信息量不多,比源代码还少。

我真的很感激在这方面的一些精心帮助。 :) 提前致谢。

git-lfs libgit2
1个回答
0
投票

Git LFS 使用 smudge/clean 过滤器(和钩子)。您需要通过注册自己的过滤器来运行涂抹/清洁过滤器:

https://libgit2.org/libgit2/#HEAD/type/git_filter

© www.soinside.com 2019 - 2024. All rights reserved.