Blame tests/index/addall.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "../status/status_helpers.h"
Packit Service 20376f
#include "posix.h"
Packit Service 20376f
#include "fileops.h"
Packit Service 20376f
Packit Service 20376f
static git_repository *g_repo = NULL;
Packit Service 20376f
#define TEST_DIR "addall"
Packit Service 20376f
Packit Service 20376f
void test_index_addall__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
#define STATUS_INDEX_FLAGS \
Packit Service 20376f
	(GIT_STATUS_INDEX_NEW | GIT_STATUS_INDEX_MODIFIED | \
Packit Service 20376f
	 GIT_STATUS_INDEX_DELETED | GIT_STATUS_INDEX_RENAMED | \
Packit Service 20376f
	 GIT_STATUS_INDEX_TYPECHANGE)
Packit Service 20376f
Packit Service 20376f
#define STATUS_WT_FLAGS \
Packit Service 20376f
	(GIT_STATUS_WT_NEW | GIT_STATUS_WT_MODIFIED | \
Packit Service 20376f
	 GIT_STATUS_WT_DELETED | GIT_STATUS_WT_TYPECHANGE | \
Packit Service 20376f
	 GIT_STATUS_WT_RENAMED)
Packit Service 20376f
Packit Service 20376f
typedef struct {
Packit Service 20376f
	size_t index_adds;
Packit Service 20376f
	size_t index_dels;
Packit Service 20376f
	size_t index_mods;
Packit Service 20376f
	size_t wt_adds;
Packit Service 20376f
	size_t wt_dels;
Packit Service 20376f
	size_t wt_mods;
Packit Service 20376f
	size_t ignores;
Packit Service 20376f
	size_t conflicts;
Packit Service 20376f
} index_status_counts;
Packit Service 20376f
Packit Service 20376f
static int index_status_cb(
Packit Service 20376f
	const char *path, unsigned int status_flags, void *payload)
Packit Service 20376f
{
Packit Service 20376f
	index_status_counts *vals = payload;
Packit Service 20376f
Packit Service 20376f
	/* cb_status__print(path, status_flags, NULL); */
Packit Service 20376f
Packit Service 20376f
	GIT_UNUSED(path);
Packit Service 20376f
Packit Service 20376f
	if (status_flags & GIT_STATUS_INDEX_NEW)
Packit Service 20376f
		vals->index_adds++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_INDEX_MODIFIED)
Packit Service 20376f
		vals->index_mods++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_INDEX_DELETED)
Packit Service 20376f
		vals->index_dels++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_INDEX_TYPECHANGE)
Packit Service 20376f
		vals->index_mods++;
Packit Service 20376f
Packit Service 20376f
	if (status_flags & GIT_STATUS_WT_NEW)
Packit Service 20376f
		vals->wt_adds++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_WT_MODIFIED)
Packit Service 20376f
		vals->wt_mods++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_WT_DELETED)
Packit Service 20376f
		vals->wt_dels++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_WT_TYPECHANGE)
Packit Service 20376f
		vals->wt_mods++;
Packit Service 20376f
Packit Service 20376f
	if (status_flags & GIT_STATUS_IGNORED)
Packit Service 20376f
		vals->ignores++;
Packit Service 20376f
	if (status_flags & GIT_STATUS_CONFLICTED)
Packit Service 20376f
		vals->conflicts++;
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void check_status_at_line(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	size_t index_adds, size_t index_dels, size_t index_mods,
Packit Service 20376f
	size_t wt_adds, size_t wt_dels, size_t wt_mods, size_t ignores,
Packit Service 20376f
	size_t conflicts, const char *file, int line)
Packit Service 20376f
{
Packit Service 20376f
	index_status_counts vals;
Packit Service 20376f
Packit Service 20376f
	memset(&vals, 0, sizeof(vals));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_status_foreach(repo, index_status_cb, &vals));
Packit Service 20376f
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong index adds", 1, "%"PRIuZ, index_adds, vals.index_adds);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong index dels", 1, "%"PRIuZ, index_dels, vals.index_dels);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong index mods", 1, "%"PRIuZ, index_mods, vals.index_mods);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong workdir adds", 1, "%"PRIuZ, wt_adds, vals.wt_adds);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong workdir dels", 1, "%"PRIuZ, wt_dels, vals.wt_dels);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong workdir mods", 1, "%"PRIuZ, wt_mods, vals.wt_mods);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong ignores", 1, "%"PRIuZ, ignores, vals.ignores);
Packit Service 20376f
	clar__assert_equal(
Packit Service 20376f
		file,line,"wrong conflicts", 1, "%"PRIuZ, conflicts, vals.conflicts);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
