1 #include "clar_libgit2.h"
5 static git_repository
*g_repo
= NULL
;
6 static git_str system_attr_path
= GIT_STR_INIT
;
8 void test_filter_systemattrs__initialize(void)
10 git_buf system_path
= GIT_BUF_INIT
;
12 g_repo
= cl_git_sandbox_init("crlf");
13 cl_must_pass(p_unlink("crlf/.gitattributes"));
15 cl_git_pass(git_libgit2_opts(
16 GIT_OPT_GET_SEARCH_PATH
, GIT_CONFIG_LEVEL_SYSTEM
, &system_path
));
17 cl_git_pass(git_str_joinpath(&system_attr_path
,
18 system_path
.ptr
, "gitattributes"));
20 cl_git_mkfile(system_attr_path
.ptr
,
23 "*.crlf text eol=crlf\n"
24 "*.lf text eol=lf\n");
26 git_buf_dispose(&system_path
);
29 void test_filter_systemattrs__cleanup(void)
31 cl_must_pass(p_unlink(system_attr_path
.ptr
));
32 git_str_dispose(&system_attr_path
);
34 cl_git_sandbox_cleanup();
37 void test_filter_systemattrs__reads_system_attributes(void)
42 cl_git_pass(git_revparse_single(
43 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
45 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
47 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", NULL
));
48 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
50 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", NULL
));
51 cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF
, buf
.ptr
);
53 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", NULL
));
54 cl_assert_equal_s(ALL_LF_TEXT_AS_LF
, buf
.ptr
);
56 git_buf_dispose(&buf
);
60 void test_filter_systemattrs__disables_system_attributes(void)
64 git_blob_filter_options opts
= GIT_BLOB_FILTER_OPTIONS_INIT
;
66 opts
.flags
|= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES
;
68 cl_git_pass(git_revparse_single(
69 (git_object
**)&blob
, g_repo
, "799770d")); /* all-lf */
71 cl_assert_equal_s(ALL_LF_TEXT_RAW
, git_blob_rawcontent(blob
));
73 cl_git_pass(git_blob_filter(&buf
, blob
, "file.bin", &opts
));
74 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
76 /* No attributes mean these are all treated literally */
77 cl_git_pass(git_blob_filter(&buf
, blob
, "file.crlf", &opts
));
78 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
80 cl_git_pass(git_blob_filter(&buf
, blob
, "file.lf", &opts
));
81 cl_assert_equal_s(ALL_LF_TEXT_RAW
, buf
.ptr
);
83 git_buf_dispose(&buf
);