Skip to content

Commit 3661e35

Browse files
committed
filter: test we can filter a blob in a bare repo
1 parent fba3bf7 commit 3661e35

File tree

68 files changed

+134
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+134
-0
lines changed

tests/filter/bare.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "clar_libgit2.h"
2+
#include "crlf.h"
3+
4+
static git_repository *g_repo = NULL;
5+
static git_blob_filter_options filter_opts = GIT_BLOB_FILTER_OPTIONS_INIT;
6+
7+
void test_filter_bare__initialize(void)
8+
{
9+
cl_fixture_sandbox("crlf.git");
10+
cl_git_pass(git_repository_open(&g_repo, "crlf.git"));
11+
12+
filter_opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
13+
filter_opts.flags |= GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD;
14+
}
15+
16+
void test_filter_bare__cleanup(void)
17+
{
18+
git_repository_free(g_repo);
19+
cl_fixture_cleanup("crlf.git");
20+
}
21+
22+
void test_filter_bare__all_crlf(void)
23+
{
24+
git_blob *blob;
25+
git_buf buf = { 0 };
26+
27+
cl_git_pass(git_revparse_single(
28+
(git_object **)&blob, g_repo, "a9a2e89")); /* all-crlf */
29+
30+
cl_assert_equal_s(ALL_CRLF_TEXT_RAW, git_blob_rawcontent(blob));
31+
32+
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
33+
34+
cl_assert_equal_s(ALL_CRLF_TEXT_RAW, buf.ptr);
35+
36+
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
37+
38+
/* in this case, raw content has crlf in it already */
39+
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
40+
41+
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
42+
43+
/* we never convert CRLF -> LF on platforms that have LF */
44+
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
45+
46+
cl_git_pass(git_blob_filter(&buf, blob, "file.txt", &filter_opts));
47+
48+
/* in this case, raw content has crlf in it already */
49+
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
50+
51+
git_buf_dispose(&buf);
52+
git_blob_free(blob);
53+
}
54+
55+
void test_filter_bare__from_lf(void)
56+
{
57+
git_blob *blob;
58+
git_buf buf = { 0 };
59+
60+
cl_git_pass(git_revparse_single(
61+
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
62+
63+
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
64+
65+
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
66+
67+
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
68+
69+
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
70+
71+
/* in this case, raw content has crlf in it already */
72+
cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
73+
74+
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
75+
76+
/* we never convert CRLF -> LF on platforms that have LF */
77+
cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
78+
79+
git_buf_dispose(&buf);
80+
git_blob_free(blob);
81+
}
82+
83+
void test_filter_bare__sanitizes(void)
84+
{
85+
git_blob *blob;
86+
git_buf buf = GIT_BUF_INIT;
87+
88+
cl_git_pass(git_revparse_single(
89+
(git_object **)&blob, g_repo, "e69de29")); /* zero-byte */
90+
91+
cl_assert_equal_i(0, git_blob_rawsize(blob));
92+
cl_assert_equal_s("", git_blob_rawcontent(blob));
93+
94+
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
95+
cl_assert_equal_sz(0, buf.size);
96+
cl_assert_equal_s("", buf.ptr);
97+
git_buf_dispose(&buf);
98+
99+
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
100+
cl_assert_equal_sz(0, buf.size);
101+
cl_assert_equal_s("", buf.ptr);
102+
git_buf_dispose(&buf);
103+
104+
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
105+
cl_assert_equal_sz(0, buf.size);
106+
cl_assert_equal_s("", buf.ptr);
107+
git_buf_dispose(&buf);
108+
109+
git_blob_free(blob);
110+
}
111+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add .gitattributes

tests/resources/crlf.git/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

tests/resources/crlf.git/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[core]
2+
repositoryformatversion = 0
3+
bare = true

tests/resources/crlf.git/logs/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5afb6a14a864e30787857dd92af837e8cdd2cb1b 6b9d5748663795f573ea857276eb2a5f8330efa0 Edward Thomson <ethomson@edwardthomson.com> 1561324263 +0100 commit: Add .gitattributes
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5afb6a14a864e30787857dd92af837e8cdd2cb1b 6b9d5748663795f573ea857276eb2a5f8330efa0 Edward Thomson <ethomson@edwardthomson.com> 1561324263 +0100 commit: Add .gitattributes

tests/resources/crlf.git/objects/04/4bcd5c9bf5ebdd51e514a9a36457018f06f6e1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x-��j�0D{�W�4H+�+C(ɡ����]a��JU��|}���̃�ʺ.к�VE@���v��Ȕ���vB�x=%���l�sD��x�H�!x3�E9�A�hP�dU���T��k� {�k�+�A��v���`���C2|h��괟lR�{�~/�]`z��-̥<����]�M�5�?]ud������r��&K!
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)