RepositoryBrowser: Add drag handler
[TortoiseGit.git] / ext / libgit2-0001-core.autocrlf-true-and-core.safecrlf-true-did-not-fa.patch
blob4019fc26952f2db25acadffe943ec33aec805cf0
1 From 0445fc8383a1b316932f54cbb97240ad5f37ea5d 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 1/6] 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 CHANGELOG.md | 3 +++
11 src/crlf.c | 4 ++--
12 tests/filter/crlf.c | 6 +++---
13 tests/index/crlf.c | 38 +++++++++++++++++++++++++++++++++++++-
14 4 files changed, 45 insertions(+), 6 deletions(-)
16 diff --git a/CHANGELOG.md b/CHANGELOG.md
17 index e140608..8fb39cd 100644
18 --- a/CHANGELOG.md
19 +++ b/CHANGELOG.md
20 @@ -10,6 +10,9 @@ v0.22 + 1
21 * Updated binary identification in CRLF filtering to avoid false positives in
22 UTF-8 files.
24 +* LF -> CRLF filter now correctly honors core.safecrlf=true errors
25 + * LF only files were accepted with core.autocrlf=true on CRLF platforms
27 * Rename and copy detection is enabled for small files.
29 * Checkout can now handle an initial checkout of a repository, making
30 diff --git a/src/crlf.c b/src/crlf.c
31 index f391137..3a3c937 100644
32 --- a/src/crlf.c
33 +++ b/src/crlf.c
34 @@ -138,8 +138,8 @@ static int crlf_apply_to_odb(
35 if (git_buf_text_gather_stats(&stats, from, false))
36 return GIT_PASSTHROUGH;
38 - /* If there are no CR characters to filter out, then just pass */
39 - if (!stats.cr)
40 + /* If there are no CR characters to filter out and CrLf is not set to "true", then just pass */
41 + if (!stats.cr && ca->auto_crlf != GIT_AUTO_CRLF_TRUE)
42 return GIT_PASSTHROUGH;
44 /* If safecrlf is enabled, sanity-check the result. */
45 diff --git a/tests/filter/crlf.c b/tests/filter/crlf.c
46 index a8ebd94..3490f1e 100644
47 --- a/tests/filter/crlf.c
48 +++ b/tests/filter/crlf.c
49 @@ -99,12 +99,12 @@ void test_filter_crlf__with_safecrlf(void)
50 cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
51 cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
53 - /* Normalized \n is reversible, so does not fail with safecrlf */
54 + /* Normalized \n fails with safecrlf if AutoCrLf=true which is the case here */
55 in.ptr = "Normal\nLF\nonly\nline-endings.\n";
56 in.size = strlen(in.ptr);
58 - cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
59 - cl_assert_equal_s(in.ptr, out.ptr);
60 + cl_git_fail(git_filter_list_apply_to_data(&out, fl, &in));
61 + cl_assert_equal_i(giterr_last()->klass, GITERR_FILTER);
63 git_filter_list_free(fl);
64 git_buf_free(&out);
65 diff --git a/tests/index/crlf.c b/tests/index/crlf.c
66 index 98783fb..d2f01d1 100644
67 --- a/tests/index/crlf.c
68 +++ b/tests/index/crlf.c
69 @@ -341,13 +341,49 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void)
70 cl_assert_equal_oid(&oid, &entry->id);
73 +void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void)
75 + const git_index_entry *entry;
76 + git_oid oid;
78 + cl_git_mkfile("./crlf/.gitattributes", "* text=auto\n");
80 + cl_repo_set_string(g_repo, "core.autocrlf", "input");
81 + cl_repo_set_bool(g_repo, "core.safecrlf", true);
83 + cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
85 + cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
86 + entry = git_index_get_bypath(g_index, "newfile.txt", 0);
88 + cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
89 + cl_assert_equal_oid(&oid, &entry->id);
92 +void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void)
94 + const git_index_entry *entry;
95 + git_oid oid;
97 + cl_repo_set_string(g_repo, "core.autocrlf", "input");
98 + cl_repo_set_bool(g_repo, "core.safecrlf", true);
100 + cl_git_mkfile("./crlf/newfile.txt", FILE_CONTENTS_LF);
102 + cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
103 + entry = git_index_get_bypath(g_index, "newfile.txt", 0);
105 + cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF));
106 + cl_assert_equal_oid(&oid, &entry->id);
109 void test_index_crlf__safecrlf_true_no_attrs(void)
111 cl_repo_set_bool(g_repo, "core.autocrlf", true);
112 cl_repo_set_bool(g_repo, "core.safecrlf", true);
114 cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW);
115 - cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
116 + 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" */
118 cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW);
119 cl_git_pass(git_index_add_bypath(g_index, "newfile.txt"));
121 2.4.4.windows.2