1 #include "clar_libgit2.h"
5 static git_repository
*g_repo
= NULL
;
6 static git_buf system_attr_path
= GIT_BUF_INIT
;
8 void test_filter_systemattrs__initialize(void)
10 g_repo
= cl_git_sandbox_init("crlf");
11 cl_must_pass(p_unlink("crlf/.gitattributes"));
13 cl_git_pass(git_libgit2_opts(
14 GIT_OPT_GET_SEARCH_PATH
, GIT_CONFIG_LEVEL_SYSTEM
, &system_attr_path
));
15 cl_git_pass(git_buf_joinpath(&system_attr_path
,
16 system_attr_path
.ptr
, "gitattributes"));
18 cl_git_mkfile(system_attr_path
.ptr
,
21 "*.crlf text eol=crlf\n"
22 "*.lf text eol=lf\n");
25 void test_filter_systemattrs__cleanup(void)
27 cl_must_pass(p_unlink(system_attr_path
.ptr
));
28 git_buf_dispose(&system_attr_path
);
30 cl_git_sandbox_cleanup();
33 void test_filter_systemattrs__reads_system_attributes(void)
38 cl_git_pass(git_revparse_single(
39 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
41 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
43 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", NULL
));
44 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
46 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", NULL
));
47 cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF
, buf
.ptr
);
49 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", NULL
));
50 cl_assert_equal_s(ALL_LF_TEXT_AS_LF
, buf
.ptr
);
52 git_buf_dispose(&buf
);
56 void test_filter_systemattrs__disables_system_attributes(void)
60 git_blob_filter_options opts
= GIT_BLOB_FILTER_OPTIONS_INIT
;
62 opts
.flags
|= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES
;
64 cl_git_pass(git_revparse_single(
65 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
67 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
69 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", &opts
));
70 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
72 /* No attributes mean these are all treated literally */
73 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", &opts
));
74 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
76 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", &opts
));
77 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
79 git_buf_dispose(&buf
);