void test_stash_apply__progress_cb_can_abort(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.progress_cb = aborting_progress_cb; cl_git_fail_with(-44, git_stash_apply(repo, 0, &opts)); }
void test_stash_apply__with_default(void) { cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_stash_apply__calls_progress_cb(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; git_stash_apply_progress_t progress = GIT_STASH_APPLY_PROGRESS_NONE; opts.progress_cb = progress_cb; opts.progress_payload = &progress; cl_git_pass(git_stash_apply(repo, 0, &opts)); cl_assert_equal_i(progress, GIT_STASH_APPLY_PROGRESS_DONE); }
void test_stash_apply__conflict_workdir_with_default(void) { cl_git_rewritefile("stash/what", "ciao\n"); cl_git_fail_with(git_stash_apply(repo, 0, NULL), GIT_ECONFLICT); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_CURRENT); assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_stash_apply__uses_reflog_like_indices_2(void) { git_oid oid; cl_git_mkfile("stash/untracked", "untracked\n"); cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); assert_status(repo, "untracked", GIT_ENOTFOUND); // stash@{0} is the newest stash we made immediately above cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "untracked", GIT_STATUS_WT_NEW); }
void test_stash_apply__conflict_untracked_with_default(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; cl_git_mkfile("stash/when", "nothing\n"); cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_CURRENT); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_CURRENT); assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_stash_apply__with_reinstate_index(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX; cl_git_pass(git_stash_apply(repo, 0, &opts)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_stash_apply__fails_with_uncommitted_changes_in_index(void) { cl_git_rewritefile("stash/who", "nothing\n"); cl_git_pass(git_index_add_bypath(repo_index, "who")); cl_git_pass(git_index_write(repo_index)); cl_git_fail_with(git_stash_apply(repo, 0, NULL), GIT_EUNCOMMITTED); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_CURRENT); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_ENOTFOUND); assert_status(repo, "why", GIT_ENOTFOUND); }
void test_stash_apply__conflict_workdir_with_reinstate_index(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX; cl_git_rewritefile("stash/what", "ciao\n"); cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_CURRENT); assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_stash_apply__merges_new_file(void) { const git_index_entry *ancestor, *our, *their; cl_git_mkfile("stash/where", "committed before stash\n"); cl_git_pass(git_index_add_bypath(repo_index, "where")); cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit"); cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(1, git_index_has_conflicts(repo_index)); assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED); cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "where")); /* unmerged */ assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_STATUS_INDEX_NEW); }
void test_stash_apply__uses_reflog_like_indices_1(void) { git_oid oid; cl_git_mkfile("stash/untracked", "untracked\n"); cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); assert_status(repo, "untracked", GIT_ENOTFOUND); // stash@{1} is the oldest (first) stash we made cl_git_pass(git_stash_apply(repo, 1, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_STATUS_INDEX_NEW); assert_status(repo, "where", GIT_STATUS_INDEX_NEW); }
void test_stash_apply__conflict_index_with_default(void) { const git_index_entry *ancestor; const git_index_entry *our; const git_index_entry *their; cl_git_rewritefile("stash/who", "nothing\n"); cl_git_pass(git_index_add_bypath(repo_index, "who")); cl_git_pass(git_index_write(repo_index)); cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 1); assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "who")); /* unmerged */ assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_stash_apply__conflict_index_with_reinstate_index(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX; cl_git_rewritefile("stash/who", "nothing\n"); cl_git_pass(git_index_add_bypath(repo_index, "who")); cl_git_pass(git_index_write(repo_index)); cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_CURRENT); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_ENOTFOUND); }
void test_stash_apply__with_default(void) { git_buf where = GIT_BUF_INIT; cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_STATUS_INDEX_NEW); assert_status(repo, "where", GIT_STATUS_INDEX_NEW); cl_git_pass(git_futils_readbuffer(&where, "stash/where")); cl_assert_equal_s("....\n", where.ptr); git_buf_free(&where); }
void test_stash_apply__conflict_commit_with_reinstate_index(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; const git_index_entry *ancestor; const git_index_entry *our; const git_index_entry *their; opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX; cl_git_rewritefile("stash/what", "ciao\n"); cl_git_pass(git_index_add_bypath(repo_index, "what")); cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit"); cl_git_pass(git_stash_apply(repo, 0, &opts)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 1); cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "what")); /* unmerged */ assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); }
/** * Apply a single stashed state from the stash list. * * @param repo S3 class git_repository that contains the stash * @param index The index to the stash. 0 is the most recent stash. * @return R_NilValue */ SEXP git2r_stash_apply(SEXP repo, SEXP index) { int error; git_repository *repository = NULL; if (git2r_arg_check_integer_gte_zero(index)) git2r_error(__func__, NULL, "'index'", git2r_err_integer_gte_zero_arg); repository = git2r_repository_open(repo); if (!repository) git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL); error = git_stash_apply(repository, INTEGER(index)[0], NULL); if (error == GIT_ENOTFOUND) error = 0; git_repository_free(repository); if (error) git2r_error(__func__, GIT2R_ERROR_LAST(), NULL, NULL); return R_NilValue; }
void test_stash_apply__executes_notify_cb(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; struct seen_paths seen_paths = {0}; opts.checkout_options.notify_cb = checkout_notify; opts.checkout_options.notify_flags = GIT_CHECKOUT_NOTIFY_ALL; opts.checkout_options.notify_payload = &seen_paths; cl_git_pass(git_stash_apply(repo, 0, &opts)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); cl_assert_equal_b(true, seen_paths.what); cl_assert_equal_b(false, seen_paths.how); cl_assert_equal_b(true, seen_paths.who); cl_assert_equal_b(true, seen_paths.when); }
void test_stash_apply__with_reinstate_index(void) { git_buf where = GIT_BUF_INIT; git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX; cl_git_pass(git_stash_apply(repo, 0, &opts)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_STATUS_INDEX_NEW); assert_status(repo, "where", GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED); cl_git_pass(git_futils_readbuffer(&where, "stash/where")); cl_assert_equal_s("....\n", where.ptr); git_buf_free(&where); }
void test_stash_apply__with_existing_file(void) { cl_git_mkfile("stash/where", "oops!\n"); cl_git_fail(git_stash_apply(repo, 0, NULL)); }