1

Initial question:

My clones with libgit2 don't checkout the LFS-tracked files in the cloned repo. Eventhough the .gitattributes file is there and git-lfs is installed.

How can I make libgit2 to checkout those LFS-tracked files properly? Thanks in advance!

I'm cloning repositories as follows:


#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);

Update:

According to lrm29's answer, I have to define my own filters. Regarding this SO answer I guess I have something to do like:

// 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
};

I guess afterwards I have to add those filters to a filter list and define the mode. But I'm a bit confused as I have to set the filter mode (GIT_FILTER_SMUDGE/GIT_FILTER_CLEAN) on the filter list and not the filter. Do I then only have a single filter per list? Why is the mode not set directly on the filter or am I getting here something wrong. What about the process filter? Unfortunately the API Documentation of libgit2 is not very informative, less than the source code.

I'd really appreciate some elaborate help on this. :) Thanks in advance.

hwiedPro
  • 11
  • 2

1 Answers1

0

Git LFS uses smudge/clean filters (and hooks). You'll need to run the smudge/clean filters by registering your own filters:

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

lrm29
  • 458
  • 4
  • 17
  • Thanks, for your response. Can you elaborate on how to do this? I'm not familiar with git's filters – hwiedPro May 08 '23 at 11:52