Fix missing reset of index
[TortoiseGit.git] / ext / libgit2-0001-core.autocrlf-true-and-core.safecrlf-true-did-not-fa.patch
blob63fb19be051e4bb3b48d43c7adb1f606a0ee4e53
1 From 2146afb93ec53691421d58c01d883e622f7effba Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Fri, 23 Jan 2015 14:16:34 +0100
4 Subject: [PATCH] core.autocrlf=true and core.safecrlf=true did not fail on
5 LF-only file as vanilla git does
7 Reported-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw>
8 Signed-off-by: Sven Strickroth <email@cs-ware.de>
9 ---
10 src/crlf.c | 4 ++--
11 tests/filter/crlf.c | 6 +++---
12 tests/index/crlf.c | 38 +++++++++++++++++++++++++++++++++++++-
13 3 files changed, 42 insertions(+), 6 deletions(-)
15 diff --git a/src/crlf.c b/src/crlf.c
16 index b8ae5cda1..6e39b0b9f 100644
17 --- a/src/crlf.c
18 +++ b/src/crlf.c
19 @@ -138,8 +138,8 @@ static int crlf_apply_to_odb(
20 if (git_buf_text_gather_stats(&stats, from, false))
21 return GIT_PASSTHROUGH;
23 - /* If there are no CR characters to filter out, then just pass */
24 - if (!stats.cr)
25 + /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
26 + if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
27 return GIT_PASSTHROUGH;
29 /* If safecrlf is enabled, sanity-check the result. */
30 diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
31 index a8ebd949f..3490f1e0d 100644
32 --- a/tests/filter/crlf.c
33 +++ b/tests/filter/crlf.c
34 @@ -99,12 +99,12 @@ void test_filter_crlf__with_safecrlf(void)
35 cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
36 cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
38 - /* Normalized \n is reversible, so does not fail with safecrlf */
39 + /* Normalized \n fails with safecrlf if AutoCrLf=true which is the case here */
40 in.ptr = "Normal\nLF\nonly\nline-endings.\n";
41 in.size = strlen(in.ptr);
43 - cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
44 - cl_assert_equal_s(in.ptr, out.ptr);
45 + cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
46 + cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
48 git_filter_list_free(fl);
49 git_buf_free(&out);
50 diff --git a/tests/index/crlf.c b/tests/index/crlf.c
51 index 6544d9b52..024f4b056 100644
52 --- a/tests/index/crlf.c
53 +++ b/tests/index/crlf.c
54 @@ -340,13 +340,49 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void)
55 cl_assert_equal_oid(&oid, &entry->id);
58 +void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void)
60 + const git_index_entry *entry;
61 + git_oid oid;
63 + cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
65 + cl_repo_set_string(g_repo, "core.autocrlf", "input");
66 + cl_repo_set_bool(g_repo, "core.safecrlf", true);
68 + cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
70 + cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
71 + entry = git_index_get_bypath(g_index, "newfile.txt", 0);
73 + cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
74 + cl_assert_equal_oid(&oid, &entry->id);
77 +void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void)
79 + const git_index_entry *entry;
80 + git_oid oid;
82 + cl_repo_set_string(g_repo, "core.autocrlf", "input");
83 + cl_repo_set_bool(g_repo, "core.safecrlf", true);
85 + cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
87 + cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
88 + entry = git_index_get_bypath(g_index, "newfile.txt", 0);
90 + cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
91 + cl_assert_equal_oid(&oid, &entry->id);
94 void test_index_crlf__safecrlf_true_no_attrs(void)
96 cl_repo_set_bool(g_repo, "core.autocrlf", true);
97 cl_repo_set_bool(g_repo, "core.safecrlf", true);
99 cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW);
100 - cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
101 + cl_git_fail(git_index_add_bypath(g_index, "newfile.txt")); /* vanilla git fails here (on CrLf as well as on Lf-ony platforms): "fatal: LF would be replaced by CRLF in crlf/newfile.txt" */
103 cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW);
104 cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
106 2.11.0.windows.3