File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments