Commit 2a9b0102 by Sven Strickroth Committed by Edward Thomson

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>
parent ef8f8ec6
......@@ -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);
......
......@@ -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"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment