Blame tests/diff/pathspec.c

Packit ae9e2a
#include "clar_libgit2.h"
Packit ae9e2a
#include "diff_helpers.h"
Packit ae9e2a
Packit ae9e2a
static git_repository *g_repo = NULL;
Packit ae9e2a
Packit ae9e2a
void test_diff_pathspec__initialize(void)
Packit ae9e2a
{
Packit ae9e2a
	g_repo = cl_git_sandbox_init("status");
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_diff_pathspec__cleanup(void)
Packit ae9e2a
{
Packit ae9e2a
	cl_git_sandbox_cleanup();
Packit ae9e2a
}
Packit ae9e2a
Packit ae9e2a
void test_diff_pathspec__0(void)
Packit ae9e2a
{
Packit ae9e2a
	const char *a_commit = "26a125ee"; /* the current HEAD */
Packit ae9e2a
	const char *b_commit = "0017bd4a"; /* the start */
Packit ae9e2a
	git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
Packit ae9e2a
	git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
Packit ae9e2a
	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
Packit ae9e2a
	git_diff *diff = NULL;
Packit ae9e2a
	git_strarray paths = { NULL, 1 };
Packit ae9e2a
	char *path;
Packit ae9e2a
	git_pathspec *ps;
Packit ae9e2a
	git_pathspec_match_list *matches;
Packit ae9e2a
Packit ae9e2a
	cl_assert(a);
Packit ae9e2a
	cl_assert(b);
Packit ae9e2a
Packit ae9e2a
	path = "*_file";
Packit ae9e2a
	paths.strings = &pat;;
Packit ae9e2a
	cl_git_pass(git_pathspec_new(&ps, &paths));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_pathspec_match_tree(&matches, a, GIT_PATHSPEC_DEFAULT, ps));
Packit ae9e2a
	cl_assert_equal_i(7, (int)git_pathspec_match_list_entrycount(matches));
Packit ae9e2a
	cl_assert_equal_s("current_file", git_pathspec_match_list_entry(matches,0));
Packit ae9e2a
	cl_assert(git_pathspec_match_list_diff_entry(matches,0) == NULL);
Packit ae9e2a
	git_pathspec_match_list_free(matches);
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, NULL, a, &opts));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_pathspec_match_diff(
Packit ae9e2a
		&matches, diff, GIT_PATHSPEC_DEFAULT, ps));
Packit ae9e2a
	cl_assert_equal_i(7, (int)git_pathspec_match_list_entrycount(matches));
Packit ae9e2a
	cl_assert(git_pathspec_match_list_diff_entry(matches, 0) != NULL);
Packit ae9e2a
	cl_assert(git_pathspec_match_list_entry(matches, 0) == NULL);
Packit ae9e2a
	cl_assert_equal_s("current_file",
Packit ae9e2a
		git_pathspec_match_list_diff_entry(matches,0)->new_file.path);
Packit ae9e2a
	cl_assert_equal_i(GIT_DELTA_ADDED,
Packit ae9e2a
		(int)git_pathspec_match_list_diff_entry(matches,0)->status);
Packit ae9e2a
	git_pathspec_match_list_free(matches);
Packit ae9e2a
Packit ae9e2a
	git_diff_free(diff);
Packit ae9e2a
	diff = NULL;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_pathspec_match_diff(
Packit ae9e2a
		&matches, diff, GIT_PATHSPEC_DEFAULT, ps));
Packit ae9e2a
	cl_assert_equal_i(3, (int)git_pathspec_match_list_entrycount(matches));
Packit ae9e2a
	cl_assert(git_pathspec_match_list_diff_entry(matches, 0) != NULL);
Packit ae9e2a
	cl_assert(git_pathspec_match_list_entry(matches, 0) == NULL);
Packit ae9e2a
	cl_assert_equal_s("subdir/current_file",
Packit ae9e2a
		git_pathspec_match_list_diff_entry(matches,0)->new_file.path);
Packit ae9e2a
	cl_assert_equal_i(GIT_DELTA_DELETED,
Packit ae9e2a
		(int)git_pathspec_match_list_diff_entry(matches,0)->status);
Packit ae9e2a
	git_pathspec_match_list_free(matches);
Packit ae9e2a
Packit ae9e2a
	git_diff_free(diff);
Packit ae9e2a
	diff = NULL;
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
Packit ae9e2a
Packit ae9e2a
	cl_git_pass(git_pathspec_match_diff(
Packit ae9e2a
		&matches, diff, GIT_PATHSPEC_DEFAULT, ps));
Packit ae9e2a
	cl_assert_equal_i(4, (int)git_pathspec_match_list_entrycount(matches));
Packit ae9e2a
	cl_assert(git_pathspec_match_list_diff_entry(matches, 0) != NULL);
Packit ae9e2a
	cl_assert(git_pathspec_match_list_entry(matches, 0) == NULL);
Packit ae9e2a
	cl_assert_equal_s("modified_file",
Packit ae9e2a
		git_pathspec_match_list_diff_entry(matches,0)->new_file.path);
Packit ae9e2a
	cl_assert_equal_i(GIT_DELTA_MODIFIED,
Packit ae9e2a
		(int)git_pathspec_match_list_diff_entry(matches,0)->status);
Packit ae9e2a
	git_pathspec_match_list_free(matches);
Packit ae9e2a
Packit ae9e2a
	git_diff_free(diff);
Packit ae9e2a
	diff = NULL;
Packit ae9e2a
Packit ae9e2a
	git_tree_free(a);
Packit ae9e2a
	git_tree_free(b);
Packit ae9e2a
	git_pathspec_free(ps);
Packit ae9e2a
}