Skip to content

Commit 7ee233a

Browse files
author
Vicent Marti
committed
Merge pull request libgit2#2375 from libgit2/rb/safecrlf-on-lf-platform
Make core.safecrlf not generate an error on LF-ending platforms
2 parents ff9fb44 + c094197 commit 7ee233a

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/crlf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ static int crlf_apply_to_odb(
138138
if (git_buf_text_gather_stats(&stats, from, false))
139139
return GIT_PASSTHROUGH;
140140

141+
/* If there are no CR characters to filter out, then just pass */
142+
if (!stats.cr)
143+
return GIT_PASSTHROUGH;
144+
141145
/* If safecrlf is enabled, sanity-check the result. */
142146
if (stats.cr != stats.crlf || stats.lf != stats.crlf) {
143147
switch (ca->safe_crlf) {

tests/filter/crlf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ void test_filter_crlf__with_safecrlf(void)
103103
cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
104104
cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
105105

106-
/* Normalized \n fails with safecrlf */
106+
/* Normalized \n is reversible, so does not fail with safecrlf */
107107
in.ptr = "Normal\nLF\nonly\nline-endings.\n";
108108
in.size = strlen(in.ptr);
109109

110-
cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
111-
cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
110+
cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
111+
cl_assert_equal_s(in.ptr, out.ptr);
112112

113113
git_filter_list_free(fl);
114114
git_buf_free(&out);

tests/index/crlf.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,21 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void)
134134
cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
135135
cl_assert(git_oid_cmp(&oid, &entry->id) == 0);
136136
}
137+
138+
void test_index_crlf__safecrlf_true_no_attrs(void)
139+
{
140+
cl_repo_set_bool(g_repo, "core.autocrlf", true);
141+
cl_repo_set_bool(g_repo, "core.safecrlf", true);
142+
143+
cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW);
144+
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
145+
146+
cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW);
147+
cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
148+
149+
cl_git_mkfile("crlf/newfile.txt", MORE_CRLF_TEXT_RAW);
150+
cl_git_fail(git_index_add_bypath(g_index, "newfile.txt"));
151+
152+
cl_git_mkfile("crlf/newfile.txt", MORE_LF_TEXT_RAW);
153+
cl_git_fail(git_index_add_bypath(g_index, "newfile.txt"));
154+
}

0 commit comments

Comments
 (0)