Blame tests/stash/apply.c

Packit Service 20376f
#include "clar_libgit2.h"
Packit Service 20376f
#include "fileops.h"
Packit Service 20376f
#include "stash_helpers.h"
Packit Service 20376f
Packit Service 20376f
static git_signature *signature;
Packit Service 20376f
static git_repository *repo;
Packit Service 20376f
static git_index *repo_index;
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__initialize(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid oid;
Packit Service 20376f
Packit Service 20376f
	repo = cl_git_sandbox_init_new("stash");
Packit Service 20376f
	cl_git_pass(git_repository_index(&repo_index, repo));
Packit Service 20376f
	cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("stash/what", "hello\n");
Packit Service 20376f
	cl_git_mkfile("stash/how", "small\n");
Packit Service 20376f
	cl_git_mkfile("stash/who", "world\n");
Packit Service 20376f
	cl_git_mkfile("stash/where", "meh\n");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "what"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "how"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "who"));
Packit Service 20376f
Packit Service 20376f
	cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit");
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/what", "goodbye\n");
Packit Service 20376f
	cl_git_rewritefile("stash/who", "funky world\n");
Packit Service 20376f
	cl_git_mkfile("stash/when", "tomorrow\n");
Packit Service 20376f
	cl_git_mkfile("stash/why", "would anybody use stash?\n");
Packit Service 20376f
	cl_git_mkfile("stash/where", "????\n");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "who"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "why"));
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "where"));
Packit Service 20376f
	git_index_write(repo_index);
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/where", "....\n");
Packit Service 20376f
Packit Service 20376f
	/* Pre-stash state */
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
	assert_status(repo, "where", GIT_STATUS_INDEX_NEW|GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
Packit Service 20376f
Packit Service 20376f
	/* Post-stash state */
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "when", GIT_ENOTFOUND);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
	assert_status(repo, "where", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__cleanup(void)
Packit Service 20376f
{
Packit Service 20376f
	git_signature_free(signature);
Packit Service 20376f
	signature = NULL;
Packit Service 20376f
Packit Service 20376f
	git_index_free(repo_index);
Packit Service 20376f
	repo_index = NULL;
Packit Service 20376f
Packit Service 20376f
	cl_git_sandbox_cleanup();
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__with_default(void)
Packit Service 20376f
{
Packit Service 20376f
	git_buf where = GIT_BUF_INIT;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
	assert_status(repo, "where", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
Packit Service 20376f
	cl_assert_equal_s("....\n", where.ptr);
Packit Service 20376f
Packit Service 20376f
	git_buf_free(&where);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__with_existing_file(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_mkfile("stash/where", "oops!\n");
Packit Service 20376f
	cl_git_fail(git_stash_apply(repo, 0, NULL));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__merges_new_file(void)
Packit Service 20376f
{
Packit Service 20376f
	const git_index_entry *ancestor, *our, *their;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("stash/where", "committed before stash\n");
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "where"));
Packit Service 20376f
	cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(1, git_index_has_conflicts(repo_index));
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "where")); /* unmerged */
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__with_reinstate_index(void)
Packit Service 20376f
{
Packit Service 20376f
	git_buf where = GIT_BUF_INIT;
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, &opts));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
	assert_status(repo, "where", GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
Packit Service 20376f
	cl_assert_equal_s("....\n", where.ptr);
Packit Service 20376f
Packit Service 20376f
	git_buf_free(&where);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_index_with_default(void)
Packit Service 20376f
{
Packit Service 20376f
	const git_index_entry *ancestor;
Packit Service 20376f
	const git_index_entry *our;
Packit Service 20376f
	const git_index_entry *their;
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/who", "nothing\n");
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "who"));
Packit Service 20376f
	cl_git_pass(git_index_write(repo_index));
Packit Service 20376f
	cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 1);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "who")); /* unmerged */
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_index_with_reinstate_index(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/who", "nothing\n");
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "who"));
Packit Service 20376f
	cl_git_pass(git_index_write(repo_index));
Packit Service 20376f
	cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "when", GIT_ENOTFOUND);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_untracked_with_default(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("stash/when", "nothing\n");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_untracked_with_reinstate_index(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("stash/when", "nothing\n");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_workdir_with_default(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_rewritefile("stash/what", "ciao\n");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_apply(repo, 0, NULL), GIT_ECONFLICT);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_workdir_with_reinstate_index(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/what", "ciao\n");
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_commit_with_default(void)
Packit Service 20376f
{
Packit Service 20376f
	const git_index_entry *ancestor;
Packit Service 20376f
	const git_index_entry *our;
Packit Service 20376f
	const git_index_entry *their;
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/what", "ciao\n");
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "what"));
Packit Service 20376f
	cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 1);
Packit Service 20376f
	cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "what")); /* unmerged */
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__conflict_commit_with_reinstate_index(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
	const git_index_entry *ancestor;
Packit Service 20376f
	const git_index_entry *our;
Packit Service 20376f
	const git_index_entry *their;
Packit Service 20376f
Packit Service 20376f
	opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
Packit Service 20376f
Packit Service 20376f
	cl_git_rewritefile("stash/what", "ciao\n");
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "what"));
Packit Service 20376f
	cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, &opts));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 1);
