]> git.proxmox.com Git - libgit2.git/blob - tests/filter/systemattrs.c
New upstream version 1.3.0+dfsg.1
[libgit2.git] / tests / filter / systemattrs.c
1 #include "clar_libgit2.h"
2 #include "crlf.h"
3 #include "path.h"
4
5 static git_repository *g_repo = NULL;
6 static git_buf system_attr_path = GIT_BUF_INIT;
7
8 void test_filter_systemattrs__initialize(void)
9 {
10 g_repo = cl_git_sandbox_init("crlf");
11 cl_must_pass(p_unlink("crlf/.gitattributes"));
12
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"));
17
18 cl_git_mkfile(system_attr_path.ptr,
19 "*.txt text\n"
20 "*.bin binary\n"
21 "*.crlf text eol=crlf\n"
22 "*.lf text eol=lf\n");
23 }
24
25 void test_filter_systemattrs__cleanup(void)
26 {
27 cl_must_pass(p_unlink(system_attr_path.ptr));
28 git_buf_dispose(&system_attr_path);
29
30 cl_git_sandbox_cleanup();
31 }
32
33 void test_filter_systemattrs__reads_system_attributes(void)
34 {
35 git_blob *blob;
36 git_buf buf = { 0 };
37
38 cl_git_pass(git_revparse_single(
39 (git_object **)&blob, g_repo, "799770d")); /* all-lf */
40
41 cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
42
43 cl_git_pass(git_blob_filter(&buf, blob, "file.bin", NULL));
44 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
45
46 cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", NULL));
47 cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
48
49 cl_git_pass(git_blob_filter(&buf, blob, "file.lf", NULL));
50 cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
51
52 git_buf_dispose(&buf);
53 git_blob_free(blob);
54 }
55
56 void test_filter_systemattrs__disables_system_attributes(void)
57 {
58 git_blob *blob;
59 git_buf buf = { 0 };
60 git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
61
62 opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
63
64 cl_git_pass(git_revparse_single(
65 (git_object **)&blob, g_repo, "799770d")); /* all-lf */
66
67 cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
68
69 cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &opts));
70 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
71
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);
75
76 cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &opts));
77 cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
78
79 git_buf_dispose(&buf);
80 git_blob_free(blob);
81 }