1 #include "clar_libgit2.h"
4 static git_repository
*g_repo
= NULL
;
5 static git_blob_filter_options filter_opts
= GIT_BLOB_FILTER_OPTIONS_INIT
;
7 void test_filter_bare__initialize(void)
9 cl_fixture_sandbox("crlf.git");
10 cl_git_pass(git_repository_open(&g_repo
, "crlf.git"));
12 filter_opts
.flags
|= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES
;
13 filter_opts
.flags
|= GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD
;
16 void test_filter_bare__cleanup(void)
18 git_repository_free(g_repo
);
19 cl_fixture_cleanup("crlf.git");
22 void test_filter_bare__all_crlf(void)
27 cl_git_pass(git_revparse_single(
28 (git_object
**)&blob
, g_repo
, "a9a2e89")); /* all-crlf */
30 cl_assert_equal_s(ALL_CRLF_TEXT_RAW
, git_blob_rawcontent(blob
));
32 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", &filter_opts
));
34 cl_assert_equal_s(ALL_CRLF_TEXT_RAW
, buf
.ptr
);
36 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", &filter_opts
));
38 /* in this case, raw content has crlf in it already */
39 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF
, buf
.ptr
);
41 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", &filter_opts
));
43 /* we never convert CRLF -> LF on platforms that have LF */
44 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF
, buf
.ptr
);
46 cl_git_pass(git_blob_filter(&buf
, blob
, "file.txt", &filter_opts
));
48 /* in this case, raw content has crlf in it already */
49 cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF
, buf
.ptr
);
51 git_buf_dispose(&buf
);
55 void test_filter_bare__from_lf(void)
60 cl_git_pass(git_revparse_single(
61 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
63 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
65 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", &filter_opts
));
67 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
69 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", &filter_opts
));
71 /* in this case, raw content has crlf in it already */
72 cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF
, buf
.ptr
);
74 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", &filter_opts
));
76 /* we never convert CRLF -> LF on platforms that have LF */
77 cl_assert_equal_s(ALL_LF_TEXT_AS_LF
, buf
.ptr
);
79 git_buf_dispose(&buf
);
83 void test_filter_bare__nested_attributes(void)
88 cl_git_pass(git_revparse_single(
89 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
91 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
93 cl_git_pass(git_blob_filter(&buf
, blob
, "raw/file.bin", &filter_opts
));
94 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
96 cl_git_pass(git_blob_filter(&buf
, blob
, "raw/file.crlf", &filter_opts
));
97 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
99 cl_git_pass(git_blob_filter(&buf
, blob
, "raw/file.lf", &filter_opts
));
100 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
102 git_buf_dispose(&buf
);
106 void test_filter_bare__sanitizes(void)
109 git_buf buf
= GIT_BUF_INIT
;
111 cl_git_pass(git_revparse_single(
112 (git_object
**)&blob
, g_repo
, "e69de29")); /* zero-byte */
114 cl_assert_equal_i(0, git_blob_rawsize(blob
));
115 cl_assert_equal_s("", git_blob_rawcontent(blob
));
117 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", &filter_opts
));
118 cl_assert_equal_sz(0, buf
.size
);
119 cl_assert_equal_s("", buf
.ptr
);
120 git_buf_dispose(&buf
);
122 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", &filter_opts
));
123 cl_assert_equal_sz(0, buf
.size
);
124 cl_assert_equal_s("", buf
.ptr
);
125 git_buf_dispose(&buf
);
127 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", &filter_opts
));
128 cl_assert_equal_sz(0, buf
.size
);
129 cl_assert_equal_s("", buf
.ptr
);
130 git_buf_dispose(&buf
);
135 void test_filter_bare__from_specific_commit_one(void)
137 git_blob_filter_options opts
= GIT_BLOB_FILTER_OPTIONS_INIT
;
141 opts
.flags
|= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES
;
142 opts
.flags
|= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT
;
143 cl_git_pass(git_oid_fromstr(&opts
.attr_commit_id
, "b8986fec0f7bde90f78ac72706e782d82f24f2f0"));
145 cl_git_pass(git_revparse_single(
146 (git_object
**)&blob
, g_repo
, "055c872")); /* ident */
148 cl_assert_equal_s("$Id$\n", git_blob_rawcontent(blob
));
150 cl_git_pass(git_blob_filter(&buf
, blob
, "ident.bin", &opts
));
151 cl_assert_equal_s("$Id$\n", buf
.ptr
);
153 cl_git_pass(git_blob_filter(&buf
, blob
, "ident.identlf", &opts
));
154 cl_assert_equal_s("$Id: 055c8729cdcc372500a08db659c045e16c4409fb $\n", buf
.ptr
);
156 git_buf_dispose(&buf
);
160 void test_filter_bare__from_specific_commit_with_no_attributes_file(void)
162 git_blob_filter_options opts
= GIT_BLOB_FILTER_OPTIONS_INIT
;
166 opts
.flags
|= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES
;
167 opts
.flags
|= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT
;
168 cl_git_pass(git_oid_fromstr(&opts
.attr_commit_id
, "5afb6a14a864e30787857dd92af837e8cdd2cb1b"));
170 cl_git_pass(git_revparse_single(
171 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
173 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
175 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", &opts
));
176 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
178 /* we never convert CRLF -> LF on platforms that have LF */
179 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", &opts
));
180 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
182 /* we never convert CRLF -> LF on platforms that have LF */
183 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", &opts
));
184 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
186 git_buf_dispose(&buf
);