diff options
Diffstat (limited to 'tests')
35 files changed, 692 insertions, 2 deletions
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 <assert.h> + +#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/grafts/basic.c b/tests/libgit2/grafts/basic.c new file mode 100644 index 000000000..30c87f908 --- /dev/null +++ b/tests/libgit2/grafts/basic.c @@ -0,0 +1,121 @@ +#include "clar_libgit2.h" + +#include "futils.h" +#include "grafts.h" + +static git_repository *g_repo; + +void test_grafts_basic__initialize(void) +{ + g_repo = cl_git_sandbox_init("grafted.git"); +} + +void test_grafts_basic__cleanup(void) +{ + 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, GIT_OID_SHA1)); + + cl_assert(oid1 = git_array_alloc(parents)); + 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_SHA1); + 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", 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", 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", 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); +} + +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..3b0618a1d --- /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, GIT_OID_SHA1)); +} + +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, 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 *), GIT_OID_SHA1)); + 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..5911a26aa --- /dev/null +++ b/tests/libgit2/grafts/shallow.c @@ -0,0 +1,134 @@ +#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__initialize(void) +{ + cl_git_pass(git_oid__fromstr(&g_shallow_oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); +} + +void test_grafts_shallow__cleanup(void) +{ + 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", GIT_OID_SHA1)); + 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); +} diff --git a/tests/libgit2/online/shallow.c b/tests/libgit2/online/shallow.c new file mode 100644 index 000000000..5c0e6565b --- /dev/null +++ b/tests/libgit2/online/shallow.c @@ -0,0 +1,166 @@ +#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_oid *roots; + size_t roots_len; + + 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, &roots_len, repo)); + cl_assert_equal_i(0, roots_len); + + git__free(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_oid *roots; + size_t roots_len; + 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, &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); + + 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__free(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_oid *roots; + size_t roots_len; + 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, &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); + + 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__free(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.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)); + 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/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)); diff --git a/tests/resources/grafted.git/HEAD b/tests/resources/grafted.git/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/tests/resources/grafted.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/resources/grafted.git/config b/tests/resources/grafted.git/config new file mode 100644 index 000000000..e6da23157 --- /dev/null +++ b/tests/resources/grafted.git/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true + ignorecase = true + precomposeunicode = true diff --git a/tests/resources/grafted.git/info/grafts b/tests/resources/grafted.git/info/grafts new file mode 100644 index 000000000..bb9df8c0a --- /dev/null +++ b/tests/resources/grafted.git/info/grafts @@ -0,0 +1,3 @@ +f503807ffa920e407a600cfaee96b7152259acc7 2f3053cbff8a4ca2f0666de364ddb734a28a31a9 +0512adebd3782157f0d5c9b22b043f87b4aaff9e 2f3053cbff8a4ca2f0666de364ddb734a28a31a9 +66cc22a015f6ca75b34c82d28f78ba663876bade e414f42f4e6bc6934563a2349a8600f0ab68618e 8a00e91619098618be97c0d2ceabb05a2c58edd9 1c18e80a276611bb9b146590616bbc5aebdf2945 2f3053cbff8a4ca2f0666de364ddb734a28a31a9 diff --git a/tests/resources/grafted.git/objects/05/12adebd3782157f0d5c9b22b043f87b4aaff9e b/tests/resources/grafted.git/objects/05/12adebd3782157f0d5c9b22b043f87b4aaff9e Binary files differnew file mode 100644 index 000000000..16880d596 --- /dev/null +++ b/tests/resources/grafted.git/objects/05/12adebd3782157f0d5c9b22b043f87b4aaff9e diff --git a/tests/resources/grafted.git/objects/1c/18e80a276611bb9b146590616bbc5aebdf2945 b/tests/resources/grafted.git/objects/1c/18e80a276611bb9b146590616bbc5aebdf2945 Binary files differnew file mode 100644 index 000000000..2c057b85d --- /dev/null +++ b/tests/resources/grafted.git/objects/1c/18e80a276611bb9b146590616bbc5aebdf2945 diff --git a/tests/resources/grafted.git/objects/1c/3f11eca55d76bc1bf7353ca7e4226246d353ed b/tests/resources/grafted.git/objects/1c/3f11eca55d76bc1bf7353ca7e4226246d353ed Binary files differnew file mode 100644 index 000000000..b92a3047f --- /dev/null +++ b/tests/resources/grafted.git/objects/1c/3f11eca55d76bc1bf7353ca7e4226246d353ed diff --git a/tests/resources/grafted.git/objects/2a/f02ebff1fc0142d2380c98758d81c67b365869 b/tests/resources/grafted.git/objects/2a/f02ebff1fc0142d2380c98758d81c67b365869 Binary files differnew file mode 100644 index 000000000..ed3f874a7 --- /dev/null +++ b/tests/resources/grafted.git/objects/2a/f02ebff1fc0142d2380c98758d81c67b365869 diff --git a/tests/resources/grafted.git/objects/2b/ecadd3f1ecad07a054392421edf9c0e1c375b2 b/tests/resources/grafted.git/objects/2b/ecadd3f1ecad07a054392421edf9c0e1c375b2 Binary files differnew file mode 100644 index 000000000..724eedbb2 --- /dev/null +++ b/tests/resources/grafted.git/objects/2b/ecadd3f1ecad07a054392421edf9c0e1c375b2 diff --git a/tests/resources/grafted.git/objects/2f/3053cbff8a4ca2f0666de364ddb734a28a31a9 b/tests/resources/grafted.git/objects/2f/3053cbff8a4ca2f0666de364ddb734a28a31a9 Binary files differnew file mode 100644 index 000000000..3d124a673 --- /dev/null +++ b/tests/resources/grafted.git/objects/2f/3053cbff8a4ca2f0666de364ddb734a28a31a9 diff --git a/tests/resources/grafted.git/objects/45/342912745ba6f8893b1e126df4653a4355df1a b/tests/resources/grafted.git/objects/45/342912745ba6f8893b1e126df4653a4355df1a Binary files differnew file mode 100644 index 000000000..4a8c471bd --- /dev/null +++ b/tests/resources/grafted.git/objects/45/342912745ba6f8893b1e126df4653a4355df1a diff --git a/tests/resources/grafted.git/objects/48/b2b333732644eafb385771a992b923fa88f135 b/tests/resources/grafted.git/objects/48/b2b333732644eafb385771a992b923fa88f135 Binary files differnew file mode 100644 index 000000000..ac640636b --- /dev/null +++ b/tests/resources/grafted.git/objects/48/b2b333732644eafb385771a992b923fa88f135 diff --git a/tests/resources/grafted.git/objects/5d/31bf4b437e1191b6c709c665f1bd329d0ed0bf b/tests/resources/grafted.git/objects/5d/31bf4b437e1191b6c709c665f1bd329d0ed0bf Binary files differnew file mode 100644 index 000000000..47a05377e --- /dev/null +++ b/tests/resources/grafted.git/objects/5d/31bf4b437e1191b6c709c665f1bd329d0ed0bf diff --git a/tests/resources/grafted.git/objects/66/cc22a015f6ca75b34c82d28f78ba663876bade b/tests/resources/grafted.git/objects/66/cc22a015f6ca75b34c82d28f78ba663876bade new file mode 100644 index 000000000..c68b2cd4f --- /dev/null +++ b/tests/resources/grafted.git/objects/66/cc22a015f6ca75b34c82d28f78ba663876bade @@ -0,0 +1,2 @@ +xM +0F]$Dx=4N4Fϯ#x|260dvmap1a}NhL!E&}BTO^dn )$~ꖜl,=bF|:W{myrYuN~t/<N]ڡEHkأATi䯈Ho<N>ѫM,
\ No newline at end of file diff --git a/tests/resources/grafted.git/objects/6c/f192eb71cd3243c9fbbe2551012c4449de3fcf b/tests/resources/grafted.git/objects/6c/f192eb71cd3243c9fbbe2551012c4449de3fcf Binary files differnew file mode 100644 index 000000000..a437f2432 --- /dev/null +++ b/tests/resources/grafted.git/objects/6c/f192eb71cd3243c9fbbe2551012c4449de3fcf diff --git a/tests/resources/grafted.git/objects/7c/9da502b2744b70522bb694cd607fb00104a233 b/tests/resources/grafted.git/objects/7c/9da502b2744b70522bb694cd607fb00104a233 Binary files differnew file mode 100644 index 000000000..b363584fd --- /dev/null +++ b/tests/resources/grafted.git/objects/7c/9da502b2744b70522bb694cd607fb00104a233 diff --git a/tests/resources/grafted.git/objects/8a/00e91619098618be97c0d2ceabb05a2c58edd9 b/tests/resources/grafted.git/objects/8a/00e91619098618be97c0d2ceabb05a2c58edd9 new file mode 100644 index 000000000..887778a60 --- /dev/null +++ b/tests/resources/grafted.git/objects/8a/00e91619098618be97c0d2ceabb05a2c58edd9 @@ -0,0 +1,2 @@ +xA +0E]t4Dt <$@J#ч@B5@b$'[ig&V/^6H ]J<AbH,2ȎSne{R˶T8ovשp|d~_u1 RŨߚNC
\ No newline at end of file diff --git a/tests/resources/grafted.git/objects/a0/4de168dd5c43aa2af594d794d62e922f8b3b34 b/tests/resources/grafted.git/objects/a0/4de168dd5c43aa2af594d794d62e922f8b3b34 Binary files differnew file mode 100644 index 000000000..1ed3ed906 --- /dev/null +++ b/tests/resources/grafted.git/objects/a0/4de168dd5c43aa2af594d794d62e922f8b3b34 diff --git a/tests/resources/grafted.git/objects/b2/b4f9e5fe5dacbb2f98bd71d1dc86c7b571ddd1 b/tests/resources/grafted.git/objects/b2/b4f9e5fe5dacbb2f98bd71d1dc86c7b571ddd1 Binary files differnew file mode 100644 index 000000000..2adc85721 --- /dev/null +++ b/tests/resources/grafted.git/objects/b2/b4f9e5fe5dacbb2f98bd71d1dc86c7b571ddd1 diff --git a/tests/resources/grafted.git/objects/ba/54010f8d41532eb130eba420f50248881f7fc2 b/tests/resources/grafted.git/objects/ba/54010f8d41532eb130eba420f50248881f7fc2 Binary files differnew file mode 100644 index 000000000..52a887274 --- /dev/null +++ b/tests/resources/grafted.git/objects/ba/54010f8d41532eb130eba420f50248881f7fc2 diff --git a/tests/resources/grafted.git/objects/d7/224d49d6d5aff6ade596ed74f4bcd4f77b29e2 b/tests/resources/grafted.git/objects/d7/224d49d6d5aff6ade596ed74f4bcd4f77b29e2 new file mode 100644 index 000000000..5b41b6778 --- /dev/null +++ b/tests/resources/grafted.git/objects/d7/224d49d6d5aff6ade596ed74f4bcd4f77b29e2 @@ -0,0 +1,2 @@ +xA +0E]dҐDx=$hI_Gp/Ԁ,"%p&/1ތԓƀq֓z"ZMG%6co|Ϝ(^8IJr^kú|e.|mѠuH*lW%Q%YZڧbUoaRj
\ No newline at end of file diff --git a/tests/resources/grafted.git/objects/db/8e43f297a313c439530c977b733aaa8c10d54e b/tests/resources/grafted.git/objects/db/8e43f297a313c439530c977b733aaa8c10d54e Binary files differnew file mode 100644 index 000000000..b9cf5947b --- /dev/null +++ b/tests/resources/grafted.git/objects/db/8e43f297a313c439530c977b733aaa8c10d54e diff --git a/tests/resources/grafted.git/objects/e4/14f42f4e6bc6934563a2349a8600f0ab68618e b/tests/resources/grafted.git/objects/e4/14f42f4e6bc6934563a2349a8600f0ab68618e Binary files differnew file mode 100644 index 000000000..1a14959c4 --- /dev/null +++ b/tests/resources/grafted.git/objects/e4/14f42f4e6bc6934563a2349a8600f0ab68618e diff --git a/tests/resources/grafted.git/objects/e6/7b587a57850c69f6f9351ee10c7c8a41dacc78 b/tests/resources/grafted.git/objects/e6/7b587a57850c69f6f9351ee10c7c8a41dacc78 Binary files differnew file mode 100644 index 000000000..213f9ac22 --- /dev/null +++ b/tests/resources/grafted.git/objects/e6/7b587a57850c69f6f9351ee10c7c8a41dacc78 diff --git a/tests/resources/grafted.git/objects/f0/7330bc2e4ed4bd0bf2301505f6c6bbad01aa2a b/tests/resources/grafted.git/objects/f0/7330bc2e4ed4bd0bf2301505f6c6bbad01aa2a Binary files differnew file mode 100644 index 000000000..f2d648892 --- /dev/null +++ b/tests/resources/grafted.git/objects/f0/7330bc2e4ed4bd0bf2301505f6c6bbad01aa2a diff --git a/tests/resources/grafted.git/objects/f5/03807ffa920e407a600cfaee96b7152259acc7 b/tests/resources/grafted.git/objects/f5/03807ffa920e407a600cfaee96b7152259acc7 new file mode 100644 index 000000000..21436c177 --- /dev/null +++ b/tests/resources/grafted.git/objects/f5/03807ffa920e407a600cfaee96b7152259acc7 @@ -0,0 +1,2 @@ +xA +0E]J&6) @@#xZ)z{D/ɋMb9P&yyBF&7헙Qw
=KPV;Oߖ:P+3Ə6Z+:Qw\Hy>zA
\ No newline at end of file diff --git a/tests/resources/grafted.git/refs/heads/bottom b/tests/resources/grafted.git/refs/heads/bottom new file mode 100644 index 000000000..10513e698 --- /dev/null +++ b/tests/resources/grafted.git/refs/heads/bottom @@ -0,0 +1 @@ +66cc22a015f6ca75b34c82d28f78ba663876bade diff --git a/tests/resources/grafted.git/refs/heads/branch b/tests/resources/grafted.git/refs/heads/branch new file mode 100644 index 000000000..d0fe5c283 --- /dev/null +++ b/tests/resources/grafted.git/refs/heads/branch @@ -0,0 +1 @@ +8a00e91619098618be97c0d2ceabb05a2c58edd9 diff --git a/tests/resources/grafted.git/refs/heads/master b/tests/resources/grafted.git/refs/heads/master new file mode 100644 index 000000000..de809b942 --- /dev/null +++ b/tests/resources/grafted.git/refs/heads/master @@ -0,0 +1 @@ +2f3053cbff8a4ca2f0666de364ddb734a28a31a9 diff --git a/tests/resources/grafted.git/refs/heads/top b/tests/resources/grafted.git/refs/heads/top new file mode 100644 index 000000000..ce226110b --- /dev/null +++ b/tests/resources/grafted.git/refs/heads/top @@ -0,0 +1 @@ +1c18e80a276611bb9b146590616bbc5aebdf2945 |