#define check_status(R,IA,ID,IM,WA,WD,WM,IG,C) \
Packit Service 20376f
	check_status_at_line(R,IA,ID,IM,WA,WD,WM,IG,C,__FILE__,__LINE__)
Packit Service 20376f
Packit Service 20376f
static void check_stat_data(git_index *index, const char *path, bool match)
Packit Service 20376f
{
Packit Service 20376f
	const git_index_entry *entry;
Packit Service 20376f
	struct stat st;
Packit Service 20376f
Packit Service 20376f
	cl_must_pass(p_lstat(path, &st);;
Packit Service 20376f
Packit Service 20376f
	/* skip repo base dir name */
Packit Service 20376f
	while (*path != '/')
Packit Service 20376f
		++path;
Packit Service 20376f
	++path;
Packit Service 20376f
Packit Service 20376f
	entry = git_index_get_bypath(index, path, 0);
Packit Service 20376f
	cl_assert(entry);
Packit Service 20376f
Packit Service 20376f
	if (match) {
Packit Service 20376f
		cl_assert(st.st_ctime == entry->ctime.seconds);
Packit Service 20376f
		cl_assert(st.st_mtime == entry->mtime.seconds);
Packit Service 20376f
		cl_assert(st.st_size == entry->file_size);
Packit Service 20376f
		cl_assert(st.st_uid  == entry->uid);
Packit Service 20376f
		cl_assert(st.st_gid  == entry->gid);
Packit Service 20376f
		cl_assert_equal_i_fmt(
Packit Service 20376f
			GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
Packit Service 20376f
		if (cl_is_chmod_supported())
Packit Service 20376f
			cl_assert_equal_b(
Packit Service 20376f
				GIT_PERMS_IS_EXEC(st.st_mode), GIT_PERMS_IS_EXEC(entry->mode));
Packit Service 20376f
	} else {
Packit Service 20376f
		/* most things will still match */
Packit Service 20376f
		cl_assert(st.st_size != entry->file_size);
Packit Service 20376f
		/* would check mtime, but with second resolution it won't work :( */
Packit Service 20376f
	}
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static void addall_create_test_repo(bool check_every_step)
Packit Service 20376f
{
Packit Service 20376f
	g_repo = cl_git_sandbox_init_new(TEST_DIR);
Packit Service 20376f
Packit Service 20376f
	if (check_every_step)
Packit Service 20376f
		check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/file.foo", "a file");
Packit Service 20376f
	if (check_every_step)
Packit Service 20376f
		check_status(g_repo, 0, 0, 0, 1, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/.gitignore", "*.foo\n");
Packit Service 20376f
	if (check_every_step)
Packit Service 20376f
		check_status(g_repo, 0, 0, 0, 1, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/file.bar", "another file");
Packit Service 20376f
	if (check_every_step)
Packit Service 20376f
		check_status(g_repo, 0, 0, 0, 2, 0, 0, 1, 0);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__repo_lifecycle(void)
Packit Service 20376f
{
Packit Service 20376f
	int error;
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_strarray paths = { NULL, 0 };
Packit Service 20376f
	char *strs[1];
Packit Service 20376f
Packit Service 20376f
	addall_create_test_repo(true);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	strs[0] = "file.*";
Packit Service 20376f
	paths.strings = strs;
Packit Service 20376f
	paths.count   = 1;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 1, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile(TEST_DIR "/file.bar", "new content for file");
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", false);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 1, 0, 1, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 4, 0, 1, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.zzz", true);
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "first commit");
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	if (cl_repo_get_bool(g_repo, "core.filemode")) {
Packit Service 20376f
		cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
		cl_must_pass(p_chmod(TEST_DIR "/file.zzz", 0777));
Packit Service 20376f
		cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
		check_status(g_repo, 0, 0, 1, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
		/* go back to what we had before */
Packit Service 20376f
		cl_must_pass(p_chmod(TEST_DIR "/file.zzz", 0666));
Packit Service 20376f
		cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
		check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
	/* attempt to add an ignored file - does nothing */
Packit Service 20376f
	strs[0] = "file.foo";
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	/* add with check - should generate error */
Packit Service 20376f
	error = git_index_add_all(
Packit Service 20376f
		index, &paths, GIT_INDEX_ADD_CHECK_PATHSPEC, NULL, NULL);
Packit Service 20376f
	cl_assert_equal_i(GIT_EINVALIDSPEC, error);
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	/* add with force - should allow */
Packit Service 20376f
	cl_git_pass(git_index_add_all(
Packit Service 20376f
		index, &paths, GIT_INDEX_ADD_FORCE, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.foo", true);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 3, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	/* now it's in the index, so regular add should work */
Packit Service 20376f
	cl_git_rewritefile(TEST_DIR "/file.foo", "new content for file");
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.foo", false);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 3, 0, 1, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.foo", true);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 3, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "more.zzz"));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/more.zzz", true);
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 2, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile(TEST_DIR "/file.zzz", "new content for file");
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 2, 0, 1, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "file.zzz"));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.zzz", true);
Packit Service 20376f
	check_status(g_repo, 2, 0, 1, 2, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	strs[0] = "*.zzz";
Packit Service 20376f
	cl_git_pass(git_index_remove_all(index, &paths, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 1, 1, 0, 4, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(index, "file.zzz"));
Packit Service 20376f
	check_status(g_repo, 1, 0, 1, 3, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "second commit");
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_must_pass(p_unlink(TEST_DIR "/file.zzz"));
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 3, 1, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	/* update_all should be able to remove entries */
Packit Service 20376f
	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 0, 1, 0, 3, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	strs[0] = "*";
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 3, 1, 0, 0, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	/* must be able to remove at any position while still updating other files */
Packit Service 20376f
	cl_must_pass(p_unlink(TEST_DIR "/.gitignore"));
Packit Service 20376f
	cl_git_rewritefile(TEST_DIR "/file.zzz", "reconstructed file");
Packit Service 20376f
	cl_git_rewritefile(TEST_DIR "/more.zzz", "altered file reality");
Packit Service 20376f
	check_status(g_repo, 3, 1, 0, 1, 1, 1, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 2, 1, 0, 1, 0, 0, 0, 0);
Packit Service 20376f
	/* this behavior actually matches 'git add -u' where "file.zzz" has
Packit Service 20376f
	 * been removed from the index, so when you go to update, even though
Packit Service 20376f
	 * it exists in the HEAD, it is not re-added to the index, leaving it
Packit Service 20376f
	 * as a DELETE when comparing HEAD to index and as an ADD comparing
Packit Service 20376f
	 * index to worktree
Packit Service 20376f
	 */
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__files_in_folders(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	addall_create_test_repo(true);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 0, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_must_pass(p_mkdir(TEST_DIR "/subdir", 0777));
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/subdir/file", "hello!\n");
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 1, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 3, 0, 0, 0, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__hidden_files(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	GIT_UNUSED(index);
Packit Service 20376f
Packit Service 20376f
#ifdef GIT_WIN32
Packit Service 20376f
	addall_create_test_repo(true);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 0, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");
Packit Service 20376f
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_win32__set_hidden(TEST_DIR "/file.zzz", true));
Packit Service 20376f
	cl_git_pass(git_win32__set_hidden(TEST_DIR "/more.zzz", true));
Packit Service 20376f
	cl_git_pass(git_win32__set_hidden(TEST_DIR "/other.zzz", true));
Packit Service 20376f
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 5, 0, 0, 0, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
#endif
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static int addall_match_prefix(
Packit Service 20376f
	const char *path, const char *matched_pathspec, void *payload)
Packit Service 20376f
{
Packit Service 20376f
	GIT_UNUSED(matched_pathspec);
Packit Service 20376f
	return !git__prefixcmp(path, payload) ? 0 : 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static int addall_match_suffix(
Packit Service 20376f
	const char *path, const char *matched_pathspec, void *payload)
Packit Service 20376f
{
Packit Service 20376f
	GIT_UNUSED(matched_pathspec);
Packit Service 20376f
	return !git__suffixcmp(path, payload) ? 0 : 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
static int addall_cancel_at(
Packit Service 20376f
	const char *path, const char *matched_pathspec, void *payload)
Packit Service 20376f
{
Packit Service 20376f
	GIT_UNUSED(matched_pathspec);
Packit Service 20376f
	return !strcmp(path, payload) ? -123 : 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__callback_filtering(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
Packit Service 20376f
	addall_create_test_repo(false);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(
Packit Service 20376f
		git_index_add_all(index, NULL, 0, addall_match_prefix, "file."));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 1, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
Packit Service 20376f
	cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/file.bar", true);
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(
Packit Service 20376f
		git_index_add_all(index, NULL, 0, addall_match_prefix, "other"));
Packit Service 20376f
	check_stat_data(index, TEST_DIR "/other.zzz", true);
Packit Service 20376f
	check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(
Packit Service 20376f
		git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz"));
Packit Service 20376f
	check_status(g_repo, 4, 0, 0, 1, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(
Packit Service 20376f
		git_index_remove_all(index, NULL, addall_match_suffix, ".zzz"));
Packit Service 20376f
	check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(
Packit Service 20376f
		git_index_add_all(index, NULL, 0, addall_cancel_at, "more.zzz"), -123);
Packit Service 20376f
	check_status(g_repo, 3, 0, 0, 2, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(
Packit Service 20376f
		git_index_add_all(index, NULL, 0, addall_cancel_at, "other.zzz"), -123);
Packit Service 20376f
	check_status(g_repo, 4, 0, 0, 1, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(
Packit Service 20376f
		git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz"));
Packit Service 20376f
	check_status(g_repo, 5, 0, 0, 0, 0, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_must_pass(p_unlink(TEST_DIR "/file.zzz"));
Packit Service 20376f
	cl_must_pass(p_unlink(TEST_DIR "/more.zzz"));
Packit Service 20376f
	cl_must_pass(p_unlink(TEST_DIR "/other.zzz"));
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(
Packit Service 20376f
		git_index_update_all(index, NULL, addall_cancel_at, "more.zzz"), -123);
Packit Service 20376f
	/* file.zzz removed from index (so Index Adds 5 -> 4) and
Packit Service 20376f
	 * more.zzz + other.zzz removed (so Worktree Dels 0 -> 2) */
Packit Service 20376f
	check_status(g_repo, 4, 0, 0, 0, 2, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(
Packit Service 20376f
		git_index_update_all(index, NULL, addall_cancel_at, "other.zzz"), -123);
Packit Service 20376f
	/* more.zzz removed from index (so Index Adds 4 -> 3) and
Packit Service 20376f
	 * Just other.zzz removed (so Worktree Dels 2 -> 1) */
Packit Service 20376f
	check_status(g_repo, 3, 0, 0, 0, 1, 0, 1, 0);
Packit Service 20376f
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__adds_conflicts(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_reference *ref;
Packit Service 20376f
	git_annotated_commit *annotated;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("merge-resolve");
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch"));
Packit Service 20376f
	cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 0, 1, 3, 0, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	git_annotated_commit_free(annotated);
Packit Service 20376f
	git_reference_free(ref);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_index_addall__removes_deleted_conflicted_files(void)
Packit Service 20376f
{
Packit Service 20376f
	git_index *index;
Packit Service 20376f
	git_reference *ref;
Packit Service 20376f
	git_annotated_commit *annotated;
Packit Service 20376f
Packit Service 20376f
	g_repo = cl_git_sandbox_init("merge-resolve");
Packit Service 20376f
	cl_git_pass(git_repository_index(&index, g_repo));
Packit Service 20376f
Packit Service 20376f
	check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch"));
Packit Service 20376f
	cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref));
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_merge(g_repo, (const git_annotated_commit**)&annotated, 1, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1);
Packit Service 20376f
Packit Service 20376f
	cl_git_rmfile("merge-resolve/conflicting.txt");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
Packit Service 20376f
	check_status(g_repo, 0, 2, 2, 0, 0, 0, 0, 0);
Packit Service 20376f
Packit Service 20376f
	git_annotated_commit_free(annotated);
Packit Service 20376f
	git_reference_free(ref);
Packit Service 20376f
	git_index_free(index);
Packit Service 20376f
}