Add cl_repo_set_bool and cleanup tests This adds a helper function for the cases where you want to quickly set a single boolean config value for a repository. This allowed me to remove a lot of code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
diff --git a/tests-clar/checkout/binaryunicode.c b/tests-clar/checkout/binaryunicode.c
index 5a78174..14ab9fd 100644
--- a/tests-clar/checkout/binaryunicode.c
+++ b/tests-clar/checkout/binaryunicode.c
@@ -47,22 +47,12 @@ static void execute_test(void)
void test_checkout_binaryunicode__noautocrlf(void)
{
- git_config *config;
-
- cl_git_pass(git_repository_config(&config, g_repo));
- cl_git_pass(git_config_set_bool(config, "core.autocrlf", false));
- git_config_free(config);
-
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
execute_test();
}
void test_checkout_binaryunicode__autocrlf(void)
{
- git_config *config;
-
- cl_git_pass(git_repository_config(&config, g_repo));
- cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
- git_config_free(config);
-
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
execute_test();
}
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
index 38c0080..74da276 100644
--- a/tests-clar/checkout/crlf.c
+++ b/tests-clar/checkout/crlf.c
@@ -24,30 +24,13 @@ void test_checkout_crlf__cleanup(void)
cl_git_sandbox_cleanup();
}
-#ifdef GIT_WIN32
-static void set_config_entry_to(const char *entry_name, bool value)
-{
- git_config *cfg;
-
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, entry_name, value));
-
- git_config_free(cfg);
-}
-
-static void set_core_autocrlf_to(bool value)
-{
- set_config_entry_to("core.autocrlf", value);
-}
-#endif
-
void test_checkout_crlf__detect_crlf_autocrlf_false(void)
{
#ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- set_core_autocrlf_to(false);
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
git_checkout_head(g_repo, &opts);
@@ -63,7 +46,7 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- set_core_autocrlf_to(false);
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
git_checkout_head(g_repo, &opts);
@@ -82,7 +65,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
git_checkout_head(g_repo, &opts);
@@ -98,7 +81,7 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
git_checkout_head(g_repo, &opts);
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index e8a61ca..3976dd2 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -92,21 +92,6 @@ void test_checkout_index__honor_the_specified_pathspecs(void)
test_file_contents("./testrepo/new.txt", "my new file\n");
}
-static void set_config_entry_to(const char *entry_name, bool value)
-{
- git_config *cfg;
-
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, entry_name, value));
-
- git_config_free(cfg);
-}
-
-static void set_core_autocrlf_to(bool value)
-{
- set_config_entry_to("core.autocrlf", value);
-}
-
void test_checkout_index__honor_the_gitattributes_directives(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
@@ -115,7 +100,7 @@ void test_checkout_index__honor_the_gitattributes_directives(void)
"new.txt text eol=lf\n";
cl_git_mkfile("./testrepo/.gitattributes", attributes);
- set_core_autocrlf_to(false);
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -133,7 +118,7 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
const char *expected_readme_text = "hey there\r\n";
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -143,16 +128,11 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
#endif
}
-static void set_repo_symlink_handling_cap_to(bool value)
-{
- set_config_entry_to("core.symlinks", value);
-}
-
void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- set_repo_symlink_handling_cap_to(true);
+ cl_repo_set_bool(g_repo, "core.symlinks", true);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -178,7 +158,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- set_repo_symlink_handling_cap_to(false);
+ cl_repo_set_bool(g_repo, "core.symlinks", false);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -372,7 +352,7 @@ void test_checkout_index__wont_notify_of_expected_line_ending_changes(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
cl_git_mkfile("./testrepo/new.txt", "my new file\r\n");
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index 348be51..8309cd7 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -452,32 +452,31 @@ void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
git_oid tree_id, commit_id;
git_tree *tree = NULL;
git_commit *commit = NULL;
-
+
git_repository_index(&index, g_repo);
-
+
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
-
+
cl_git_pass(git_reference_name_to_id(&commit_id, g_repo, "refs/heads/master"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
-
+
cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
-
-
+
cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777));
cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n");
-
+
cl_git_pass(git_index_add_bypath(index, "this-is-dir/contained_file"));
git_index_write_tree(&tree_id, index);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
-
+
cl_git_pass(p_unlink("./testrepo/this-is-dir/contained_file"));
-
+
opts.checkout_strategy = GIT_CHECKOUT_SAFE;
-
+
opts.checkout_strategy = 1;
git_checkout_tree(g_repo, (git_object *)tree, &opts);
-
+
git_tree_free(tree);
git_commit_free(commit);
git_index_free(index);
diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c
index 8033cdc..68d1716 100644
--- a/tests-clar/clar_libgit2.c
+++ b/tests-clar/clar_libgit2.c
@@ -323,3 +323,11 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
return error;
}
+
+void cl_repo_set_bool(git_repository *repo, const char *cfg, int value)
+{
+ git_config *config;
+ cl_git_pass(git_repository_config(&config, repo));
+ cl_git_pass(git_config_set_bool(config, cfg, value != 0));
+ git_config_free(config);
+}
diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h
index 667b805..93909d8 100644
--- a/tests-clar/clar_libgit2.h
+++ b/tests-clar/clar_libgit2.h
@@ -68,4 +68,7 @@ const char* cl_git_path_url(const char *path);
/* Test repository cleaner */
int cl_git_remove_placeholders(const char *directory_path, const char *filename);
+/* config setting helpers */
+void cl_repo_set_bool(git_repository *repo, const char *cfg, int value);
+
#endif
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 983465b..1ac5631 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -472,7 +472,6 @@ void test_diff_workdir__to_index_notify_can_be_used_as_filtering_function(void)
void test_diff_workdir__filemode_changes(void)
{
- git_config *cfg;
git_diff_list *diff = NULL;
diff_expects exp;
int use_iterator;
@@ -482,8 +481,7 @@ void test_diff_workdir__filemode_changes(void)
g_repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, "core.filemode", true));
+ cl_repo_set_bool(g_repo, "core.filemode", true);
/* test once with no mods */
@@ -530,12 +528,10 @@ void test_diff_workdir__filemode_changes(void)
git_diff_list_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
- git_config_free(cfg);
}
void test_diff_workdir__filemode_changes_with_filemode_false(void)
{
- git_config *cfg;
git_diff_list *diff = NULL;
diff_expects exp;
@@ -544,8 +540,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
g_repo = cl_git_sandbox_init("issue_592");
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, "core.filemode", false));
+ cl_repo_set_bool(g_repo, "core.filemode", false);
/* test once with no mods */
@@ -578,7 +573,6 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
git_diff_list_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt"));
- git_config_free(cfg);
}
void test_diff_workdir__head_index_and_workdir_all_differ(void)
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index 1bb4417..e56a9c0 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -66,13 +66,10 @@ static void add_and_check_mode(
void test_index_filemodes__untrusted(void)
{
- git_config *cfg;
git_index *index;
bool can_filemode = cl_is_chmod_supported();
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, "core.filemode", false));
- git_config_free(cfg);
+ cl_repo_set_bool(g_repo, "core.filemode", false);
cl_git_pass(git_repository_index(&index, g_repo));
cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) != 0);
@@ -113,7 +110,6 @@ void test_index_filemodes__untrusted(void)
void test_index_filemodes__trusted(void)
{
- git_config *cfg;
git_index *index;
/* Only run these tests on platforms where I can actually
@@ -122,9 +118,7 @@ void test_index_filemodes__trusted(void)
if (!cl_is_chmod_supported())
return;
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, "core.filemode", true));
- git_config_free(cfg);
+ cl_repo_set_bool(g_repo, "core.filemode", true);
cl_git_pass(git_repository_index(&index, g_repo));
cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) == 0);
diff --git a/tests-clar/repo/hashfile.c b/tests-clar/repo/hashfile.c
index 129e5d3..4cc9f18 100644
--- a/tests-clar/repo/hashfile.c
+++ b/tests-clar/repo/hashfile.c
@@ -41,11 +41,8 @@ void test_repo_hashfile__simple(void)
void test_repo_hashfile__filtered(void)
{
git_oid a, b;
- git_config *config;
- cl_git_pass(git_repository_config(&config, _repo));
- cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
- git_config_free(config);
+ cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index e6f5308..8cf7379 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -276,11 +276,9 @@ void test_repo_init__reinit_overwrites_filemode(void)
cl_set_cleanup(&cleanup_repository, "overwrite.git");
cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
-
/* Change the "core.filemode" config value to something unlikely */
- git_repository_config(&config, _repo);
- git_config_set_bool(config, "core.filemode", !expected);
- git_config_free(config);
+ cl_repo_set_bool(_repo, "core.filemode", !expected);
+
git_repository_free(_repo);
_repo = NULL;
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index b5449f6..5b11d1f 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -470,15 +470,14 @@ 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_INIT;
- git_config *cfg;
/* overwrite stored filemode with platform appropriate value */
- cl_git_pass(git_repository_config(&cfg, repo));
if (cl_is_chmod_supported())
- cl_git_pass(git_config_set_bool(cfg, "core.filemode", true));
+ cl_repo_set_bool(repo, "core.filemode", true);
else {
int i;
- cl_git_pass(git_config_set_bool(cfg, "core.filemode", false));
+
+ cl_repo_set_bool(repo, "core.filemode", false);
/* won't trust filesystem mode diffs, so these will appear unchanged */
for (i = 0; i < filemode_count; ++i)
@@ -502,8 +501,6 @@ void test_status_worktree__filemode_changes(void)
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
-
- git_config_free(cfg);
}
static int cb_status__interrupt(const char *p, unsigned int s, void *payload)
@@ -533,12 +530,9 @@ void test_status_worktree__interruptable_foreach(void)
void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void)
{
git_repository *repo = cl_git_sandbox_init("status");
- git_config *config;
unsigned int status;
- cl_git_pass(git_repository_config(&config, repo));
- cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
- git_config_free(config);
+ cl_repo_set_bool(repo, "core.autocrlf", true);
cl_git_rewritefile("status/current_file", "current_file\r\n");
@@ -621,7 +615,6 @@ static void assert_ignore_case(
int expected_lower_cased_file_status,
int expected_camel_cased_file_status)
{
- git_config *config;
unsigned int status;
git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
git_repository *repo, *repo2;
@@ -629,9 +622,7 @@ static void assert_ignore_case(
repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
- cl_git_pass(git_repository_config(&config, repo));
- cl_git_pass(git_config_set_bool(config, "core.ignorecase", should_ignore_case));
- git_config_free(config);
+ cl_repo_set_bool(repo, "core.ignorecase", should_ignore_case);
cl_git_pass(git_buf_joinpath(&lower_case_path,
git_repository_workdir(repo), "plop"));
diff --git a/tests-clar/status/worktree_init.c b/tests-clar/status/worktree_init.c
index 0c34dde..b67107a 100644
--- a/tests-clar/status/worktree_init.c
+++ b/tests-clar/status/worktree_init.c
@@ -316,15 +316,13 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
{
git_repository *repo;
git_index *index;
- git_config *config;
unsigned int status;
cl_set_cleanup(&cleanup_new_repo, "getting_started");
cl_git_pass(git_repository_init(&repo, "getting_started", 0));
// Ensure that repo has core.autocrlf=true
- cl_git_pass(git_repository_config(&config, repo));
- cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
+ cl_repo_set_bool(repo, "core.autocrlf", true);
cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF
@@ -335,7 +333,6 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
cl_git_pass(git_status_file(&status, repo, "testfile.txt"));
cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status);
- git_config_free(config);
git_index_free(index);
git_repository_free(repo);
}