Exemple #1
0
void test_reset_hard__resetting_reverts_modified_files(void)
{
	git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
	int i;
	static const char *files[4] = {
		"current_file",
		"modified_file",
		"staged_new_file",
		"staged_changes_modified_file" };
	static const char *before[4] = {
		"current_file\n",
		"modified_file\nmodified_file\n",
		"staged_new_file\n",
		"staged_changes_modified_file\nstaged_changes_modified_file\nstaged_changes_modified_file\n"
	};
	static const char *after[4] = {
		"current_file\n",
		"modified_file\n",
		/* wrong value because reset is still slightly incorrect */
		"staged_new_file\n",
		/* right value: NULL, */
		"staged_changes_modified_file\n"
	};
	const char *wd = git_repository_workdir(repo);

	cl_assert(wd);

	for (i = 0; i < 4; ++i) {
		cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
		cl_git_pass(git_futils_readbuffer(&content, path.ptr));
		cl_assert_equal_s(before[i], content.ptr);
	}

	retrieve_target_from_oid(
		&target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");

	cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));

	for (i = 0; i < 4; ++i) {
		cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
		if (after[i]) {
			cl_git_pass(git_futils_readbuffer(&content, path.ptr));
			cl_assert(strequal_ignore_eol(after[i], content.ptr));
		} else {
			cl_assert(!git_path_exists(path.ptr));
		}
	}

	git_buf_free(&content);
	git_buf_free(&path);
}
Exemple #2
0
void test_reset_hard__resetting_reverts_modified_files(void)
{
    git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
    int i;
    static const char *files[4] = {
        "current_file",
        "modified_file",
        "staged_new_file",
        "staged_changes_modified_file"
    };
    static const char *before[4] = {
        "current_file\n",
        "modified_file\nmodified_file\n",
        "staged_new_file\n",
        "staged_changes_modified_file\nstaged_changes_modified_file\nstaged_changes_modified_file\n"
    };
    static const char *after[4] = {
        "current_file\n",
        "modified_file\n",
        NULL,
        "staged_changes_modified_file\n"
    };
    const char *wd = git_repository_workdir(repo);

    cl_assert(wd);

    for (i = 0; i < 4; ++i) {
        cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
        cl_git_pass(git_futils_readbuffer(&content, path.ptr));
        cl_assert_equal_s(before[i], content.ptr);
    }

    cl_git_pass(git_revparse_single(&target, repo, "26a125e"));

    cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));

    for (i = 0; i < 4; ++i) {
        cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
        if (after[i]) {
            cl_git_pass(git_futils_readbuffer(&content, path.ptr));
            cl_assert(strequal_ignore_eol(after[i], content.ptr));
        } else {
            cl_assert(!git_path_exists(path.ptr));
        }
    }

    git_buf_free(&content);
    git_buf_free(&path);
}