Packit Service 20376f
	cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "what")); /* unmerged */
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__fails_with_uncommitted_changes_in_index(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_rewritefile("stash/who", "nothing\n");
Packit Service 20376f
	cl_git_pass(git_index_add_bypath(repo_index, "who"));
Packit Service 20376f
	cl_git_pass(git_index_write(repo_index));
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_apply(repo, 0, NULL), GIT_EUNCOMMITTED);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_ENOTFOUND);
Packit Service 20376f
	assert_status(repo, "why", GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__pop(void)
Packit Service 20376f
{
Packit Service 20376f
	cl_git_pass(git_stash_pop(repo, 0, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(git_stash_pop(repo, 0, NULL), GIT_ENOTFOUND);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
struct seen_paths {
Packit Service 20376f
	bool what;
Packit Service 20376f
	bool how;
Packit Service 20376f
	bool who;
Packit Service 20376f
	bool when;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
int checkout_notify(
Packit Service 20376f
	git_checkout_notify_t why,
Packit Service 20376f
	const char *path,
Packit Service 20376f
	const git_diff_file *baseline,
Packit Service 20376f
	const git_diff_file *target,
Packit Service 20376f
	const git_diff_file *workdir,
Packit Service 20376f
	void *payload)
Packit Service 20376f
{
Packit Service 20376f
	struct seen_paths *seen_paths = (struct seen_paths *)payload;
Packit Service 20376f
Packit Service 20376f
	GIT_UNUSED(why);
Packit Service 20376f
	GIT_UNUSED(baseline);
Packit Service 20376f
	GIT_UNUSED(target);
Packit Service 20376f
	GIT_UNUSED(workdir);
Packit Service 20376f
Packit Service 20376f
	if (strcmp(path, "what") == 0)
Packit Service 20376f
		seen_paths->what = 1;
Packit Service 20376f
	else if (strcmp(path, "how") == 0)
Packit Service 20376f
		seen_paths->how = 1;
Packit Service 20376f
	else if (strcmp(path, "who") == 0)
Packit Service 20376f
		seen_paths->who = 1;
Packit Service 20376f
	else if (strcmp(path, "when") == 0)
Packit Service 20376f
		seen_paths->when = 1;
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__executes_notify_cb(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
	struct seen_paths seen_paths = {0};
Packit Service 20376f
Packit Service 20376f
	opts.checkout_options.notify_cb = checkout_notify;
Packit Service 20376f
	opts.checkout_options.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
Packit Service 20376f
	opts.checkout_options.notify_payload = &seen_paths;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, &opts));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
	assert_status(repo, "where", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_b(true, seen_paths.what);
Packit Service 20376f
	cl_assert_equal_b(false, seen_paths.how);
Packit Service 20376f
	cl_assert_equal_b(true, seen_paths.who);
Packit Service 20376f
	cl_assert_equal_b(true, seen_paths.when);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int progress_cb(
Packit Service 20376f
	git_stash_apply_progress_t progress,
Packit Service 20376f
	void *payload)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_progress_t *p = (git_stash_apply_progress_t *)payload;
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i((*p)+1, progress);
Packit Service 20376f
Packit Service 20376f
	*p = progress;
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__calls_progress_cb(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
	git_stash_apply_progress_t progress = GIT_STASH_APPLY_PROGRESS_NONE;
Packit Service 20376f
Packit Service 20376f
	opts.progress_cb = progress_cb;
Packit Service 20376f
	opts.progress_payload = &progress;
Packit Service 20376f
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, &opts));
Packit Service 20376f
	cl_assert_equal_i(progress, GIT_STASH_APPLY_PROGRESS_DONE);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int aborting_progress_cb(
Packit Service 20376f
	git_stash_apply_progress_t progress,
Packit Service 20376f
	void *payload)
Packit Service 20376f
{
Packit Service 20376f
	GIT_UNUSED(payload);
Packit Service 20376f
Packit Service 20376f
	if (progress == GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED)
Packit Service 20376f
		return -44;
Packit Service 20376f
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__progress_cb_can_abort(void)
Packit Service 20376f
{
Packit Service 20376f
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
Packit Service 20376f
Packit Service 20376f
	opts.progress_cb = aborting_progress_cb;
Packit Service 20376f
Packit Service 20376f
	cl_git_fail_with(-44, git_stash_apply(repo, 0, &opts));
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__uses_reflog_like_indices_1(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid oid;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("stash/untracked", "untracked\n");
Packit Service 20376f
	cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
Packit Service 20376f
	assert_status(repo, "untracked", GIT_ENOTFOUND);
Packit Service 20376f
Packit Service 20376f
	// stash@{1} is the oldest (first) stash we made
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 1, NULL));
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "how", GIT_STATUS_CURRENT);
Packit Service 20376f
	assert_status(repo, "who", GIT_STATUS_WT_MODIFIED);
Packit Service 20376f
	assert_status(repo, "when", GIT_STATUS_WT_NEW);
Packit Service 20376f
	assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
	assert_status(repo, "where", GIT_STATUS_INDEX_NEW);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
void test_stash_apply__uses_reflog_like_indices_2(void)
Packit Service 20376f
{
Packit Service 20376f
	git_oid oid;
Packit Service 20376f
Packit Service 20376f
	cl_git_mkfile("stash/untracked", "untracked\n");
Packit Service 20376f
	cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
Packit Service 20376f
	assert_status(repo, "untracked", GIT_ENOTFOUND);
Packit Service 20376f
Packit Service 20376f
	// stash@{0} is the newest stash we made immediately above
Packit Service 20376f
	cl_git_pass(git_stash_apply(repo, 0, NULL));
Packit Service 20376f
Packit Service 20376f
	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
Packit Service 20376f
	assert_status(repo, "untracked", GIT_STATUS_WT_NEW);
Packit Service 20376f
}