Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4cf8268

Browse files
author
Vicent Marti
committed
Merge pull request libgit2#2388 from ethomson/safecrlf_ignore_warn
Ignore core.safecrlf=warn until we have a warn infrastructure
2 parents 58eea5e + 49837fd commit 4cf8268

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/config_cache.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ static git_cvar_map _cvar_map_autocrlf[] = {
5151
{GIT_CVAR_STRING, "input", GIT_AUTO_CRLF_INPUT}
5252
};
5353

54+
static git_cvar_map _cvar_map_safecrlf[] = {
55+
{GIT_CVAR_FALSE, NULL, GIT_SAFE_CRLF_FALSE},
56+
{GIT_CVAR_TRUE, NULL, GIT_SAFE_CRLF_FAIL},
57+
{GIT_CVAR_STRING, "warn", GIT_SAFE_CRLF_WARN}
58+
};
59+
5460
/*
5561
* Generic map for integer values
5662
*/
@@ -68,7 +74,7 @@ static struct map_data _cvar_maps[] = {
6874
{"core.trustctime", NULL, 0, GIT_TRUSTCTIME_DEFAULT },
6975
{"core.abbrev", _cvar_map_int, 1, GIT_ABBREV_DEFAULT },
7076
{"core.precomposeunicode", NULL, 0, GIT_PRECOMPOSE_DEFAULT },
71-
{"core.safecrlf", NULL, 0, GIT_SAFE_CRLF_DEFAULT},
77+
{"core.safecrlf", _cvar_map_safecrlf, ARRAY_SIZE(_cvar_map_safecrlf), GIT_SAFE_CRLF_DEFAULT},
7278
{"core.logallrefupdates", NULL, 0, GIT_LOGALLREFUPDATES_DEFAULT },
7379
};
7480

tests/filter/crlf.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,44 @@ void test_filter_crlf__no_safecrlf(void)
196196
git_buf_free(&out);
197197
}
198198

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

Comments
 (0)