@@ -196,3 +196,44 @@ void test_filter_crlf__no_safecrlf(void)
196
196
git_buf_free (& out );
197
197
}
198
198
199
+ void test_filter_crlf__safecrlf_warn (void )
200
+ {
201
+ git_filter_list * fl ;
202
+ git_filter * crlf ;
203
+ git_buf in = {0 }, out = GIT_BUF_INIT ;
204
+
205
+ cl_repo_set_string (g_repo , "core.safecrlf" , "warn" );
206
+
207
+ cl_git_pass (git_filter_list_new (
208
+ & fl , g_repo , GIT_FILTER_TO_ODB , 0 ));
209
+
210
+ crlf = git_filter_lookup (GIT_FILTER_CRLF );
211
+ cl_assert (crlf != NULL );
212
+
213
+ cl_git_pass (git_filter_list_push (fl , crlf , NULL ));
214
+
215
+ /* Normalized \r\n succeeds with safecrlf=warn */
216
+ in .ptr = "Normal\r\nCRLF\r\nline-endings.\r\n" ;
217
+ in .size = strlen (in .ptr );
218
+
219
+ cl_git_pass (git_filter_list_apply_to_data (& out , fl , & in ));
220
+ cl_assert_equal_s ("Normal\nCRLF\nline-endings.\n" , out .ptr );
221
+
222
+ /* Mix of line endings succeeds with safecrlf=warn */
223
+ in .ptr = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n" ;
224
+ in .size = strlen (in .ptr );
225
+
226
+ cl_git_pass (git_filter_list_apply_to_data (& out , fl , & in ));
227
+ /* TODO: check for warning */
228
+ cl_assert_equal_s ("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n" , out .ptr );
229
+
230
+ /* Normalized \n is reversible, so does not fail with safecrlf=warn */
231
+ in .ptr = "Normal\nLF\nonly\nline-endings.\n" ;
232
+ in .size = strlen (in .ptr );
233
+
234
+ cl_git_pass (git_filter_list_apply_to_data (& out , fl , & in ));
235
+ cl_assert_equal_s (in .ptr , out .ptr );
236
+
237
+ git_filter_list_free (fl );
238
+ git_buf_free (& out );
239
+ }
0 commit comments