Blame tests/repo/hashfile.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
Packit Service 20376f
static git_repository *_repo;
Packit Service 20376f
Packit Service 20376f
void test_repo_hashfile__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
	_repo = cl_git_sandbox_init("status");
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_repo_hashfile__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
	_repo = NULL;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_repo_hashfile__simple(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid a, b;
Packit Service 20376f
	git_buf full = GIT_BUF_INIT;
Packit Service 20376f
Packit Service 20376f
	/* hash with repo relative path */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJ_BLOB, NULL));
Packit Service 20376f
	cl_assert_equal_oid(&a, &b);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file"));
Packit Service 20376f
Packit Service 20376f
	/* hash with full path */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_BLOB, NULL));
Packit Service 20376f
	cl_assert_equal_oid(&a, &b);
Packit Service 20376f
Packit Service 20376f
	/* hash with invalid type */
Packit Service 20376f
	cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJ_ANY));
Packit Service 20376f
	cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_OFS_DELTA, NULL));
Packit Service 20376f
Packit Service 20376f
	git_buf_free(&full);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_repo_hashfile__filtered(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid a, b;
Packit Service 20376f
Packit Service 20376f
	cl_repo_set_bool(_repo, "core.autocrlf", true);
Packit Service 20376f
Packit Service 20376f
	cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
Packit Service 20376f
Packit Service 20376f
	/* create some sample content with CRLF in it */
Packit Service 20376f
	cl_git_mkfile("status/testfile.txt", "content\r\n");
Packit Service 20376f
	cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n");
Packit Service 20376f
Packit Service 20376f
	/* not equal hashes because of filtering */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, NULL));
Packit Service 20376f
	cl_assert(git_oid_cmp(&a, &b);;
Packit Service 20376f
Packit Service 20376f
	/* equal hashes because filter is binary */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, NULL));
Packit Service 20376f
	cl_assert_equal_oid(&a, &b);
Packit Service 20376f
Packit Service 20376f
	/* equal hashes when 'as_file' points to binary filtering */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, "foo.bin"));
Packit Service 20376f
	cl_assert_equal_oid(&a, &b);
Packit Service 20376f
Packit Service 20376f
	/* not equal hashes when 'as_file' points to text filtering */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, "foo.txt"));
Packit Service 20376f
	cl_assert(git_oid_cmp(&a, &b);;
Packit Service 20376f
Packit Service 20376f
	/* equal hashes when 'as_file' is empty and turns off filtering */
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, ""));
Packit Service 20376f
	cl_assert_equal_oid(&a, &b);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
Packit Service 20376f
	cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, ""));
Packit Service 20376f
	cl_assert_equal_oid(&a, &b);
Packit Service 20376f
Packit Service 20376f
	/* some hash type failures */
Packit Service 20376f
	cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
Packit Service 20376f
	cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_ANY, NULL));
Packit Service 20376f
}