Fix missing reset of index
[TortoiseGit.git] / ext / libgit2-0004-Make-files-with-CR-CRLF-not-fail-with-core.safecrlf-.patch
blobaf351eb6174bf96326a8ec2372391ca85232affe
1 From 78b6049046afcb041d785b56641664f5ffa99e9f Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Fri, 23 Jan 2015 17:15:16 +0100
4 Subject: [PATCH] Make files with #CR!=#CRLF not fail with
5 core.safecrlf=true
7 Signed-off-by: Sven Strickroth <email@cs-ware.de>
8 ---
9 src/crlf.c | 18 +++++++++---------
10 tests/filter/crlf.c | 7 +++++++
11 2 files changed, 16 insertions(+), 9 deletions(-)
13 diff --git a/src/crlf.c b/src/crlf.c
14 index dd5a7625c..858a94484 100644
15 --- a/src/crlf.c
16 +++ b/src/crlf.c
17 @@ -138,12 +138,20 @@ static int crlf_apply_to_odb(
18 if (git_buf_text_gather_stats(&stats, from, false))
19 return GIT_PASSTHROUGH;
21 + /*
22 + * We're currently not going to even try to convert stuff
23 + * that has bare CR characters. Does anybody do that crazy
24 + * stuff?
25 + */
26 + if (stats.cr != stats.crlf)
27 + return GIT_PASSTHROUGH;
29 /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
30 if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
31 return GIT_PASSTHROUGH;
33 /* If safecrlf is enabled, sanity-check the result. */
34 - if (stats.cr != stats.crlf || stats.lf != stats.crlf) {
35 + if (stats.lf != stats.crlf) {
36 switch (ca->safe_crlf) {
37 case GIT_SAFE_CRLF_FAIL:
38 giterr_set(
39 @@ -171,14 +179,6 @@ static int crlf_apply_to_odb(
43 - /*
44 - * We're currently not going to even try to convert stuff
45 - * that has bare CR characters. Does anybody do that crazy
46 - * stuff?
47 - */
48 - if (stats.cr != stats.crlf)
49 - return GIT_PASSTHROUGH;
51 if (ca->crlf_action == GIT_CRLF_GUESS) {
53 * If the file in the index has any CR in it, do not convert.
54 diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
55 index 3490f1e0d..d1bf7a450 100644
56 --- a/tests/filter/crlf.c
57 +++ b/tests/filter/crlf.c
58 @@ -106,6 +106,13 @@ void test_filter_crlf__with_safecrlf(void)
59 cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
60 cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
62 + /* String with \r but without \r\n does not fail with safecrlf */
63 + in.ptr = "Normal\nCR only\rand some more\nline-endings.\n";
64 + in.size = strlen(in.ptr);
66 + cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
67 + cl_assert_equal_s("Normal\nCR only\rand some more\nline-endings.\n", out.ptr);
69 git_filter_list_free(fl);
70 git_buf_free(&out);
72 --
73 2.11.0.windows.3