-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Description
From what I can tell, shallow clones don't seem to work with local clones. Am I missing some option? I'm guessing they only work with the smart transport. I would expect it to work like the git CLI, which can support shallow clones when using file:// URLs.
git clone --depth=1 file:///path/to/test
Reproduction steps
#include <assert.h>
#include <git2/repository.h>
#include <git2/errors.h>
#include <git2/global.h>
#include <git2/signature.h>
#include <git2/index.h>
#include <git2/commit.h>
#include <git2/clone.h>
#include <git2/diff.h>
#include <stdio.h>
#include <unistd.h>
int main() {
assert(git_libgit2_init() == 1);
git_repository *repo;
assert(git_repository_init(&repo, "repo", 0) == 0);
FILE *fp;
fp = fopen("repo/file", "w");
fputs("this is a test\n", fp);
fclose(fp);
git_index *index;
assert(git_repository_index(&index, repo) == 0);
assert(git_index_add_bypath(index, "file") == 0);
assert(git_index_write(index) == 0);
git_oid tree_id;
git_tree *tree;
assert(git_index_write_tree(&tree_id, index) == 0);
assert(git_tree_lookup(&tree, repo, &tree_id) == 0);
git_signature *sig;
assert(git_signature_default(&sig, repo) == 0);
git_oid first_commit_id;
assert(git_commit_create_v(&first_commit_id, repo, "HEAD", sig, sig, NULL, "first", tree, 0) == 0);
truncate("repo/file", 0);
assert(git_repository_index(&index, repo) == 0);
assert(git_index_add_bypath(index, "file") == 0);
assert(git_index_write(index) == 0);
assert(git_tree_lookup(&tree, repo, &tree_id) == 0);
git_oid second_commit_id;
assert(git_commit_create_v(&second_commit_id, repo, "HEAD", sig, sig, NULL, "second", tree, 1, first_commit_id) == 0);
git_repository *repo2;
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
clone_opts.fetch_opts.depth = 1;
// It doesn't seem to matter how `local` is set.
clone_opts.local = GIT_CLONE_LOCAL_NO_LINKS;
assert(git_clone(&repo2, "repo", "repo2", &clone_opts) == 0);
assert(git_repository_is_shallow(repo2) == 1);
return 0;
}Expected behavior
Local repos can be shallow cloned.
Actual behavior
It seems to ignore the depth parameter.
Version of libgit2 (release number or SHA1)
Operating system(s) tested
macOS
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels