Some tests with ident and crlf filters Fixed the filter order to match core Git, too. This test demonstrates an interesting behavior of core Git (which is totally reasonable and which libgit2 matches, although mostly by coincidence). If you use the ident filter and commit a file with a garbage ident in it, like '$Id: this is just garbage$' and then immediately do a 'git checkout-index' with the new file, Git will not consider the file out of date and will not overwrite the file with an updated $Id$. Libgit2 has the same behavior. If you remove the file and then do a checkout-index, it will be replaced with a filtered version that has injected the OID correctly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
diff --git a/examples/showindex.c b/examples/showindex.c
index e92a9c8..93718c8 100644
--- a/examples/showindex.c
+++ b/examples/showindex.c
@@ -12,6 +12,8 @@ int main (int argc, char** argv)
char out[41];
out[40] = '\0';
+ git_threads_init();
+
if (argc > 1)
dir = argv[1];
if (!dir || argc > 2) {
@@ -62,6 +64,8 @@ int main (int argc, char** argv)
git_index_free(index);
git_repository_free(repo);
+ git_threads_shutdown();
+
return 0;
}
diff --git a/src/filter.c b/src/filter.c
index 62aefb4..3782098 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -593,7 +593,7 @@ int git_filter_list_apply_to_data(
for (i = 0; i < git_array_size(fl->filters); ++i) {
unsigned int di = 1 - si;
- uint32_t fidx = (fl->source.mode == GIT_FILTER_TO_ODB) ?
+ uint32_t fidx = (fl->source.mode == GIT_FILTER_TO_WORKTREE) ?
i : git_array_size(fl->filters) - 1 - i;
git_filter_entry *fe = git_array_get(fl->filters, fidx);
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
index 5f5f1b7..4953609 100644
--- a/tests-clar/checkout/crlf.c
+++ b/tests-clar/checkout/crlf.c
@@ -4,6 +4,7 @@
#include "git2/checkout.h"
#include "repository.h"
+#include "posix.h"
static git_repository *g_repo;
@@ -136,3 +137,67 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
git_index_free(index);
}
+
+void test_checkout_crlf__with_ident(void)
+{
+ git_index *index;
+ git_blob *blob;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_mkfile("crlf/.gitattributes",
+ "*.txt text\n*.bin binary\n"
+ "*.crlf text eol=crlf\n"
+ "*.lf text eol=lf\n"
+ "*.ident text ident\n"
+ "*.identcrlf ident text eol=crlf\n"
+ "*.identlf ident text eol=lf\n");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ /* add files with $Id$ */
+
+ cl_git_mkfile("crlf/lf.ident", ALL_LF_TEXT_RAW "\n$Id: initial content$\n");
+ cl_git_mkfile("crlf/crlf.ident", ALL_CRLF_TEXT_RAW "\r\n$Id$\r\n\r\n");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_add_bypath(index, "lf.ident"));
+ cl_git_pass(git_index_add_bypath(index, "crlf.ident"));
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "Some ident files\n");
+
+ git_checkout_head(g_repo, &opts);
+
+ /* check that blob has $Id$ */
+
+ cl_git_pass(git_blob_lookup(&blob, g_repo,
+ & git_index_get_bypath(index, "lf.ident", 0)->oid));
+ cl_assert_equal_s(
+ ALL_LF_TEXT_RAW "\n$Id$\n", git_blob_rawcontent(blob));
+
+ git_blob_free(blob);
+
+ /* check that filesystem is initially untouched - matching core Git */
+
+ cl_assert_equal_file(
+ ALL_LF_TEXT_RAW "\n$Id: initial content$\n", 0, "crlf/lf.ident");
+
+ /* check that forced checkout rewrites correctly */
+
+ p_unlink("crlf/lf.ident");
+ p_unlink("crlf/crlflf.ident");
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ cl_assert_equal_file(
+ ALL_LF_TEXT_RAW
+ "\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\n",
+ 0, "crlf/lf.ident");
+ else
+ cl_assert_equal_file(
+ ALL_LF_TEXT_AS_CRLF
+ "\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\r\n",
+ 0, "crlf/lf.ident");
+
+ git_index_free(index);
+}
diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c
index 4cf6824..d7e2883 100644
--- a/tests-clar/clar_libgit2.c
+++ b/tests-clar/clar_libgit2.c
@@ -455,8 +455,15 @@ void clar__assert_equal_file(
if (ignore_cr)
bytes = strip_cr_from_buf(buf, bytes);
- clar__assert(memcmp(expected_data, buf, bytes) == 0,
- file, line, "file content mismatch", path, 1);
+ if (memcmp(expected_data, buf, bytes) != 0) {
+ int pos;
+ for (pos = 0; pos < bytes && expected_data[pos] == buf[pos]; ++pos)
+ /* find differing byte offset */;
+ p_snprintf(
+ buf, sizeof(buf), "file content mismatch at byte %d",
+ (int)(total_bytes + pos));
+ clar__fail(file, line, buf, path, 1);
+ }
expected_data += bytes;
total_bytes += bytes;