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