]>
git.proxmox.com Git - libgit2.git/blob - tests/repo/hashfile.c
0fb4e6772a1e10cb9b0bd83fe47134a56dcd72d8
1 #include "clar_libgit2.h"
4 static git_repository
*_repo
;
6 void test_repo_hashfile__initialize(void)
8 _repo
= cl_git_sandbox_init("status");
11 void test_repo_hashfile__cleanup(void)
13 cl_git_sandbox_cleanup();
17 void test_repo_hashfile__simple(void)
20 git_buf full
= GIT_BUF_INIT
;
22 /* hash with repo relative path */
23 cl_git_pass(git_odb_hashfile(&a
, "status/current_file", GIT_OBJECT_BLOB
));
24 cl_git_pass(git_repository_hashfile(&b
, _repo
, "current_file", GIT_OBJECT_BLOB
, NULL
));
25 cl_assert_equal_oid(&a
, &b
);
27 cl_git_pass(git_buf_joinpath(&full
, git_repository_workdir(_repo
), "current_file"));
29 /* hash with full path */
30 cl_git_pass(git_odb_hashfile(&a
, full
.ptr
, GIT_OBJECT_BLOB
));
31 cl_git_pass(git_repository_hashfile(&b
, _repo
, full
.ptr
, GIT_OBJECT_BLOB
, NULL
));
32 cl_assert_equal_oid(&a
, &b
);
34 /* hash with invalid type */
35 cl_git_fail(git_odb_hashfile(&a
, full
.ptr
, GIT_OBJECT_ANY
));
36 cl_git_fail(git_repository_hashfile(&b
, _repo
, full
.ptr
, GIT_OBJECT_OFS_DELTA
, NULL
));
38 git_buf_dispose(&full
);
41 void test_repo_hashfile__filtered(void)
45 cl_repo_set_bool(_repo
, "core.autocrlf", true);
47 cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
49 /* create some sample content with CRLF in it */
50 cl_git_mkfile("status/testfile.txt", "content\r\n");
51 cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n");
53 /* not equal hashes because of filtering */
54 cl_git_pass(git_odb_hashfile(&a
, "status/testfile.txt", GIT_OBJECT_BLOB
));
55 cl_git_pass(git_repository_hashfile(&b
, _repo
, "testfile.txt", GIT_OBJECT_BLOB
, NULL
));
56 cl_assert(git_oid_cmp(&a
, &b
));
58 /* equal hashes because filter is binary */
59 cl_git_pass(git_odb_hashfile(&a
, "status/testfile.bin", GIT_OBJECT_BLOB
));
60 cl_git_pass(git_repository_hashfile(&b
, _repo
, "testfile.bin", GIT_OBJECT_BLOB
, NULL
));
61 cl_assert_equal_oid(&a
, &b
);
63 /* equal hashes when 'as_file' points to binary filtering */
64 cl_git_pass(git_odb_hashfile(&a
, "status/testfile.txt", GIT_OBJECT_BLOB
));
65 cl_git_pass(git_repository_hashfile(&b
, _repo
, "testfile.txt", GIT_OBJECT_BLOB
, "foo.bin"));
66 cl_assert_equal_oid(&a
, &b
);
68 /* not equal hashes when 'as_file' points to text filtering */
69 cl_git_pass(git_odb_hashfile(&a
, "status/testfile.bin", GIT_OBJECT_BLOB
));
70 cl_git_pass(git_repository_hashfile(&b
, _repo
, "testfile.bin", GIT_OBJECT_BLOB
, "foo.txt"));
71 cl_assert(git_oid_cmp(&a
, &b
));
73 /* equal hashes when 'as_file' is empty and turns off filtering */
74 cl_git_pass(git_odb_hashfile(&a
, "status/testfile.txt", GIT_OBJECT_BLOB
));
75 cl_git_pass(git_repository_hashfile(&b
, _repo
, "testfile.txt", GIT_OBJECT_BLOB
, ""));
76 cl_assert_equal_oid(&a
, &b
);
78 cl_git_pass(git_odb_hashfile(&a
, "status/testfile.bin", GIT_OBJECT_BLOB
));
79 cl_git_pass(git_repository_hashfile(&b
, _repo
, "testfile.bin", GIT_OBJECT_BLOB
, ""));
80 cl_assert_equal_oid(&a
, &b
);
82 /* some hash type failures */
83 cl_git_fail(git_odb_hashfile(&a
, "status/testfile.txt", 0));
84 cl_git_fail(git_repository_hashfile(&b
, _repo
, "testfile.txt", GIT_OBJECT_ANY
, NULL
));