Skip to content

Commit c66f760

Browse files
committed
filter: ensure system attributes are read
By default, `/etc/gitattributes` (or the system equivalent) is read to provide attributes. Ensure that, by default, this is read when filtering blobs.
1 parent fa1a4c7 commit c66f760

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/filter/systemattrs.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

0 commit comments

Comments
 (0)