1 From 2146afb93ec53691421d58c01d883e622f7effba Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Fri, 23 Jan 2015 14:16:34 +0100
4 Subject: [PATCH 1/8] core.autocrlf=true and core.safecrlf=true did not fail on
5 LF-only file as vanilla git does
7 Reported-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw>
8 Signed-off-by: Sven Strickroth <email@cs-ware.de>
12 tests/filter/crlf.c | 6 +++---
13 tests/index/crlf.c | 38 +++++++++++++++++++++++++++++++++++++-
14 4 files changed, 45 insertions(+), 6 deletions(-)
16 diff --git a/CHANGELOG.md b/CHANGELOG.md
17 index 0ae75e156..5784d3b86 100644
20 @@ -7,6 +7,9 @@ v0.25 + 1
21 This aligns this structure with the default by `git_merge` and
22 `git_merge_trees` when `NULL` was provided for the options.
24 +* LF -> CRLF filter now correctly honors core.safecrlf=true errors
25 + * LF only files were accepted with core.autocrlf=true on CRLF platforms
30 diff --git a/src/crlf.c b/src/crlf.c
31 index b8ae5cda1..6e39b0b9f 100644
34 @@ -138,8 +138,8 @@ static int crlf_apply_to_odb(
35 if (git_buf_text_gather_stats(&stats, from, false))
36 return GIT_PASSTHROUGH;
38 - /* If there are no CR characters to filter out, then just pass */
40 + /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
41 + if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
42 return GIT_PASSTHROUGH;
44 /* If safecrlf is enabled, sanity-check the result. */
45 diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
46 index a8ebd949f..3490f1e0d 100644
47 --- a/tests/filter/crlf.c
48 +++ b/tests/filter/crlf.c
49 @@ -99,12 +99,12 @@ void test_filter_crlf__with_safecrlf(void)
50 cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
51 cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
53 - /* Normalized \n is reversible, so does not fail with safecrlf */
54 + /* Normalized \n fails with safecrlf if AutoCrLf=true which is the case here */
55 in.ptr = "Normal\nLF\nonly\nline-endings.\n";
56 in.size = strlen(in.ptr);
58 - cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
59 - cl_assert_equal_s(in.ptr, out.ptr);
60 + cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
61 + cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
63 git_filter_list_free(fl);
65 diff --git a/tests/index/crlf.c b/tests/index/crlf.c
66 index 6544d9b52..024f4b056 100644
67 --- a/tests/index/crlf.c
68 +++ b/tests/index/crlf.c
69 @@ -340,13 +340,49 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void)
70 cl_assert_equal_oid(&oid, &entry->id);
73 +void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void)
75 + const git_index_entry *entry;
78 + cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
80 + cl_repo_set_string(g_repo, "core.autocrlf", "input");
81 + cl_repo_set_bool(g_repo, "core.safecrlf", true);
83 + cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
85 + cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
86 + entry = git_index_get_bypath(g_index, "newfile.txt", 0);
88 + cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
89 + cl_assert_equal_oid(&oid, &entry->id);
92 +void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void)
94 + const git_index_entry *entry;
97 + cl_repo_set_string(g_repo, "core.autocrlf", "input");
98 + cl_repo_set_bool(g_repo, "core.safecrlf", true);
100 + cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
102 + cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
103 + entry = git_index_get_bypath(g_index, "newfile.txt", 0);
105 + cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
106 + cl_assert_equal_oid(&oid, &entry->id);
109 void test_index_crlf__safecrlf_true_no_attrs(void)
111 cl_repo_set_bool(g_repo, "core.autocrlf", true);
112 cl_repo_set_bool(g_repo, "core.safecrlf", true);
114 cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW);
115 - cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
116 + cl_git_fail(git_index_add_bypath(g_index, "newfile.txt")); /* vanilla git fails here (on CrLf as well as on Lf-ony platforms): "fatal: LF would be replaced by CRLF in crlf/newfile.txt" */
118 cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW);
119 cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));