summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Strickroth <email@cs-ware.de>2015-01-23 14:16:34 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2018-12-03 17:02:10 -0800
commit2a9b0102fc9c96bccc674db420a056f65cbc179f (patch)
tree15f8c195b816071f1a692922911f45d14d2cad55
parentef8f8ec604035142916271178b009f57faf1877a (diff)
downloadlibgit2-2a9b0102fc9c96bccc674db420a056f65cbc179f.tar.gz
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>
-rw-r--r--tests/filter/crlf.c11
-rw-r--r--tests/index/crlf.c44
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"));