diff options
-rw-r--r-- | tests/filter/crlf.c | 11 | ||||
-rw-r--r-- | tests/index/crlf.c | 44 |
2 files changed, 52 insertions, 3 deletions
diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c index f67cb6248..a98646271 100644 --- a/tests/filter/crlf.c +++ b/tests/filter/crlf.c @@ -99,12 +99,19 @@ void test_filter_crlf__with_safecrlf(void) cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in)); cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER); - /* Normalized \n is reversible, so does not fail with safecrlf */ + /* Normalized \n fails for autocrlf=true when safecrlf=true */ in.ptr = "Normal\nLF\nonly\nline-endings.\n"; in.size = strlen(in.ptr); + cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in)); + cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER); + + /* String with \r but without \r\n does not fail with safecrlf */ + in.ptr = "Normal\nCR only\rand some more\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); + cl_assert_equal_s("Normal\nCR only\rand some more\nline-endings.\n", out.ptr); git_filter_list_free(fl); git_buf_dispose(&out); diff --git a/tests/index/crlf.c b/tests/index/crlf.c index c9c30b8b7..31050f8f8 100644 --- a/tests/index/crlf.c +++ b/tests/index/crlf.c @@ -339,13 +339,55 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void) cl_assert_equal_oid(&oid, &entry->id); } +void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void) +{ + const git_index_entry *entry; + git_oid oid; + + cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n"); + + cl_repo_set_string(g_repo, "core.autocrlf", "input"); + cl_repo_set_bool(g_repo, "core.safecrlf", true); + + cl_git_mkfile("./crlf/newfile.txt", 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_equal_oid(&oid, &entry->id); + + cl_git_mkfile("./crlf/newfile2.txt", FILE_CONTENTS_CRLF); + cl_git_fail(git_index_add_bypath(g_index, "newfile2.txt")); +} + +void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void) +{ + const git_index_entry *entry; + git_oid oid; + + cl_repo_set_string(g_repo, "core.autocrlf", "input"); + cl_repo_set_bool(g_repo, "core.safecrlf", true); + + cl_git_mkfile("./crlf/newfile.txt", 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_equal_oid(&oid, &entry->id); + + cl_git_mkfile("./crlf/newfile2.txt", FILE_CONTENTS_CRLF); + cl_git_fail(git_index_add_bypath(g_index, "newfile2.txt")); +} + void test_index_crlf__safecrlf_true_no_attrs(void) { cl_repo_set_bool(g_repo, "core.autocrlf", true); cl_repo_set_bool(g_repo, "core.safecrlf", true); cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW); - cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); + cl_git_fail(git_index_add_bypath(g_index, "newfile.txt")); cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW); cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); |