Skip to content

Commit 2a9b010

Browse files
cswareethomson
authored andcommitted
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 parent ef8f8ec commit 2a9b010

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

tests/filter/crlf.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,19 @@ void test_filter_crlf__with_safecrlf(void)
9999
cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
100100
cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
101101

102-
/* Normalized \n is reversible, so does not fail with safecrlf */
102+
/* Normalized \n fails for autocrlf=true when safecrlf=true */
103103
in.ptr = "Normal\nLF\nonly\nline-endings.\n";
104104
in.size = strlen(in.ptr);
105105

106+
cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
107+
cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
108+
109+
/* String with \r but without \r\n does not fail with safecrlf */
110+
in.ptr = "Normal\nCR only\rand some more\nline-endings.\n";
111+
in.size = strlen(in.ptr);
112+
106113
cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
107-
cl_assert_equal_s(in.ptr, out.ptr);
114+
cl_assert_equal_s("Normal\nCR only\rand some more\nline-endings.\n", out.ptr);
108115

109116
git_filter_list_free(fl);
110117
git_buf_dispose(&out);

tests/index/crlf.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,55 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void)
339339
cl_assert_equal_oid(&oid, &entry->id);
340340
}
341341

342+
void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void)
343+
{
344+
const git_index_entry *entry;
345+
git_oid oid;
346+
347+
cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
348+
349+
cl_repo_set_string(g_repo, "core.autocrlf", "input");
350+
cl_repo_set_bool(g_repo, "core.safecrlf", true);
351+
352+
cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
353+
354+
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
355+
entry = git_index_get_bypath(g_index, "newfile.txt", 0);
356+
357+
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
358+
cl_assert_equal_oid(&oid, &entry->id);
359+
360+
cl_git_mkfile("./crlf/newfile2.txt", FILE_CONTENTS_CRLF);
361+
cl_git_fail(git_index_add_bypath(g_index, "newfile2.txt"));
362+
}
363+
364+
void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void)
365+
{
366+
const git_index_entry *entry;
367+
git_oid oid;
368+
369+
cl_repo_set_string(g_repo, "core.autocrlf", "input");
370+
cl_repo_set_bool(g_repo, "core.safecrlf", true);
371+
372+
cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
373+
374+
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
375+
entry = git_index_get_bypath(g_index, "newfile.txt", 0);
376+
377+
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
378+
cl_assert_equal_oid(&oid, &entry->id);
379+
380+
cl_git_mkfile("./crlf/newfile2.txt", FILE_CONTENTS_CRLF);
381+
cl_git_fail(git_index_add_bypath(g_index, "newfile2.txt"));
382+
}
383+
342384
void test_index_crlf__safecrlf_true_no_attrs(void)
343385
{
344386
cl_repo_set_bool(g_repo, "core.autocrlf", true);
345387
cl_repo_set_bool(g_repo, "core.safecrlf", true);
346388

347389
cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW);
348-
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
390+
cl_git_fail(git_index_add_bypath(g_index, "newfile.txt"));
349391

350392
cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW);
351393
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));

0 commit comments

Comments
 (0)