Additional core.autocrlf and core.safecrlf tests This is a cherry-pick of the tests from the following commits: core.autocrlf=true and core.safecrlf=true did not fail on LF-only file as vanilla git does Adding a CRLF-file with core.autocrlf=input and core.safecrlf=true does not fail as with vanilla git Make files with #CR!=#CRLF not fail with core.safecrlf=true Reported-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw> Signed-off-by: Sven Strickroth <email@cs-ware.de>
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
diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
index f67cb62..a986462 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 c9c30b8..31050f8 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"));