void test_merge_driver__honors_custom_mergedefault(void) { const char *expected = "This is the `custom` driver.\n"; cl_repo_set_string(repo, "merge.default", "custom"); merge_branch(); cl_assert_equal_file(expected, strlen(expected), TEST_REPO_PATH "/applied.txt"); }
void test_merge_driver__honors_builtin_mergedefault(void) { const git_index_entry *ancestor, *ours, *theirs; cl_repo_set_string(repo, "merge.default", "binary"); merge_branch(); cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs, repo_index, "automergeable.txt")); }
void test_checkout_crlf__autocrlf_input_no_attrs(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_repo_set_string(g_repo, "core.autocrlf", "input"); git_checkout_head(g_repo, &opts); check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW); check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW); }
void test_merge_driver__unset_forces_binary(void) { const git_index_entry *ancestor, *ours, *theirs; /* `-merge` without specifying a driver indicates `binary` */ set_gitattributes_to(NULL); cl_repo_set_string(repo, "merge.default", "custom"); merge_branch(); cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs, repo_index, "automergeable.txt")); }
void test_merge_driver__set_forces_text(void) { const git_index_entry *idx; /* `merge` without specifying a driver indicates `text` */ set_gitattributes_to(""); cl_repo_set_string(repo, "merge.default", "custom"); merge_branch(); cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0))); cl_assert_equal_oid(&automergeable_id, &idx->id); }
void test_merge_driver__mergedefault_deferring_falls_back_to_text(void) { const git_index_entry *idx; cl_git_pass(git_merge_driver_register("defer", &test_driver_defer_apply.base)); cl_repo_set_string(repo, "merge.default", "defer"); merge_branch(); cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0))); cl_assert_equal_oid(&automergeable_id, &idx->id); git_merge_driver_unregister("defer"); }
void test_index_crlf__autocrlf_input_no_attrs(void) { const git_index_entry *entry; git_oid oid; cl_repo_set_string(g_repo, "core.autocrlf", "input"); cl_git_mkfile("./crlf/newfile.txt", (GIT_EOL_NATIVE == GIT_EOL_CRLF) ? FILE_CONTENTS_CRLF : FILE_CONTENTS_LF); cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); cl_assert(git_oid_cmp(&oid, &entry->id) == 0); }
void test_filter_crlf__safecrlf_warn(void) { git_filter_list *fl; git_filter *crlf; git_buf in = {0}, out = GIT_BUF_INIT; cl_repo_set_string(g_repo, "core.safecrlf", "warn"); cl_git_pass(git_filter_list_new( &fl, g_repo, GIT_FILTER_TO_ODB, 0)); crlf = git_filter_lookup(GIT_FILTER_CRLF); cl_assert(crlf != NULL); cl_git_pass(git_filter_list_push(fl, crlf, NULL)); /* Normalized \r\n succeeds with safecrlf=warn */ in.ptr = "Normal\r\nCRLF\r\nline-endings.\r\n"; in.size = strlen(in.ptr); cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr); /* Mix of line endings succeeds with safecrlf=warn */ in.ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n"; in.size = strlen(in.ptr); cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); /* TODO: check for warning */ cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr); /* Normalized \n is reversible, so does not fail with safecrlf=warn */ in.ptr = "Normal\nLF\nonly\nline-endings.\n"; in.size = strlen(in.ptr); cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in)); cl_assert_equal_s(in.ptr, out.ptr); git_filter_list_free(fl); git_buf_free(&out); }