From cfc2ae68b4792f0c64152888869ef69d868079d7 Mon Sep 17 00:00:00 2001 From: yuangli Date: Wed, 27 Jul 2022 11:53:37 +0100 Subject: eliminate build warnings --- tests/libgit2/grafts/basic.c | 123 ++++++++++++++++++++++++++++++++++ tests/libgit2/grafts/parse.c | 149 +++++++++++++++++++++++++++++++++++++++++ tests/libgit2/grafts/shallow.c | 146 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 418 insertions(+) create mode 100644 tests/libgit2/grafts/basic.c create mode 100644 tests/libgit2/grafts/parse.c create mode 100644 tests/libgit2/grafts/shallow.c (limited to 'tests/libgit2') diff --git a/tests/libgit2/grafts/basic.c b/tests/libgit2/grafts/basic.c new file mode 100644 index 000000000..4be4a12bf --- /dev/null +++ b/tests/libgit2/grafts/basic.c @@ -0,0 +1,123 @@ +#include "clar_libgit2.h" + +#include "futils.h" +#include "grafts.h" + +static git_repository *g_repo; + +void test_grafts_basic__initialize(void) +{ + git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1); + g_repo = cl_git_sandbox_init("grafted.git"); +} + +void test_grafts_basic__cleanup(void) +{ + git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); + cl_git_sandbox_cleanup(); +} + +void test_grafts_basic__graft_add(void) +{ + git_array_oid_t parents = GIT_ARRAY_INIT; + git_oid oid_src, *oid1; + git_commit_graft *graft; + git_grafts *grafts; + + cl_git_pass(git_grafts_new(&grafts)); + + cl_assert(oid1 = git_array_alloc(parents)); + cl_git_pass(git_oid_fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9")); + git_oid_cpy(oid1, &oid_src); + + git_oid_fromstr(&oid_src, "f503807ffa920e407a600cfaee96b7152259acc7"); + cl_git_pass(git_grafts_add(grafts, &oid_src, parents)); + git_array_clear(parents); + + cl_assert_equal_i(1, git_grafts_size(grafts)); + cl_git_pass(git_grafts_get(&graft, grafts, &oid_src)); + cl_assert_equal_s("f503807ffa920e407a600cfaee96b7152259acc7", git_oid_tostr_s(&graft->oid)); + cl_assert_equal_i(1, git_array_size(graft->parents)); + cl_assert_equal_s("2f3053cbff8a4ca2f0666de364ddb734a28a31a9", git_oid_tostr_s(git_array_get(graft->parents, 0))); + + git_grafts_free(grafts); +} + +void test_grafts_basic__grafted_revwalk(void) +{ + git_revwalk *w; + git_oid oids[10]; + size_t i = 0; + git_commit *commit; + + cl_git_pass(git_revwalk_new(&w, g_repo)); + cl_git_pass(git_revwalk_push_ref(w, "refs/heads/branch")); + + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[0]), "8a00e91619098618be97c0d2ceabb05a2c58edd9"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[1]), "f503807ffa920e407a600cfaee96b7152259acc7"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[2]), "2f3053cbff8a4ca2f0666de364ddb734a28a31a9"); + + cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oids[i++], w)); + + cl_git_pass(git_commit_lookup(&commit, g_repo, &oids[0])); + + cl_assert_equal_i(1, git_commit_parentcount(commit)); + + git_commit_free(commit); + git_revwalk_free(w); +} + +void test_grafts_basic__grafted_objects(void) +{ + git_oid oid; + git_commit *commit; + + cl_git_pass(git_oid_fromstr(&oid, "f503807ffa920e407a600cfaee96b7152259acc7")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); + cl_assert_equal_i(1, git_commit_parentcount(commit)); + git_commit_free(commit); + + cl_git_pass(git_oid_fromstr(&oid, "0512adebd3782157f0d5c9b22b043f87b4aaff9e")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); + cl_assert_equal_i(1, git_commit_parentcount(commit)); + git_commit_free(commit); + + cl_git_pass(git_oid_fromstr(&oid, "66cc22a015f6ca75b34c82d28f78ba663876bade")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); + cl_assert_equal_i(4, git_commit_parentcount(commit)); + git_commit_free(commit); +} + +void test_grafts_basic__grafted_merge_revwalk(void) +{ + git_revwalk *w; + git_oid oids[10]; + size_t i = 0; + + cl_git_pass(git_revwalk_new(&w, g_repo)); + cl_git_pass(git_revwalk_push_ref(w, "refs/heads/bottom")); + + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "66cc22a015f6ca75b34c82d28f78ba663876bade"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "e414f42f4e6bc6934563a2349a8600f0ab68618e"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "8a00e91619098618be97c0d2ceabb05a2c58edd9"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "1c18e80a276611bb9b146590616bbc5aebdf2945"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "d7224d49d6d5aff6ade596ed74f4bcd4f77b29e2"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "0512adebd3782157f0d5c9b22b043f87b4aaff9e"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "f503807ffa920e407a600cfaee96b7152259acc7"); + cl_git_pass(git_revwalk_next(&oids[i++], w)); + cl_assert_equal_s(git_oid_tostr_s(&oids[i - 1]), "2f3053cbff8a4ca2f0666de364ddb734a28a31a9"); + + cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oids[i++], w)); + + git_revwalk_free(w); +} diff --git a/tests/libgit2/grafts/parse.c b/tests/libgit2/grafts/parse.c new file mode 100644 index 000000000..de110c901 --- /dev/null +++ b/tests/libgit2/grafts/parse.c @@ -0,0 +1,149 @@ +#include "clar_libgit2.h" + +#include "grafts.h" + +#define OID0 "c0368f9f9743e950e6cfe1f45a649f8a9dfcd97e" +#define OID1 "cfc50a0db87ce908fb8a8c5b8f7b4ab96eee8643" +#define OID2 "6914d97cd08b9edf5e855fca211c750fa82fd80a" +#define OID3 "516521937d0e9ce9d0d836149a0702671f326b4a" +#define OID4 "e2c29d67ef2f217650196f94c796f0532b8caad6" +#define OID5 "79bcb936596cb50353fe7be28b7444e66e4a2842" +#define OID6 "b9c54107d57c17dbcaf646c4d52f66eb9e69d23d" +#define OID7 "9f8a746e9ad7b58cc840016bc3944d5ad262acb5" +#define OID8 "392f4beef7d0d15b2bc5b1abe1a754eba0ec36da" + +#define OID_TRUNCATED "392f4beef7d0d15b2bc5b1abe1a754eba0ec36d" +#define OID_NONHEX "9f8a746e9ax7b58cc840016bc3944d5ad262acb5" + +static git_grafts *grafts; + +void test_grafts_parse__initialize(void) +{ + cl_git_pass(git_grafts_new(&grafts)); +} + +void test_grafts_parse__cleanup(void) +{ + git_grafts_free(grafts); + grafts = NULL; +} + +static void assert_parse_succeeds(git_grafts *grafts, const char *string, size_t n) +{ + cl_git_pass(git_grafts_parse(grafts, string, strlen(string))); + cl_assert_equal_i(git_grafts_size(grafts), n); +} + +static void assert_parse_fails(git_grafts *grafts, const char *string) +{ + cl_git_fail(git_grafts_parse(grafts, string, strlen(string))); +} + +static void assert_graft_contains(git_grafts *grafts, const char *graft, size_t n, ...) +{ + git_commit_graft *commit; + git_oid oid; + va_list ap; + size_t i = 0; + + cl_git_pass(git_oid_fromstr(&oid, graft)); + cl_git_pass(git_grafts_get(&commit, grafts, &oid)); + cl_assert_equal_oid(&commit->oid, &oid); + cl_assert_equal_i(commit->parents.size, n); + + va_start(ap, n); + while (i < n) { + cl_git_pass(git_oid_fromstr(&oid, va_arg(ap, const char *))); + cl_assert_equal_oid(&commit->parents.ptr[i], &oid); + i++; + } + va_end(ap); +} + +void test_grafts_parse__single_oid(void) +{ + assert_parse_succeeds(grafts, OID1, 1); + assert_graft_contains(grafts, OID1, 0); +} + +void test_grafts_parse__single_oid_with_newline(void) +{ + assert_parse_succeeds(grafts, OID1 "\n", 1); + assert_graft_contains(grafts, OID1, 0); +} + +void test_grafts_parse__multiple_oids(void) +{ + assert_parse_succeeds(grafts, OID1 "\n" OID2 "\n" OID3, 3); + assert_graft_contains(grafts, OID1, 0); + assert_graft_contains(grafts, OID2, 0); + assert_graft_contains(grafts, OID3, 0); +} + +void test_grafts_parse__same_oid(void) +{ + assert_parse_succeeds(grafts, OID1 "\n" OID1, 1); + assert_graft_contains(grafts, OID1, 0); +} + +void test_grafts_parse__oid_with_parent(void) +{ + assert_parse_succeeds(grafts, OID1 " " OID2, 1); + assert_graft_contains(grafts, OID1, 1, OID2); +} + +void test_grafts_parse__oid_with_parent_and_newline(void) +{ + assert_parse_succeeds(grafts, OID1 " " OID2 "\n", 1); + assert_graft_contains(grafts, OID1, 1, OID2); +} + +void test_grafts_parse__oid_with_multiple_parents(void) +{ + assert_parse_succeeds(grafts, OID1 " " OID2 " " OID3 " " OID4 " " OID5, 1); + assert_graft_contains(grafts, OID1, 4, OID2, OID3, OID4, OID5); +} + +void test_grafts_parse__multiple_oids_with_multiple_parents(void) +{ + assert_parse_succeeds(grafts, + OID1 " " OID2 " " OID3 " " OID4 " " OID5 "\n" + OID6 " " OID7 " " OID8 "\n" , 2); + assert_graft_contains(grafts, OID1, 4, OID2, OID3, OID4, OID5); + assert_graft_contains(grafts, OID6, 2, OID7, OID8); +} + +void test_grafts_parse__multiple_spaces_fails(void) +{ + assert_parse_fails(grafts, OID1 " " OID2); +} + +void test_grafts_parse__trailing_space_fails(void) +{ + assert_parse_fails(grafts, OID1 " " OID2 " "); +} + +void test_grafts_parse__invalid_character_inbetween_fails(void) +{ + assert_parse_fails(grafts, OID1 " x " OID2); +} + +void test_grafts_parse__truncated_oid_fails(void) +{ + assert_parse_fails(grafts, OID_TRUNCATED); +} + +void test_grafts_parse__truncated_parent_fails(void) +{ + assert_parse_fails(grafts, OID1 " " OID_TRUNCATED); +} + +void test_grafts_parse__invalid_oid_fails(void) +{ + assert_parse_fails(grafts, OID_NONHEX); +} + +void test_grafts_parse__invalid_parent_fails(void) +{ + assert_parse_fails(grafts, OID1 " " OID_NONHEX); +} diff --git a/tests/libgit2/grafts/shallow.c b/tests/libgit2/grafts/shallow.c new file mode 100644 index 000000000..a75b5a051 --- /dev/null +++ b/tests/libgit2/grafts/shallow.c @@ -0,0 +1,146 @@ +#include "clar_libgit2.h" + +#include "futils.h" +#include "grafts.h" +#include "repository.h" + +static git_repository *g_repo; +static git_oid g_shallow_oid; + +void test_grafts_shallow__set_feature_flag(void) +{ + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1)); +} + +void test_grafts_shallow__unset_feature_flag(void) +{ + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0)); +} + +void test_grafts_shallow__initialize(void) +{ + git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1); + cl_git_pass(git_oid_fromstr(&g_shallow_oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); +} + +void test_grafts_shallow__cleanup(void) +{ + git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); + cl_git_sandbox_cleanup(); +} + +void test_grafts_shallow__no_shallow_file(void) +{ + g_repo = cl_git_sandbox_init("testrepo.git"); + cl_assert_equal_i(0, git_repository_is_shallow(g_repo)); +} + +void test_grafts_shallow__empty_shallow_file(void) +{ + g_repo = cl_git_sandbox_init("testrepo.git"); + cl_git_mkfile("testrepo.git/shallow", ""); + cl_assert_equal_i(0, git_repository_is_shallow(g_repo)); +} + +void test_grafts_shallow__shallow_repo(void) +{ + g_repo = cl_git_sandbox_init("shallow.git"); + cl_assert_equal_i(1, git_repository_is_shallow(g_repo)); +} + +void test_grafts_shallow__clears_errors(void) +{ + g_repo = cl_git_sandbox_init("testrepo.git"); + cl_assert_equal_i(0, git_repository_is_shallow(g_repo)); + cl_assert_equal_p(NULL, git_error_last()); +} + +void test_grafts_shallow__shallow_oids(void) +{ + git_commit_graft *graft; + git_grafts *grafts; + + g_repo = cl_git_sandbox_init("shallow.git"); + + cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo)); + cl_assert_equal_i(1, git_grafts_size(grafts)); + cl_git_pass(git_grafts_get(&graft, grafts, &g_shallow_oid)); +} + +void test_grafts_shallow__cache_clearing(void) +{ + git_commit_graft *graft; + git_grafts *grafts; + git_oid tmp_oid; + + cl_git_pass(git_oid_fromstr(&tmp_oid, "0000000000000000000000000000000000000000")); + g_repo = cl_git_sandbox_init("shallow.git"); + cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo)); + + cl_assert_equal_i(1, git_grafts_size(grafts)); + cl_git_pass(git_grafts_get(&graft, grafts, &g_shallow_oid)); + + cl_git_mkfile("shallow.git/shallow", + "be3563ae3f795b2b4353bcce3a527ad0a4f7f644\n" + "0000000000000000000000000000000000000000\n" + ); + + cl_git_pass(git_grafts_refresh(grafts)); + cl_assert_equal_i(2, git_grafts_size(grafts)); + cl_git_pass(git_grafts_get(&graft, grafts, &g_shallow_oid)); + cl_git_pass(git_grafts_get(&graft, grafts, &tmp_oid)); + + cl_git_pass(p_unlink("shallow.git/shallow")); + cl_git_pass(git_grafts_refresh(grafts)); + cl_assert_equal_i(0, git_grafts_size(grafts)); +} + +void test_grafts_shallow__errors_on_borked(void) +{ + git_grafts *grafts; + + g_repo = cl_git_sandbox_init("shallow.git"); + + cl_git_mkfile("shallow.git/shallow", "lolno"); + cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo)); + cl_git_fail(git_grafts_refresh(grafts)); + cl_assert_equal_i(0, git_grafts_size(grafts)); + + cl_git_mkfile("shallow.git/shallow", "lolno\n"); + cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo)); + cl_git_fail(git_grafts_refresh(grafts)); + cl_assert_equal_i(0, git_grafts_size(grafts)); +} + +void test_grafts_shallow__revwalk_behavior(void) +{ + git_revwalk *w; + git_oid oid_1, oid_2, oid_3; + + g_repo = cl_git_sandbox_init("shallow.git"); + + cl_git_pass(git_revwalk_new(&w, g_repo)); + cl_git_pass(git_revwalk_push_head(w)); + + cl_git_pass(git_revwalk_next(&oid_1, w)); // a65fedf39aefe402d3bb6e24df4d4f5fe4547750 + cl_git_pass(git_revwalk_next(&oid_2, w)); // be3563ae3f795b2b4353bcce3a527ad0a4f7f644 + cl_git_fail_with(GIT_ITEROVER, git_revwalk_next(&oid_3, w)); + + cl_assert_equal_s(git_oid_tostr_s(&oid_1), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + cl_assert_equal_s(git_oid_tostr_s(&oid_2), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + + git_revwalk_free(w); +} + +void test_grafts_shallow__grafted_object(void) +{ + git_commit *commit; + + g_repo = cl_git_sandbox_init("shallow.git"); + + cl_git_pass(git_commit_lookup(&commit, g_repo, &g_shallow_oid)); + + cl_assert_equal_i(0, git_commit_parentcount(commit)); + + git_commit_free(commit); +} -- cgit v1.2.1 From 598ec303c6862f581c22c49228d543442e30257a Mon Sep 17 00:00:00 2001 From: yuangli Date: Fri, 29 Jul 2022 15:04:17 +0100 Subject: eliminate build warnings --- tests/libgit2/clone/shallow.c | 105 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/libgit2/clone/shallow.c (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c new file mode 100644 index 000000000..2cd3d6cac --- /dev/null +++ b/tests/libgit2/clone/shallow.c @@ -0,0 +1,105 @@ +#include "clar_libgit2.h" +#include "futils.h" +#include "repository.h" + +void test_clone_shallow__initialize(void) +{ + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1)); +} + +void test_clone_shallow__cleanup(void) +{ + git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); + cl_git_sandbox_cleanup(); +} + +static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) +{ + GIT_UNUSED(payload); + + cl_git_pass(git_remote_create_with_fetchspec(out, repo, name, url, "+refs/heads/master:refs/remotes/origin/master")); + + return 0; +} + +void test_clone_shallow__clone_depth_one(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_revwalk *walk; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_oid oid; + roots; + size_t num_commits = 0; + int error = 0; + + clone_opts.fetch_opts.depth = 1; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_1"); + + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + + cl_assert_equal_b(true, git_repository_is_shallow(repo)); + + cl_git_pass(git_repository_shallow_roots(&roots, repo)); + cl_assert_equal_i(1, roots.count); + cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ids[0])); + + git_revwalk_new(&walk, repo); + + git_revwalk_push_head(walk); + + while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { + num_commits++; + } + + cl_assert_equal_i(num_commits, 1); + cl_assert_equal_i(error, GIT_ITEROVER); + + git_str_dispose(&path); + git_revwalk_free(walk); + git_repository_free(repo); +} + +void test_clone_shallow__clone_depth_five(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_revwalk *walk; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_oid oid; + git_oidarray roots; + size_t num_commits = 0; + int error = 0; + + clone_opts.fetch_opts.depth = 5; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_5"); + + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + + cl_assert_equal_b(true, git_repository_is_shallow(repo)); + + cl_git_pass(git_repository_shallow_roots(&roots, repo)); + cl_assert_equal_i(3, roots.count); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots.ids[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots.ids[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ids[2])); + + git_revwalk_new(&walk, repo); + + git_revwalk_push_head(walk); + + while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { + num_commits++; + } + + cl_assert_equal_i(num_commits, 13); + cl_assert_equal_i(error, GIT_ITEROVER); + + git_str_dispose(&path); + git_revwalk_free(walk); + git_repository_free(repo); +} -- cgit v1.2.1 From 179aac788d45d3683a93ad478bfb7371c549ca98 Mon Sep 17 00:00:00 2001 From: yuangli Date: Fri, 29 Jul 2022 16:04:43 +0100 Subject: fix clone::shallow test behaviour --- tests/libgit2/clone/shallow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c index 2cd3d6cac..4b27b27a9 100644 --- a/tests/libgit2/clone/shallow.c +++ b/tests/libgit2/clone/shallow.c @@ -29,7 +29,7 @@ void test_clone_shallow__clone_depth_one(void) git_revwalk *walk; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_oid oid; - roots; + git_oidarray roots; size_t num_commits = 0; int error = 0; -- cgit v1.2.1 From 829555a9382f74af5280ab6cc2ac505534a4cecb Mon Sep 17 00:00:00 2001 From: yuangli Date: Tue, 2 Aug 2022 16:47:01 +0100 Subject: edit tests for shallow clones --- tests/libgit2/clone/shallow.c | 48 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c index 4b27b27a9..7fb056f91 100644 --- a/tests/libgit2/clone/shallow.c +++ b/tests/libgit2/clone/shallow.c @@ -22,6 +22,32 @@ static int remote_single_branch(git_remote **out, git_repository *repo, const ch return 0; } +void test_clone_shallow__clone_depth_zero(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_array_oid_t roots = GIT_ARRAY_INIT; + + clone_opts.fetch_opts.depth = 0; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_0"); + + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + + /* cloning with depth 0 results in a full clone. */ + cl_assert_equal_b(false, git_repository_is_shallow(repo)); + + /* full clones do not have shallow roots. */ + cl_git_pass(git_repository__shallow_roots(&roots, repo)); + cl_assert_equal_i(0, roots.size); + + git_array_clear(roots); + git_str_dispose(&path); + git_repository_free(repo); +} + void test_clone_shallow__clone_depth_one(void) { git_str path = GIT_STR_INIT; @@ -29,7 +55,7 @@ void test_clone_shallow__clone_depth_one(void) git_revwalk *walk; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_oid oid; - git_oidarray roots; + git_array_oid_t roots = GIT_ARRAY_INIT; size_t num_commits = 0; int error = 0; @@ -42,9 +68,9 @@ void test_clone_shallow__clone_depth_one(void) cl_assert_equal_b(true, git_repository_is_shallow(repo)); - cl_git_pass(git_repository_shallow_roots(&roots, repo)); - cl_assert_equal_i(1, roots.count); - cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ids[0])); + cl_git_pass(git_repository__shallow_roots(&roots, repo)); + cl_assert_equal_i(1, roots.size); + cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ptr[0])); git_revwalk_new(&walk, repo); @@ -57,6 +83,7 @@ void test_clone_shallow__clone_depth_one(void) cl_assert_equal_i(num_commits, 1); cl_assert_equal_i(error, GIT_ITEROVER); + git_array_clear(roots); git_str_dispose(&path); git_revwalk_free(walk); git_repository_free(repo); @@ -69,7 +96,7 @@ void test_clone_shallow__clone_depth_five(void) git_revwalk *walk; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_oid oid; - git_oidarray roots; + git_array_oid_t roots = GIT_ARRAY_INIT; size_t num_commits = 0; int error = 0; @@ -82,11 +109,11 @@ void test_clone_shallow__clone_depth_five(void) cl_assert_equal_b(true, git_repository_is_shallow(repo)); - cl_git_pass(git_repository_shallow_roots(&roots, repo)); - cl_assert_equal_i(3, roots.count); - cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots.ids[0])); - cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots.ids[1])); - cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ids[2])); + cl_git_pass(git_repository__shallow_roots(&roots, repo)); + cl_assert_equal_i(3, roots.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots.ptr[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ptr[2])); git_revwalk_new(&walk, repo); @@ -99,6 +126,7 @@ void test_clone_shallow__clone_depth_five(void) cl_assert_equal_i(num_commits, 13); cl_assert_equal_i(error, GIT_ITEROVER); + git_array_clear(roots); git_str_dispose(&path); git_revwalk_free(walk); git_repository_free(repo); -- cgit v1.2.1 From df5eb3239b1419b3f4382d7bcca9a5d85611d7d3 Mon Sep 17 00:00:00 2001 From: yuangli Date: Tue, 9 Aug 2022 19:24:57 +0100 Subject: support fetch unshallow option on shallow repos --- tests/libgit2/clone/shallow.c | 41 +++++++++++++++++++++ tests/libgit2/transports/smart/shallowarray.c | 52 +++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/libgit2/transports/smart/shallowarray.c (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c index 7fb056f91..2a88d5d05 100644 --- a/tests/libgit2/clone/shallow.c +++ b/tests/libgit2/clone/shallow.c @@ -131,3 +131,44 @@ void test_clone_shallow__clone_depth_five(void) git_revwalk_free(walk); git_repository_free(repo); } + +void test_clone_shallow__unshallow(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_revwalk *walk; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; + git_remote *origin = NULL; + git_oid oid; + size_t num_commits = 0; + int error = 0; + + clone_opts.fetch_opts.depth = 5; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "unshallow"); + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + cl_assert_equal_b(true, git_repository_is_shallow(repo)); + + fetch_opts.unshallow = 1; + cl_git_pass(git_remote_lookup(&origin, repo, "origin")); + + cl_git_pass(git_remote_fetch(origin, NULL, &fetch_opts, NULL)); + cl_assert_equal_b(false, git_repository_is_shallow(repo)); + + git_revwalk_new(&walk, repo); + git_revwalk_push_head(walk); + + while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { + num_commits++; + } + + cl_assert_equal_i(num_commits, 21); + cl_assert_equal_i(error, GIT_ITEROVER); + + git_remote_free(origin); + git_str_dispose(&path); + git_revwalk_free(walk); + git_repository_free(repo); +} diff --git a/tests/libgit2/transports/smart/shallowarray.c b/tests/libgit2/transports/smart/shallowarray.c new file mode 100644 index 000000000..c51e62713 --- /dev/null +++ b/tests/libgit2/transports/smart/shallowarray.c @@ -0,0 +1,52 @@ +#include "clar_libgit2.h" + +#include "git2/oid.h" +#include "git2/transport.h" + +#include "common.h" +#include "transports/smart.h" +#include "oid.h" + +#include + +#define oid_0 "c070ad8c08840c8116da865b2d65593a6bb9cd2a" +#define oid_1 "0966a434eb1a025db6b71485ab63a3bfbea520b6" +#define oid_2 "83834a7afdaa1a1260568567f6ad90020389f664" + +void test_transports_smart_shallowarray__add_and_remove_oid_from_shallowarray(void) +{ + git_oid oid_0_obj, oid_1_obj, oid_2_obj; + git_shallowarray *shallow_roots = git__malloc(sizeof(git_shallowarray)); + git_array_init(shallow_roots->array); + + git_oid_fromstr(&oid_0_obj, oid_0); + git_oid_fromstr(&oid_1_obj, oid_1); + git_oid_fromstr(&oid_2_obj, oid_2); + + git_shallowarray_add(shallow_roots, &oid_0_obj); + git_shallowarray_add(shallow_roots, &oid_1_obj); + git_shallowarray_add(shallow_roots, &oid_2_obj); + + cl_assert_equal_i(3, shallow_roots->array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&shallow_roots->array.ptr[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&shallow_roots->array.ptr[2])); + + git_shallowarray_remove(shallow_roots, &oid_2_obj); + + cl_assert_equal_i(2, shallow_roots->array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&shallow_roots->array.ptr[1])); + + git_shallowarray_remove(shallow_roots, &oid_1_obj); + + cl_assert_equal_i(1, shallow_roots->array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); + + git_shallowarray_remove(shallow_roots, &oid_0_obj); + + cl_assert_equal_i(0, shallow_roots->array.size); + + git_array_clear(shallow_roots->array); + git__free(shallow_roots); +} -- cgit v1.2.1 From d0eba8ae58092f0db061e3776f194256d0a56fde Mon Sep 17 00:00:00 2001 From: Yuang Li Date: Wed, 31 Aug 2022 17:03:53 +0100 Subject: fix shallowarray test --- tests/libgit2/transports/smart/shallowarray.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/transports/smart/shallowarray.c b/tests/libgit2/transports/smart/shallowarray.c index c51e62713..ec4388e42 100644 --- a/tests/libgit2/transports/smart/shallowarray.c +++ b/tests/libgit2/transports/smart/shallowarray.c @@ -19,9 +19,9 @@ void test_transports_smart_shallowarray__add_and_remove_oid_from_shallowarray(vo git_shallowarray *shallow_roots = git__malloc(sizeof(git_shallowarray)); git_array_init(shallow_roots->array); - git_oid_fromstr(&oid_0_obj, oid_0); - git_oid_fromstr(&oid_1_obj, oid_1); - git_oid_fromstr(&oid_2_obj, oid_2); + git_oid__fromstr(&oid_0_obj, oid_0, GIT_OID_SHA1); + git_oid__fromstr(&oid_1_obj, oid_1, GIT_OID_SHA1); + git_oid__fromstr(&oid_2_obj, oid_2, GIT_OID_SHA1); git_shallowarray_add(shallow_roots, &oid_0_obj); git_shallowarray_add(shallow_roots, &oid_1_obj); -- cgit v1.2.1 From 89c1b019b7026406834ce0f68a18f255f4b36f99 Mon Sep 17 00:00:00 2001 From: Yuang Li Date: Wed, 31 Aug 2022 17:28:27 +0100 Subject: fix free error --- tests/libgit2/clone/nonetwork.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/nonetwork.c b/tests/libgit2/clone/nonetwork.c index eab633635..0c4e5a87d 100644 --- a/tests/libgit2/clone/nonetwork.c +++ b/tests/libgit2/clone/nonetwork.c @@ -296,8 +296,6 @@ void test_clone_nonetwork__clone_tag_to_tree(void) cl_git_pass(git_tree_entry_bypath(&tentry, tree, file_path)); git_tree_entry_free(tentry); git_tree_free(tree); - - cl_fixture_cleanup("testrepo.git"); } static void assert_correct_reflog(const char *name) -- cgit v1.2.1 From 34de5c87fb118ffa177bf2e6a023aee72c4f46f7 Mon Sep 17 00:00:00 2001 From: Yuang Li Date: Mon, 5 Sep 2022 10:38:53 +0100 Subject: fix seg faults --- tests/libgit2/clone/nonetwork.c | 2 ++ tests/libgit2/clone/shallow.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/nonetwork.c b/tests/libgit2/clone/nonetwork.c index 0c4e5a87d..eab633635 100644 --- a/tests/libgit2/clone/nonetwork.c +++ b/tests/libgit2/clone/nonetwork.c @@ -296,6 +296,8 @@ void test_clone_nonetwork__clone_tag_to_tree(void) cl_git_pass(git_tree_entry_bypath(&tentry, tree, file_path)); git_tree_entry_free(tentry); git_tree_free(tree); + + cl_fixture_cleanup("testrepo.git"); } static void assert_correct_reflog(const char *name) diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c index 2a88d5d05..b0114081c 100644 --- a/tests/libgit2/clone/shallow.c +++ b/tests/libgit2/clone/shallow.c @@ -10,7 +10,7 @@ void test_clone_shallow__initialize(void) void test_clone_shallow__cleanup(void) { git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); - cl_git_sandbox_cleanup(); + /*cl_git_sandbox_cleanup();*/ } static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) -- cgit v1.2.1 From d23a7903d107528f9d62608f9b236251d9756b00 Mon Sep 17 00:00:00 2001 From: Yuang Li Date: Mon, 5 Sep 2022 19:44:49 +0100 Subject: remove unused statements --- tests/libgit2/clone/shallow.c | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c index b0114081c..eacfe1bcf 100644 --- a/tests/libgit2/clone/shallow.c +++ b/tests/libgit2/clone/shallow.c @@ -10,7 +10,6 @@ void test_clone_shallow__initialize(void) void test_clone_shallow__cleanup(void) { git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); - /*cl_git_sandbox_cleanup();*/ } static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) -- cgit v1.2.1 From a9793ac643a0cd82b00970d0d6e0b67681ec3112 Mon Sep 17 00:00:00 2001 From: Yuang Li Date: Tue, 6 Sep 2022 16:01:52 +0100 Subject: refactor grafts tests --- tests/libgit2/grafts/basic.c | 10 +++++----- tests/libgit2/grafts/parse.c | 4 ++-- tests/libgit2/grafts/shallow.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/grafts/basic.c b/tests/libgit2/grafts/basic.c index 4be4a12bf..5ad437b19 100644 --- a/tests/libgit2/grafts/basic.c +++ b/tests/libgit2/grafts/basic.c @@ -27,10 +27,10 @@ void test_grafts_basic__graft_add(void) cl_git_pass(git_grafts_new(&grafts)); cl_assert(oid1 = git_array_alloc(parents)); - cl_git_pass(git_oid_fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9")); + cl_git_pass(git_oid__fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9", GIT_OID_SHA1)); git_oid_cpy(oid1, &oid_src); - git_oid_fromstr(&oid_src, "f503807ffa920e407a600cfaee96b7152259acc7"); + git_oid__fromstr(&oid_src, "f503807ffa920e407a600cfaee96b7152259acc7", GIT_OID_SHA1); cl_git_pass(git_grafts_add(grafts, &oid_src, parents)); git_array_clear(parents); @@ -75,17 +75,17 @@ void test_grafts_basic__grafted_objects(void) git_oid oid; git_commit *commit; - cl_git_pass(git_oid_fromstr(&oid, "f503807ffa920e407a600cfaee96b7152259acc7")); + cl_git_pass(git_oid__fromstr(&oid, "f503807ffa920e407a600cfaee96b7152259acc7", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); cl_assert_equal_i(1, git_commit_parentcount(commit)); git_commit_free(commit); - cl_git_pass(git_oid_fromstr(&oid, "0512adebd3782157f0d5c9b22b043f87b4aaff9e")); + cl_git_pass(git_oid__fromstr(&oid, "0512adebd3782157f0d5c9b22b043f87b4aaff9e", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); cl_assert_equal_i(1, git_commit_parentcount(commit)); git_commit_free(commit); - cl_git_pass(git_oid_fromstr(&oid, "66cc22a015f6ca75b34c82d28f78ba663876bade")); + cl_git_pass(git_oid__fromstr(&oid, "66cc22a015f6ca75b34c82d28f78ba663876bade", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); cl_assert_equal_i(4, git_commit_parentcount(commit)); git_commit_free(commit); diff --git a/tests/libgit2/grafts/parse.c b/tests/libgit2/grafts/parse.c index de110c901..149b01c8c 100644 --- a/tests/libgit2/grafts/parse.c +++ b/tests/libgit2/grafts/parse.c @@ -46,14 +46,14 @@ static void assert_graft_contains(git_grafts *grafts, const char *graft, size_t va_list ap; size_t i = 0; - cl_git_pass(git_oid_fromstr(&oid, graft)); + cl_git_pass(git_oid__fromstr(&oid, graft, GIT_OID_SHA1)); cl_git_pass(git_grafts_get(&commit, grafts, &oid)); cl_assert_equal_oid(&commit->oid, &oid); cl_assert_equal_i(commit->parents.size, n); va_start(ap, n); while (i < n) { - cl_git_pass(git_oid_fromstr(&oid, va_arg(ap, const char *))); + cl_git_pass(git_oid__fromstr(&oid, va_arg(ap, const char *), GIT_OID_SHA1)); cl_assert_equal_oid(&commit->parents.ptr[i], &oid); i++; } diff --git a/tests/libgit2/grafts/shallow.c b/tests/libgit2/grafts/shallow.c index a75b5a051..8c2723922 100644 --- a/tests/libgit2/grafts/shallow.c +++ b/tests/libgit2/grafts/shallow.c @@ -20,7 +20,7 @@ void test_grafts_shallow__unset_feature_flag(void) void test_grafts_shallow__initialize(void) { git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1); - cl_git_pass(git_oid_fromstr(&g_shallow_oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&g_shallow_oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); } void test_grafts_shallow__cleanup(void) @@ -73,7 +73,7 @@ void test_grafts_shallow__cache_clearing(void) git_grafts *grafts; git_oid tmp_oid; - cl_git_pass(git_oid_fromstr(&tmp_oid, "0000000000000000000000000000000000000000")); + cl_git_pass(git_oid__fromstr(&tmp_oid, "0000000000000000000000000000000000000000", GIT_OID_SHA1)); g_repo = cl_git_sandbox_init("shallow.git"); cl_git_pass(git_repository_shallow_grafts__weakptr(&grafts, g_repo)); -- cgit v1.2.1 From dd15c615bde54eb02c5cec17257a83dcd8528371 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 22 Apr 2023 23:19:59 +0100 Subject: shallow: remove feature flag The opt mechanism isn't _really_ meant to be for feature flags, and it's weird to feature flag shallow / unshallow at all. --- tests/libgit2/clone/shallow.c | 2 -- tests/libgit2/grafts/basic.c | 2 -- tests/libgit2/grafts/shallow.c | 12 ------------ 3 files changed, 16 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c index eacfe1bcf..28b0116fa 100644 --- a/tests/libgit2/clone/shallow.c +++ b/tests/libgit2/clone/shallow.c @@ -4,12 +4,10 @@ void test_clone_shallow__initialize(void) { - cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1)); } void test_clone_shallow__cleanup(void) { - git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); } static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) diff --git a/tests/libgit2/grafts/basic.c b/tests/libgit2/grafts/basic.c index 5ad437b19..fe7477097 100644 --- a/tests/libgit2/grafts/basic.c +++ b/tests/libgit2/grafts/basic.c @@ -7,13 +7,11 @@ static git_repository *g_repo; void test_grafts_basic__initialize(void) { - git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1); g_repo = cl_git_sandbox_init("grafted.git"); } void test_grafts_basic__cleanup(void) { - git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); cl_git_sandbox_cleanup(); } diff --git a/tests/libgit2/grafts/shallow.c b/tests/libgit2/grafts/shallow.c index 8c2723922..5911a26aa 100644 --- a/tests/libgit2/grafts/shallow.c +++ b/tests/libgit2/grafts/shallow.c @@ -7,25 +7,13 @@ static git_repository *g_repo; static git_oid g_shallow_oid; -void test_grafts_shallow__set_feature_flag(void) -{ - cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1)); -} - -void test_grafts_shallow__unset_feature_flag(void) -{ - cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0)); -} - void test_grafts_shallow__initialize(void) { - git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 1); cl_git_pass(git_oid__fromstr(&g_shallow_oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); } void test_grafts_shallow__cleanup(void) { - git_libgit2_opts(GIT_OPT_ENABLE_SHALLOW, 0); cl_git_sandbox_cleanup(); } -- cgit v1.2.1 From 6cec01b4d8498203ae3a03949ffd480845269a3d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 22 Apr 2023 23:38:52 +0100 Subject: shallow: move tests to online --- tests/libgit2/clone/shallow.c | 171 ----------------------------------------- tests/libgit2/online/shallow.c | 163 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 171 deletions(-) delete mode 100644 tests/libgit2/clone/shallow.c create mode 100644 tests/libgit2/online/shallow.c (limited to 'tests/libgit2') diff --git a/tests/libgit2/clone/shallow.c b/tests/libgit2/clone/shallow.c deleted file mode 100644 index 28b0116fa..000000000 --- a/tests/libgit2/clone/shallow.c +++ /dev/null @@ -1,171 +0,0 @@ -#include "clar_libgit2.h" -#include "futils.h" -#include "repository.h" - -void test_clone_shallow__initialize(void) -{ -} - -void test_clone_shallow__cleanup(void) -{ -} - -static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) -{ - GIT_UNUSED(payload); - - cl_git_pass(git_remote_create_with_fetchspec(out, repo, name, url, "+refs/heads/master:refs/remotes/origin/master")); - - return 0; -} - -void test_clone_shallow__clone_depth_zero(void) -{ - git_str path = GIT_STR_INIT; - git_repository *repo; - git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_array_oid_t roots = GIT_ARRAY_INIT; - - clone_opts.fetch_opts.depth = 0; - clone_opts.remote_cb = remote_single_branch; - - git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_0"); - - cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); - - /* cloning with depth 0 results in a full clone. */ - cl_assert_equal_b(false, git_repository_is_shallow(repo)); - - /* full clones do not have shallow roots. */ - cl_git_pass(git_repository__shallow_roots(&roots, repo)); - cl_assert_equal_i(0, roots.size); - - git_array_clear(roots); - git_str_dispose(&path); - git_repository_free(repo); -} - -void test_clone_shallow__clone_depth_one(void) -{ - git_str path = GIT_STR_INIT; - git_repository *repo; - git_revwalk *walk; - git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_oid oid; - git_array_oid_t roots = GIT_ARRAY_INIT; - size_t num_commits = 0; - int error = 0; - - clone_opts.fetch_opts.depth = 1; - clone_opts.remote_cb = remote_single_branch; - - git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_1"); - - cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); - - cl_assert_equal_b(true, git_repository_is_shallow(repo)); - - cl_git_pass(git_repository__shallow_roots(&roots, repo)); - cl_assert_equal_i(1, roots.size); - cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ptr[0])); - - git_revwalk_new(&walk, repo); - - git_revwalk_push_head(walk); - - while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { - num_commits++; - } - - cl_assert_equal_i(num_commits, 1); - cl_assert_equal_i(error, GIT_ITEROVER); - - git_array_clear(roots); - git_str_dispose(&path); - git_revwalk_free(walk); - git_repository_free(repo); -} - -void test_clone_shallow__clone_depth_five(void) -{ - git_str path = GIT_STR_INIT; - git_repository *repo; - git_revwalk *walk; - git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_oid oid; - git_array_oid_t roots = GIT_ARRAY_INIT; - size_t num_commits = 0; - int error = 0; - - clone_opts.fetch_opts.depth = 5; - clone_opts.remote_cb = remote_single_branch; - - git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_5"); - - cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); - - cl_assert_equal_b(true, git_repository_is_shallow(repo)); - - cl_git_pass(git_repository__shallow_roots(&roots, repo)); - cl_assert_equal_i(3, roots.size); - cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots.ptr[0])); - cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots.ptr[1])); - cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ptr[2])); - - git_revwalk_new(&walk, repo); - - git_revwalk_push_head(walk); - - while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { - num_commits++; - } - - cl_assert_equal_i(num_commits, 13); - cl_assert_equal_i(error, GIT_ITEROVER); - - git_array_clear(roots); - git_str_dispose(&path); - git_revwalk_free(walk); - git_repository_free(repo); -} - -void test_clone_shallow__unshallow(void) -{ - git_str path = GIT_STR_INIT; - git_repository *repo; - git_revwalk *walk; - git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; - git_remote *origin = NULL; - git_oid oid; - size_t num_commits = 0; - int error = 0; - - clone_opts.fetch_opts.depth = 5; - clone_opts.remote_cb = remote_single_branch; - - git_str_joinpath(&path, clar_sandbox_path(), "unshallow"); - cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); - cl_assert_equal_b(true, git_repository_is_shallow(repo)); - - fetch_opts.unshallow = 1; - cl_git_pass(git_remote_lookup(&origin, repo, "origin")); - - cl_git_pass(git_remote_fetch(origin, NULL, &fetch_opts, NULL)); - cl_assert_equal_b(false, git_repository_is_shallow(repo)); - - git_revwalk_new(&walk, repo); - git_revwalk_push_head(walk); - - while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { - num_commits++; - } - - cl_assert_equal_i(num_commits, 21); - cl_assert_equal_i(error, GIT_ITEROVER); - - git_remote_free(origin); - git_str_dispose(&path); - git_revwalk_free(walk); - git_repository_free(repo); -} diff --git a/tests/libgit2/online/shallow.c b/tests/libgit2/online/shallow.c new file mode 100644 index 000000000..a889a68cd --- /dev/null +++ b/tests/libgit2/online/shallow.c @@ -0,0 +1,163 @@ +#include "clar_libgit2.h" +#include "futils.h" +#include "repository.h" + +static int remote_single_branch(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) +{ + GIT_UNUSED(payload); + + cl_git_pass(git_remote_create_with_fetchspec(out, repo, name, url, "+refs/heads/master:refs/remotes/origin/master")); + + return 0; +} + +void test_online_shallow__clone_depth_zero(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_array_oid_t roots = GIT_ARRAY_INIT; + + clone_opts.fetch_opts.depth = 0; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_0"); + + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + + /* cloning with depth 0 results in a full clone. */ + cl_assert_equal_b(false, git_repository_is_shallow(repo)); + + /* full clones do not have shallow roots. */ + cl_git_pass(git_repository__shallow_roots(&roots, repo)); + cl_assert_equal_i(0, roots.size); + + git_array_clear(roots); + git_str_dispose(&path); + git_repository_free(repo); +} + +void test_online_shallow__clone_depth_one(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_revwalk *walk; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_oid oid; + git_array_oid_t roots = GIT_ARRAY_INIT; + size_t num_commits = 0; + int error = 0; + + clone_opts.fetch_opts.depth = 1; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_1"); + + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + + cl_assert_equal_b(true, git_repository_is_shallow(repo)); + + cl_git_pass(git_repository__shallow_roots(&roots, repo)); + cl_assert_equal_i(1, roots.size); + cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ptr[0])); + + git_revwalk_new(&walk, repo); + + git_revwalk_push_head(walk); + + while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { + num_commits++; + } + + cl_assert_equal_i(num_commits, 1); + cl_assert_equal_i(error, GIT_ITEROVER); + + git_array_clear(roots); + git_str_dispose(&path); + git_revwalk_free(walk); + git_repository_free(repo); +} + +void test_online_shallow__clone_depth_five(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_revwalk *walk; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_oid oid; + git_array_oid_t roots = GIT_ARRAY_INIT; + size_t num_commits = 0; + int error = 0; + + clone_opts.fetch_opts.depth = 5; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "shallowclone_5"); + + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + + cl_assert_equal_b(true, git_repository_is_shallow(repo)); + + cl_git_pass(git_repository__shallow_roots(&roots, repo)); + cl_assert_equal_i(3, roots.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots.ptr[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ptr[2])); + + git_revwalk_new(&walk, repo); + + git_revwalk_push_head(walk); + + while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { + num_commits++; + } + + cl_assert_equal_i(num_commits, 13); + cl_assert_equal_i(error, GIT_ITEROVER); + + git_array_clear(roots); + git_str_dispose(&path); + git_revwalk_free(walk); + git_repository_free(repo); +} + +void test_online_shallow__unshallow(void) +{ + git_str path = GIT_STR_INIT; + git_repository *repo; + git_revwalk *walk; + git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; + git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; + git_remote *origin = NULL; + git_oid oid; + size_t num_commits = 0; + int error = 0; + + clone_opts.fetch_opts.depth = 5; + clone_opts.remote_cb = remote_single_branch; + + git_str_joinpath(&path, clar_sandbox_path(), "unshallow"); + cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); + cl_assert_equal_b(true, git_repository_is_shallow(repo)); + + fetch_opts.unshallow = 1; + cl_git_pass(git_remote_lookup(&origin, repo, "origin")); + + cl_git_pass(git_remote_fetch(origin, NULL, &fetch_opts, NULL)); + cl_assert_equal_b(false, git_repository_is_shallow(repo)); + + git_revwalk_new(&walk, repo); + git_revwalk_push_head(walk); + + while ((error = git_revwalk_next(&oid, walk)) == GIT_OK) { + num_commits++; + } + + cl_assert_equal_i(num_commits, 21); + cl_assert_equal_i(error, GIT_ITEROVER); + + git_remote_free(origin); + git_str_dispose(&path); + git_revwalk_free(walk); + git_repository_free(repo); +} -- cgit v1.2.1 From d69c7a72386c9e01f4b0c8945724f870bf9aa4f6 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 24 Apr 2023 11:43:03 +0100 Subject: transport: transports understand oid type Teach the smart transport more about oid types, instead of assuming SHA1. --- tests/libgit2/transports/smart/packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/transports/smart/packet.c b/tests/libgit2/transports/smart/packet.c index 2035e3b65..a775a4cfa 100644 --- a/tests/libgit2/transports/smart/packet.c +++ b/tests/libgit2/transports/smart/packet.c @@ -25,7 +25,7 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data, size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_data *pkt; - git_pkt_parse_data pkt_parse_data = { 0 }; + git_pkt_parse_data pkt_parse_data = { 1, GIT_OID_SHA1 }; cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_DATA); @@ -71,7 +71,7 @@ static void assert_ack_parses(const char *line, const char *expected_oid, enum g const char *endptr; git_pkt_ack *pkt; git_oid oid; - git_pkt_parse_data pkt_parse_data = { 0 }; + git_pkt_parse_data pkt_parse_data = { 1, GIT_OID_SHA1 }; cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1)); -- cgit v1.2.1 From 7d7f3059decbd6b4730bfd09da54726c1b3ed8ea Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 24 Apr 2023 13:32:43 +0100 Subject: grafts: handle SHA256 graft files --- tests/libgit2/grafts/basic.c | 2 +- tests/libgit2/grafts/parse.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/grafts/basic.c b/tests/libgit2/grafts/basic.c index fe7477097..30c87f908 100644 --- a/tests/libgit2/grafts/basic.c +++ b/tests/libgit2/grafts/basic.c @@ -22,7 +22,7 @@ void test_grafts_basic__graft_add(void) git_commit_graft *graft; git_grafts *grafts; - cl_git_pass(git_grafts_new(&grafts)); + cl_git_pass(git_grafts_new(&grafts, GIT_OID_SHA1)); cl_assert(oid1 = git_array_alloc(parents)); cl_git_pass(git_oid__fromstr(&oid_src, "2f3053cbff8a4ca2f0666de364ddb734a28a31a9", GIT_OID_SHA1)); diff --git a/tests/libgit2/grafts/parse.c b/tests/libgit2/grafts/parse.c index 149b01c8c..3b0618a1d 100644 --- a/tests/libgit2/grafts/parse.c +++ b/tests/libgit2/grafts/parse.c @@ -19,7 +19,7 @@ static git_grafts *grafts; void test_grafts_parse__initialize(void) { - cl_git_pass(git_grafts_new(&grafts)); + cl_git_pass(git_grafts_new(&grafts, GIT_OID_SHA1)); } void test_grafts_parse__cleanup(void) -- cgit v1.2.1 From 19ccab005ed2a65ddcd3f50a2a09214a5849871d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 25 Apr 2023 09:33:24 +0100 Subject: shallow: cleanup whitespace in tests --- tests/libgit2/transports/smart/shallowarray.c | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/transports/smart/shallowarray.c b/tests/libgit2/transports/smart/shallowarray.c index ec4388e42..34511c5f6 100644 --- a/tests/libgit2/transports/smart/shallowarray.c +++ b/tests/libgit2/transports/smart/shallowarray.c @@ -15,37 +15,37 @@ void test_transports_smart_shallowarray__add_and_remove_oid_from_shallowarray(void) { - git_oid oid_0_obj, oid_1_obj, oid_2_obj; - git_shallowarray *shallow_roots = git__malloc(sizeof(git_shallowarray)); - git_array_init(shallow_roots->array); + git_oid oid_0_obj, oid_1_obj, oid_2_obj; + git_shallowarray *shallow_roots = git__malloc(sizeof(git_shallowarray)); + git_array_init(shallow_roots->array); - git_oid__fromstr(&oid_0_obj, oid_0, GIT_OID_SHA1); - git_oid__fromstr(&oid_1_obj, oid_1, GIT_OID_SHA1); - git_oid__fromstr(&oid_2_obj, oid_2, GIT_OID_SHA1); + git_oid__fromstr(&oid_0_obj, oid_0, GIT_OID_SHA1); + git_oid__fromstr(&oid_1_obj, oid_1, GIT_OID_SHA1); + git_oid__fromstr(&oid_2_obj, oid_2, GIT_OID_SHA1); - git_shallowarray_add(shallow_roots, &oid_0_obj); - git_shallowarray_add(shallow_roots, &oid_1_obj); - git_shallowarray_add(shallow_roots, &oid_2_obj); + git_shallowarray_add(shallow_roots, &oid_0_obj); + git_shallowarray_add(shallow_roots, &oid_1_obj); + git_shallowarray_add(shallow_roots, &oid_2_obj); - cl_assert_equal_i(3, shallow_roots->array.size); + cl_assert_equal_i(3, shallow_roots->array.size); cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&shallow_roots->array.ptr[1])); cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&shallow_roots->array.ptr[2])); - git_shallowarray_remove(shallow_roots, &oid_2_obj); + git_shallowarray_remove(shallow_roots, &oid_2_obj); - cl_assert_equal_i(2, shallow_roots->array.size); + cl_assert_equal_i(2, shallow_roots->array.size); cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&shallow_roots->array.ptr[1])); - git_shallowarray_remove(shallow_roots, &oid_1_obj); + git_shallowarray_remove(shallow_roots, &oid_1_obj); - cl_assert_equal_i(1, shallow_roots->array.size); + cl_assert_equal_i(1, shallow_roots->array.size); cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); - git_shallowarray_remove(shallow_roots, &oid_0_obj); + git_shallowarray_remove(shallow_roots, &oid_0_obj); - cl_assert_equal_i(0, shallow_roots->array.size); + cl_assert_equal_i(0, shallow_roots->array.size); git_array_clear(shallow_roots->array); git__free(shallow_roots); -- cgit v1.2.1 From 0a7e32b2326c02a91f9560dfd209e56ea9fb9d49 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 8 May 2023 10:07:11 +0100 Subject: oid: use an oid array instead of shallowarray Users should provide us an array of object ids; we don't need a separate type. And especially, we should not be mutating user-providing values. Instead, use `git_oid *` in the shallow code. --- tests/libgit2/core/oidarray.c | 98 +++++++++++++++++++++++++++ tests/libgit2/online/shallow.c | 35 +++++----- tests/libgit2/transports/smart/shallowarray.c | 52 -------------- 3 files changed, 117 insertions(+), 68 deletions(-) create mode 100644 tests/libgit2/core/oidarray.c delete mode 100644 tests/libgit2/transports/smart/shallowarray.c (limited to 'tests/libgit2') diff --git a/tests/libgit2/core/oidarray.c b/tests/libgit2/core/oidarray.c new file mode 100644 index 000000000..4a9e47c70 --- /dev/null +++ b/tests/libgit2/core/oidarray.c @@ -0,0 +1,98 @@ +#include "clar_libgit2.h" + +#include "git2/oid.h" +#include "git2/transport.h" + +#include "common.h" +#include "transports/smart.h" +#include "oid.h" +#include "oidarray.h" + +#include + +#define oid_0 "c070ad8c08840c8116da865b2d65593a6bb9cd2a" +#define oid_1 "0966a434eb1a025db6b71485ab63a3bfbea520b6" +#define oid_2 "83834a7afdaa1a1260568567f6ad90020389f664" +#define oid_3 "746fb4c91a7b6190bc4761adf7410afc4b59812c" + +void test_core_oidarray__add_and_remove_oid_from_shallowarray(void) +{ + git_oid oid_0_obj, oid_1_obj, oid_2_obj, oid_3_obj; + git_array_oid_t array = GIT_ARRAY_INIT; + + git_oid__fromstr(&oid_0_obj, oid_0, GIT_OID_SHA1); + git_oid__fromstr(&oid_1_obj, oid_1, GIT_OID_SHA1); + git_oid__fromstr(&oid_2_obj, oid_2, GIT_OID_SHA1); + git_oid__fromstr(&oid_3_obj, oid_3, GIT_OID_SHA1); + + /* add some initial ids */ + git_oidarray__add(&array, &oid_0_obj); + git_oidarray__add(&array, &oid_1_obj); + git_oidarray__add(&array, &oid_2_obj); + + cl_assert_equal_i(3, array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&array.ptr[2])); + + /* don't duplicate existing ids */ + git_oidarray__add(&array, &oid_1_obj); + + cl_assert_equal_i(3, array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&array.ptr[2])); + + /* remove the last id */ + cl_assert_equal_i(1, git_oidarray__remove(&array, &oid_2_obj)); + + cl_assert_equal_i(2, array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[1])); + + /* add another id */ + git_oidarray__add(&array, &oid_3_obj); + + cl_assert_equal_i(3, array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[1])); + cl_assert_equal_s("746fb4c91a7b6190bc4761adf7410afc4b59812c", git_oid_tostr_s(&array.ptr[2])); + + /* remove the first id */ + cl_assert_equal_i(1, git_oidarray__remove(&array, &oid_0_obj)); + + cl_assert_equal_i(2, array.size); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("746fb4c91a7b6190bc4761adf7410afc4b59812c", git_oid_tostr_s(&array.ptr[1])); + + /* removing a nonexistent oid does nothing */ + cl_assert_equal_i(0, git_oidarray__remove(&array, &oid_2_obj)); + + /* add another id */ + git_oidarray__add(&array, &oid_0_obj); + + cl_assert_equal_i(3, array.size); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("746fb4c91a7b6190bc4761adf7410afc4b59812c", git_oid_tostr_s(&array.ptr[1])); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[2])); + + /* remove another id */ + cl_assert_equal_i(1, git_oidarray__remove(&array, &oid_3_obj)); + + cl_assert_equal_i(2, array.size); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&array.ptr[0])); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[1])); + + /* remove another id */ + cl_assert_equal_i(1, git_oidarray__remove(&array, &oid_1_obj)); + + cl_assert_equal_i(1, array.size); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&array.ptr[0])); + + /* remove the final id */ + cl_assert_equal_i(1, git_oidarray__remove(&array, &oid_0_obj)); + + cl_assert_equal_i(0, array.size); + + git_array_clear(array); +} diff --git a/tests/libgit2/online/shallow.c b/tests/libgit2/online/shallow.c index a889a68cd..12ef7748b 100644 --- a/tests/libgit2/online/shallow.c +++ b/tests/libgit2/online/shallow.c @@ -16,7 +16,8 @@ void test_online_shallow__clone_depth_zero(void) git_str path = GIT_STR_INIT; git_repository *repo; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; - git_array_oid_t roots = GIT_ARRAY_INIT; + git_oid *roots; + size_t roots_len; clone_opts.fetch_opts.depth = 0; clone_opts.remote_cb = remote_single_branch; @@ -29,10 +30,10 @@ void test_online_shallow__clone_depth_zero(void) cl_assert_equal_b(false, git_repository_is_shallow(repo)); /* full clones do not have shallow roots. */ - cl_git_pass(git_repository__shallow_roots(&roots, repo)); - cl_assert_equal_i(0, roots.size); + cl_git_pass(git_repository__shallow_roots(&roots, &roots_len, repo)); + cl_assert_equal_i(0, roots_len); - git_array_clear(roots); + git__free(roots); git_str_dispose(&path); git_repository_free(repo); } @@ -44,7 +45,8 @@ void test_online_shallow__clone_depth_one(void) git_revwalk *walk; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_oid oid; - git_array_oid_t roots = GIT_ARRAY_INIT; + git_oid *roots; + size_t roots_len; size_t num_commits = 0; int error = 0; @@ -57,9 +59,9 @@ void test_online_shallow__clone_depth_one(void) cl_assert_equal_b(true, git_repository_is_shallow(repo)); - cl_git_pass(git_repository__shallow_roots(&roots, repo)); - cl_assert_equal_i(1, roots.size); - cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots.ptr[0])); + cl_git_pass(git_repository__shallow_roots(&roots, &roots_len, repo)); + cl_assert_equal_i(1, roots_len); + cl_assert_equal_s("49322bb17d3acc9146f98c97d078513228bbf3c0", git_oid_tostr_s(&roots[0])); git_revwalk_new(&walk, repo); @@ -72,7 +74,7 @@ void test_online_shallow__clone_depth_one(void) cl_assert_equal_i(num_commits, 1); cl_assert_equal_i(error, GIT_ITEROVER); - git_array_clear(roots); + git__free(roots); git_str_dispose(&path); git_revwalk_free(walk); git_repository_free(repo); @@ -85,7 +87,8 @@ void test_online_shallow__clone_depth_five(void) git_revwalk *walk; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_oid oid; - git_array_oid_t roots = GIT_ARRAY_INIT; + git_oid *roots; + size_t roots_len; size_t num_commits = 0; int error = 0; @@ -98,11 +101,11 @@ void test_online_shallow__clone_depth_five(void) cl_assert_equal_b(true, git_repository_is_shallow(repo)); - cl_git_pass(git_repository__shallow_roots(&roots, repo)); - cl_assert_equal_i(3, roots.size); - cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots.ptr[0])); - cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots.ptr[1])); - cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots.ptr[2])); + cl_git_pass(git_repository__shallow_roots(&roots, &roots_len, repo)); + cl_assert_equal_i(3, roots_len); + cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&roots[0])); + cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&roots[1])); + cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&roots[2])); git_revwalk_new(&walk, repo); @@ -115,7 +118,7 @@ void test_online_shallow__clone_depth_five(void) cl_assert_equal_i(num_commits, 13); cl_assert_equal_i(error, GIT_ITEROVER); - git_array_clear(roots); + git__free(roots); git_str_dispose(&path); git_revwalk_free(walk); git_repository_free(repo); diff --git a/tests/libgit2/transports/smart/shallowarray.c b/tests/libgit2/transports/smart/shallowarray.c deleted file mode 100644 index 34511c5f6..000000000 --- a/tests/libgit2/transports/smart/shallowarray.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "clar_libgit2.h" - -#include "git2/oid.h" -#include "git2/transport.h" - -#include "common.h" -#include "transports/smart.h" -#include "oid.h" - -#include - -#define oid_0 "c070ad8c08840c8116da865b2d65593a6bb9cd2a" -#define oid_1 "0966a434eb1a025db6b71485ab63a3bfbea520b6" -#define oid_2 "83834a7afdaa1a1260568567f6ad90020389f664" - -void test_transports_smart_shallowarray__add_and_remove_oid_from_shallowarray(void) -{ - git_oid oid_0_obj, oid_1_obj, oid_2_obj; - git_shallowarray *shallow_roots = git__malloc(sizeof(git_shallowarray)); - git_array_init(shallow_roots->array); - - git_oid__fromstr(&oid_0_obj, oid_0, GIT_OID_SHA1); - git_oid__fromstr(&oid_1_obj, oid_1, GIT_OID_SHA1); - git_oid__fromstr(&oid_2_obj, oid_2, GIT_OID_SHA1); - - git_shallowarray_add(shallow_roots, &oid_0_obj); - git_shallowarray_add(shallow_roots, &oid_1_obj); - git_shallowarray_add(shallow_roots, &oid_2_obj); - - cl_assert_equal_i(3, shallow_roots->array.size); - cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); - cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&shallow_roots->array.ptr[1])); - cl_assert_equal_s("83834a7afdaa1a1260568567f6ad90020389f664", git_oid_tostr_s(&shallow_roots->array.ptr[2])); - - git_shallowarray_remove(shallow_roots, &oid_2_obj); - - cl_assert_equal_i(2, shallow_roots->array.size); - cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); - cl_assert_equal_s("0966a434eb1a025db6b71485ab63a3bfbea520b6", git_oid_tostr_s(&shallow_roots->array.ptr[1])); - - git_shallowarray_remove(shallow_roots, &oid_1_obj); - - cl_assert_equal_i(1, shallow_roots->array.size); - cl_assert_equal_s("c070ad8c08840c8116da865b2d65593a6bb9cd2a", git_oid_tostr_s(&shallow_roots->array.ptr[0])); - - git_shallowarray_remove(shallow_roots, &oid_0_obj); - - cl_assert_equal_i(0, shallow_roots->array.size); - - git_array_clear(shallow_roots->array); - git__free(shallow_roots); -} -- cgit v1.2.1 From 437c5f5a0b6ae6068168081ac6422dba44cff31d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 8 May 2023 10:17:11 +0100 Subject: fetch: remove `unshallow` option The `depth` field is suitable to specify unshallowing; provide an enum to aide in specifying the `unshallow` value. --- tests/libgit2/online/shallow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/libgit2') diff --git a/tests/libgit2/online/shallow.c b/tests/libgit2/online/shallow.c index 12ef7748b..5c0e6565b 100644 --- a/tests/libgit2/online/shallow.c +++ b/tests/libgit2/online/shallow.c @@ -143,7 +143,7 @@ void test_online_shallow__unshallow(void) cl_git_pass(git_clone(&repo, "https://github.com/libgit2/TestGitRepository", git_str_cstr(&path), &clone_opts)); cl_assert_equal_b(true, git_repository_is_shallow(repo)); - fetch_opts.unshallow = 1; + fetch_opts.depth = GIT_FETCH_DEPTH_UNSHALLOW; cl_git_pass(git_remote_lookup(&origin, repo, "origin")); cl_git_pass(git_remote_fetch(origin, NULL, &fetch_opts, NULL)); -- cgit v1.2.1