diff options
author | Vicent Martà <vicent@github.com> | 2012-12-05 11:47:19 -0800 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-12-05 11:47:19 -0800 |
commit | e05ca13f1f3550f59790c0f992841abceee1b4c5 (patch) | |
tree | a01c119011d0c6020c9288096d09ed055c475bd8 /tests-clar | |
parent | a541eafa606b58e7ce3df8e496da8e032fdb74ec (diff) | |
parent | ee1c33b146a366260a4648b1f29f470fedaca0fa (diff) | |
download | libgit2-e05ca13f1f3550f59790c0f992841abceee1b4c5.tar.gz |
Merge pull request #1115 from ben/struct-versions
Version info for public structs
Diffstat (limited to 'tests-clar')
-rw-r--r-- | tests-clar/checkout/index.c | 22 | ||||
-rw-r--r-- | tests-clar/checkout/tree.c | 2 | ||||
-rw-r--r-- | tests-clar/checkout/typechange.c | 2 | ||||
-rw-r--r-- | tests-clar/commit/parse.c | 4 | ||||
-rw-r--r-- | tests-clar/config/backend.c | 20 | ||||
-rw-r--r-- | tests-clar/diff/blob.c | 24 | ||||
-rw-r--r-- | tests-clar/diff/diff_helpers.h | 1 | ||||
-rw-r--r-- | tests-clar/diff/diffiter.c | 30 | ||||
-rw-r--r-- | tests-clar/diff/index.c | 25 | ||||
-rw-r--r-- | tests-clar/diff/rename.c | 38 | ||||
-rw-r--r-- | tests-clar/diff/tree.c | 34 | ||||
-rw-r--r-- | tests-clar/diff/workdir.c | 38 | ||||
-rw-r--r-- | tests-clar/network/fetch.c | 4 | ||||
-rw-r--r-- | tests-clar/network/push_util.h | 3 | ||||
-rw-r--r-- | tests-clar/network/remotes.c | 20 | ||||
-rw-r--r-- | tests-clar/odb/sorting.c | 4 | ||||
-rw-r--r-- | tests-clar/refs/branches/tracking.c | 3 | ||||
-rw-r--r-- | tests-clar/repo/init.c | 9 | ||||
-rw-r--r-- | tests-clar/status/ignore.c | 8 | ||||
-rw-r--r-- | tests-clar/status/worktree.c | 12 |
20 files changed, 246 insertions, 57 deletions
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c index b6d637223..a67765b26 100644 --- a/tests-clar/checkout/index.c +++ b/tests-clar/checkout/index.c @@ -25,7 +25,7 @@ void test_checkout_index__initialize(void) { git_tree *tree; - memset(&g_opts, 0, sizeof(g_opts)); + GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION); g_opts.checkout_strategy = GIT_CHECKOUT_SAFE; g_repo = cl_git_sandbox_init("testrepo"); @@ -66,7 +66,7 @@ void test_checkout_index__cannot_checkout_a_bare_repository(void) { test_checkout_index__cleanup(); - memset(&g_opts, 0, sizeof(g_opts)); + GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION); g_repo = cl_git_sandbox_init("testrepo.git"); cl_git_fail(git_checkout_index(g_repo, NULL, NULL)); @@ -426,3 +426,21 @@ void test_checkout_index__can_overcome_name_clashes(void) git_index_free(index); } + +void test_checkout_index__validates_struct_version(void) +{ + const git_error *err; + + g_opts.version = 1024; + cl_git_fail(git_checkout_index(g_repo, NULL, &g_opts)); + + err = giterr_last(); + cl_assert_equal_i(err->klass, GITERR_INVALID); + + g_opts.version = 0; + giterr_clear(); + cl_git_fail(git_checkout_index(g_repo, NULL, &g_opts)); + + err = giterr_last(); + cl_assert_equal_i(err->klass, GITERR_INVALID); +} diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c index 534c46086..88dbe4ffc 100644 --- a/tests-clar/checkout/tree.c +++ b/tests-clar/checkout/tree.c @@ -11,7 +11,7 @@ void test_checkout_tree__initialize(void) { g_repo = cl_git_sandbox_init("testrepo"); - memset(&g_opts, 0, sizeof(g_opts)); + GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION); g_opts.checkout_strategy = GIT_CHECKOUT_SAFE; } diff --git a/tests-clar/checkout/typechange.c b/tests-clar/checkout/typechange.c index cd34885de..98c15bcb7 100644 --- a/tests-clar/checkout/typechange.c +++ b/tests-clar/checkout/typechange.c @@ -38,7 +38,7 @@ void test_checkout_typechange__checkout_typechanges(void) { int i; git_object *obj; - git_checkout_opts opts = {0}; + git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; opts.checkout_strategy = GIT_CHECKOUT_FORCE; diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c index bbb502cb5..8075f2619 100644 --- a/tests-clar/commit/parse.c +++ b/tests-clar/commit/parse.c @@ -149,7 +149,7 @@ void test_commit_parse__signature(void) { const char *str = passcase->string; size_t len = strlen(passcase->string); - struct git_signature person = {NULL, NULL, {0, 0}}; + struct git_signature person = {0}; cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n')); cl_assert(strcmp(passcase->name, person.name) == 0); cl_assert(strcmp(passcase->email, person.email) == 0); @@ -162,7 +162,7 @@ void test_commit_parse__signature(void) { const char *str = failcase->string; size_t len = strlen(failcase->string); - git_signature person = {NULL, NULL, {0, 0}}; + git_signature person = {0}; cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n')); git__free(person.name); git__free(person.email); } diff --git a/tests-clar/config/backend.c b/tests-clar/config/backend.c new file mode 100644 index 000000000..1cf770263 --- /dev/null +++ b/tests-clar/config/backend.c @@ -0,0 +1,20 @@ +#include "clar_libgit2.h" + +void test_config_backend__checks_version(void) +{ + git_config *cfg; + git_config_backend backend = GIT_CONFIG_BACKEND_INIT; + backend.version = 1024; + const git_error *err; + + cl_git_pass(git_config_new(&cfg)); + cl_git_fail(git_config_add_backend(cfg, &backend, 0, false)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + backend.version = 1024; + cl_git_fail(git_config_add_backend(cfg, &backend, 0, false)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c index 6a5645d4b..d7fdba0e6 100644 --- a/tests-clar/diff/blob.c +++ b/tests-clar/diff/blob.c @@ -12,7 +12,7 @@ void test_diff_blob__initialize(void) g_repo = cl_git_sandbox_init("attr"); - memset(&opts, 0, sizeof(opts)); + GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION); opts.context_lines = 1; opts.interhunk_lines = 0; @@ -313,3 +313,25 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void) git_blob_free(old_d); } + +void test_diff_blob__checks_options_version_too_low(void) +{ + const git_error *err; + + opts.version = 0; + cl_git_fail(git_diff_blobs( + d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} + +void test_diff_blob__checks_options_version_too_high(void) +{ + const git_error *err; + + opts.version = 1024; + cl_git_fail(git_diff_blobs( + d, alien, &opts, diff_file_cb, diff_hunk_cb, diff_line_cb, &expected)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h index 12591f63e..49c265285 100644 --- a/tests-clar/diff/diff_helpers.h +++ b/tests-clar/diff/diff_helpers.h @@ -48,3 +48,4 @@ extern int diff_foreach_via_iterator( void *data); extern void diff_print(FILE *fp, git_diff_list *diff); + diff --git a/tests-clar/diff/diffiter.c b/tests-clar/diff/diffiter.c index 133392c21..306a13eb9 100644 --- a/tests-clar/diff/diffiter.c +++ b/tests-clar/diff/diffiter.c @@ -76,7 +76,7 @@ void test_diff_diffiter__iterate_files_2(void) void test_diff_diffiter__iterate_files_and_hunks(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; size_t d, num_d; int file_count = 0, hunk_count = 0; @@ -129,7 +129,7 @@ void test_diff_diffiter__iterate_files_and_hunks(void) void test_diff_diffiter__max_size_threshold(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; int file_count = 0, binary_count = 0, hunk_count = 0; size_t d, num_d; @@ -207,7 +207,7 @@ void test_diff_diffiter__max_size_threshold(void) void test_diff_diffiter__iterate_all(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp = {0}; size_t d, num_d; @@ -280,7 +280,7 @@ static void iterate_over_patch(git_diff_patch *patch, diff_expects *exp) void test_diff_diffiter__iterate_randomly_while_saving_state(void) { git_repository *repo = cl_git_sandbox_init("status"); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp = {0}; git_diff_patch *patches[PATCH_CACHE]; @@ -441,3 +441,25 @@ void test_diff_diffiter__iterate_and_generate_patch_text(void) git_diff_list_free(diff); } + +void test_diff_diffiter__checks_options_version(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff_list *diff = NULL; + const git_error *err; + + opts.version = 0; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED; + + cl_git_fail(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + opts.version = 1024; + cl_git_fail(git_diff_workdir_to_index(&diff, repo, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} + diff --git a/tests-clar/diff/index.c b/tests-clar/diff/index.c index 9591e3457..267b3291c 100644 --- a/tests-clar/diff/index.c +++ b/tests-clar/diff/index.c @@ -20,7 +20,7 @@ void test_diff_index__0(void) const char *b_commit = "0017bd4ab1ec3"; /* the start */ git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit); git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; @@ -113,7 +113,7 @@ void test_diff_index__1(void) const char *b_commit = "0017bd4ab1ec3"; /* the start */ git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit); git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit); - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; @@ -140,3 +140,24 @@ void test_diff_index__1(void) git_tree_free(a); git_tree_free(b); } + +void test_diff_index__checks_options_version(void) +{ + const char *a_commit = "26a125ee1bf"; + git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit); + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff_list *diff; + const git_error *err; + + opts.version = 0; + cl_git_fail(git_diff_index_to_tree(&diff, g_repo, a, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + opts.version = 1024; + cl_git_fail(git_diff_index_to_tree(&diff, g_repo, a, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} + diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c index 0d57f8ff0..2995b4ef5 100644 --- a/tests-clar/diff/rename.c +++ b/tests-clar/diff/rename.c @@ -33,8 +33,8 @@ void test_diff_rename__match_oid(void) const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a"; git_tree *old_tree, *new_tree; git_diff_list *diff; - git_diff_options diffopts = {0}; - git_diff_find_options opts; + git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; + git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; diff_expects exp; old_tree = resolve_commit_oid_to_tree(g_repo, old_sha); @@ -43,7 +43,6 @@ void test_diff_rename__match_oid(void) /* Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate * --find-copies-harder during rename transformion... */ - memset(&diffopts, 0, sizeof(diffopts)); diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED; cl_git_pass(git_diff_tree_to_tree( @@ -85,7 +84,6 @@ void test_diff_rename__match_oid(void) * 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \ * 2bc7f351d20b53f1c72c16c4b036e491c478c49a */ - memset(&opts, 0, sizeof(opts)); opts.flags = GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED; cl_git_pass(git_diff_find_similar(diff, &opts)); @@ -103,3 +101,35 @@ void test_diff_rename__match_oid(void) git_tree_free(old_tree); git_tree_free(new_tree); } + +void test_diff_rename__checks_options_version(void) +{ + const char *old_sha = "31e47d8c1fa36d7f8d537b96158e3f024de0a9f2"; + const char *new_sha = "2bc7f351d20b53f1c72c16c4b036e491c478c49a"; + git_tree *old_tree, *new_tree; + git_diff_list *diff; + git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; + git_diff_find_options opts = GIT_DIFF_FIND_OPTIONS_INIT; + const git_error *err; + + old_tree = resolve_commit_oid_to_tree(g_repo, old_sha); + new_tree = resolve_commit_oid_to_tree(g_repo, new_sha); + diffopts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED; + cl_git_pass(git_diff_tree_to_tree( + &diff, g_repo, old_tree, new_tree, &diffopts)); + + opts.version = 0; + cl_git_fail(git_diff_find_similar(diff, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + opts.version = 1024; + cl_git_fail(git_diff_find_similar(diff, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + git_diff_list_free(diff); + git_tree_free(old_tree); + git_tree_free(new_tree); +} diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index 58dc4e6fa..442e53b25 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -19,7 +19,7 @@ void test_diff_tree__0(void) const char *b_commit = "370fe9ec22"; const char *c_commit = "f5b0af1fb4f5c"; git_tree *a, *b, *c; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; @@ -175,7 +175,7 @@ void test_diff_tree__bare(void) const char *a_commit = "8496071c1b46c85"; const char *b_commit = "be3563ae3f79"; git_tree *a, *b; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; @@ -264,7 +264,7 @@ void test_diff_tree__larger_hunks(void) const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69"; const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; git_tree *a, *b; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; size_t d, num_d, h, num_h, l, num_l, header_len, line_len; const git_diff_delta *delta; @@ -319,3 +319,31 @@ void test_diff_tree__larger_hunks(void) git_tree_free(a); git_tree_free(b); } + +void test_diff_tree__checks_options_version(void) +{ + const char *a_commit = "8496071c1b46c85"; + const char *b_commit = "be3563ae3f79"; + git_tree *a, *b; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff_list *diff = NULL; + const git_error *err; + + g_repo = cl_git_sandbox_init("testrepo.git"); + + cl_assert((a = resolve_commit_oid_to_tree(g_repo, a_commit)) != NULL); + cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL); + + opts.version = 0; + cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + opts.version = 1024; + cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); + err = giterr_last(); + + git_tree_free(a); + git_tree_free(b); +} diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c index 57c88c3e5..10d58b118 100644 --- a/tests-clar/diff/workdir.c +++ b/tests-clar/diff/workdir.c @@ -15,7 +15,7 @@ void test_diff_workdir__cleanup(void) void test_diff_workdir__to_index(void) { - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; int use_iterator; @@ -69,7 +69,7 @@ void test_diff_workdir__to_tree(void) const char *a_commit = "26a125ee1bf"; /* the current HEAD */ const char *b_commit = "0017bd4ab1ec3"; /* the start */ git_tree *a, *b; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; git_diff_list *diff2 = NULL; diff_expects exp; @@ -202,7 +202,7 @@ void test_diff_workdir__to_tree(void) void test_diff_workdir__to_index_with_pathspec(void) { - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; char *pathspec = NULL; @@ -420,7 +420,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) void test_diff_workdir__head_index_and_workdir_all_differ(void) { - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff_i2t = NULL, *diff_w2i = NULL; diff_expects exp; char *pathspec = "staged_changes_modified_file"; @@ -518,7 +518,7 @@ void test_diff_workdir__head_index_and_workdir_all_differ(void) void test_diff_workdir__eof_newline_changes(void) { - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; char *pathspec = "current_file"; @@ -678,7 +678,7 @@ void test_diff_workdir__larger_hunks(void) const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69"; const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; git_tree *a, *b; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; size_t i, d, num_d, h, num_h, l, num_l, header_len, line_len; g_repo = cl_git_sandbox_init("diff"); @@ -763,7 +763,7 @@ void test_diff_workdir__submodules(void) { const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698"; git_tree *a; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; diff_expects exp; @@ -822,7 +822,7 @@ void test_diff_workdir__submodules(void) void test_diff_workdir__cannot_diff_against_a_bare_repository(void) { - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff_list *diff = NULL; git_tree *tree; @@ -843,7 +843,7 @@ void test_diff_workdir__to_null_tree(void) { git_diff_list *diff; diff_expects exp; - git_diff_options opts = {0}; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; opts.flags = GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_RECURSE_UNTRACKED_DIRS; @@ -861,3 +861,23 @@ void test_diff_workdir__to_null_tree(void) git_diff_list_free(diff); } + +void test_diff_workdir__checks_options_version(void) +{ + git_diff_list *diff; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + const git_error *err; + + g_repo = cl_git_sandbox_init("status"); + + opts.version = 0; + cl_git_fail(git_diff_workdir_to_tree(&diff, g_repo, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + opts.version = 1024; + cl_git_fail(git_diff_workdir_to_tree(&diff, g_repo, NULL, &opts)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c index 623352fa5..33c229316 100644 --- a/tests-clar/network/fetch.c +++ b/tests-clar/network/fetch.c @@ -36,10 +36,9 @@ static void progress(const git_transfer_progress *stats, void *payload) static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n) { git_remote *remote; - git_remote_callbacks callbacks; + git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; size_t bytes_received = 0; - memset(&callbacks, 0, sizeof(git_remote_callbacks)); callbacks.update_tips = update_tips; counter = 0; @@ -78,6 +77,7 @@ void test_network_fetch__no_tags_http(void) static void transferProgressCallback(const git_transfer_progress *stats, void *payload) { + GIT_UNUSED(stats); bool *invoked = (bool *)payload; GIT_UNUSED(stats); diff --git a/tests-clar/network/push_util.h b/tests-clar/network/push_util.h index 2f4dffce4..759122aa6 100644 --- a/tests-clar/network/push_util.h +++ b/tests-clar/network/push_util.h @@ -11,7 +11,8 @@ extern const git_oid OID_ZERO; * record data in a record_callbacks_data instance. * @param data pointer to a record_callbacks_data instance */ -#define RECORD_CALLBACKS_INIT(data) { NULL, NULL, record_update_tips_cb, data } +#define RECORD_CALLBACKS_INIT(data) \ + { GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, record_update_tips_cb, data } typedef struct { char *name; diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c index b4a3ad99d..70df001e7 100644 --- a/tests-clar/network/remotes.c +++ b/tests-clar/network/remotes.c @@ -306,3 +306,23 @@ void test_network_remotes__cannot_load_with_an_empty_url(void) cl_git_fail(git_remote_load(&remote, _repo, "empty-remote-url")); cl_assert(giterr_last()->klass == GITERR_INVALID); } + +void test_network_remotes__check_structure_version(void) +{ + git_transport transport = GIT_TRANSPORT_INIT; + const git_error *err; + + git_remote_free(_remote); + cl_git_pass(git_remote_new(&_remote, _repo, NULL, "test-protocol://localhost", NULL)); + + transport.version = 0; + cl_git_fail(git_remote_set_transport(_remote, &transport)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); + + giterr_clear(); + transport.version = 1024; + cl_git_fail(git_remote_set_transport(_remote, &transport)); + err = giterr_last(); + cl_assert_equal_i(GITERR_INVALID, err->klass); +} diff --git a/tests-clar/odb/sorting.c b/tests-clar/odb/sorting.c index bf64f6af4..b4f9e44bc 100644 --- a/tests-clar/odb/sorting.c +++ b/tests-clar/odb/sorting.c @@ -11,11 +11,11 @@ static git_odb_backend *new_backend(int position) { fake_backend *b; - b = git__malloc(sizeof(fake_backend)); + b = git__calloc(1, sizeof(fake_backend)); if (b == NULL) return NULL; - memset(b, 0x0, sizeof(fake_backend)); + b->base.version = GIT_ODB_BACKEND_VERSION; b->position = position; return (git_odb_backend *)b; } diff --git a/tests-clar/refs/branches/tracking.c b/tests-clar/refs/branches/tracking.c index 7af5f974f..bc41e0633 100644 --- a/tests-clar/refs/branches/tracking.c +++ b/tests-clar/refs/branches/tracking.c @@ -65,7 +65,8 @@ static void assert_merge_and_or_remote_key_missing(git_repository *repository, c { git_reference *branch; - cl_git_pass(git_branch_create(&branch, repository, entry_name, target, 0)); + cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type(target)); + cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0)); cl_assert_equal_i(GIT_ENOTFOUND, git_branch_tracking(&tracking, branch)); diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c index 3b14c97f2..c0acbed5a 100644 --- a/tests-clar/repo/init.c +++ b/tests-clar/repo/init.c @@ -304,8 +304,7 @@ void test_repo_init__sets_logAllRefUpdates_according_to_type_of_repository(void) void test_repo_init__extended_0(void) { - git_repository_init_options opts; - memset(&opts, 0, sizeof(opts)); + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; /* without MKDIR this should fail */ cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts)); @@ -327,8 +326,7 @@ void test_repo_init__extended_1(void) git_reference *ref; git_remote *remote; struct stat st; - git_repository_init_options opts; - memset(&opts, 0, sizeof(opts)); + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_NO_DOTGIT_DIR; @@ -367,8 +365,7 @@ void test_repo_init__extended_1(void) void test_repo_init__extended_with_template(void) { - git_repository_init_options opts; - memset(&opts, 0, sizeof(opts)); + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE; opts.template_path = cl_fixture("template"); diff --git a/tests-clar/status/ignore.c b/tests-clar/status/ignore.c index 27f9d85b9..e2e4aaf18 100644 --- a/tests-clar/status/ignore.c +++ b/tests-clar/status/ignore.c @@ -180,9 +180,6 @@ void test_status_ignore__subdirectories(void) { status_entry_single st; int ignored; - git_status_options opts; - - GIT_UNUSED(opts); g_repo = cl_git_sandbox_init("empty_standard_repo"); @@ -216,11 +213,6 @@ void test_status_ignore__subdirectories(void) cl_git_mkfile( "empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!"); - opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; - opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED | - GIT_STATUS_OPT_INCLUDE_UNTRACKED | - GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; - memset(&st, 0, sizeof(st)); cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st)); cl_assert_equal_i(2, st.count); diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index 7ae1883b9..a1f7f8684 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -111,7 +111,7 @@ void test_status_worktree__swap_subdir_and_file(void) status_entry_counts counts; git_repository *repo = cl_git_sandbox_init("status"); git_index *index; - git_status_options opts; + git_status_options opts = GIT_STATUS_OPTIONS_INIT; bool ignore_case; cl_git_pass(git_repository_index(&index, repo)); @@ -133,7 +133,6 @@ void test_status_worktree__swap_subdir_and_file(void) counts.expected_paths = ignore_case ? entry_paths3_icase : entry_paths3; counts.expected_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3; - memset(&opts, 0, sizeof(opts)); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED; @@ -150,7 +149,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void) { status_entry_counts counts; git_repository *repo = cl_git_sandbox_init("status"); - git_status_options opts; + git_status_options opts = GIT_STATUS_OPTIONS_INIT; /* first alter the contents of the worktree */ cl_git_pass(p_rename("status/current_file", "status/swap")); @@ -167,7 +166,6 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void) counts.expected_paths = entry_paths4; counts.expected_statuses = entry_statuses4; - memset(&opts, 0, sizeof(opts)); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; /* TODO: set pathspec to "current_file" eventually */ @@ -691,7 +689,7 @@ void test_status_worktree__filemode_changes(void) { git_repository *repo = cl_git_sandbox_init("filemodes"); status_entry_counts counts; - git_status_options opts; + git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_config *cfg; /* overwrite stored filemode with platform appropriate value */ @@ -708,7 +706,6 @@ void test_status_worktree__filemode_changes(void) filemode_statuses[i] = GIT_STATUS_CURRENT; } - memset(&opts, 0, sizeof(opts)); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED; @@ -746,7 +743,7 @@ static int cb_status__expected_path(const char *p, unsigned int s, void *payload void test_status_worktree__disable_pathspec_match(void) { git_repository *repo; - git_status_options opts; + git_status_options opts = GIT_STATUS_OPTIONS_INIT; char *file_with_bracket = "LICENSE[1].md", *imaginary_file_with_bracket = "LICENSE[1-2].md"; @@ -754,7 +751,6 @@ void test_status_worktree__disable_pathspec_match(void) cl_git_mkfile("pathspec/LICENSE[1].md", "screaming bracket\n"); cl_git_mkfile("pathspec/LICENSE1.md", "no bracket\n"); - memset(&opts, 0, sizeof(opts)); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; opts.pathspec.count = 1; |