summaryrefslogtreecommitdiff
path: root/tests-clar/checkout/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/checkout/index.c')
-rw-r--r--tests-clar/checkout/index.c187
1 files changed, 105 insertions, 82 deletions
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index d42b69e23..b1778a422 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -4,7 +4,6 @@
#include "repository.h"
static git_repository *g_repo;
-static git_checkout_opts g_opts;
static void reset_index_to_treeish(git_object *treeish)
{
@@ -25,8 +24,6 @@ void test_checkout_index__initialize(void)
{
git_tree *tree;
- GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
-
g_repo = cl_git_sandbox_init("testrepo");
cl_git_pass(git_repository_head_tree(&tree, g_repo));
@@ -65,7 +62,6 @@ void test_checkout_index__cannot_checkout_a_bare_repository(void)
{
test_checkout_index__cleanup();
- GIT_INIT_STRUCTURE(&g_opts, GIT_CHECKOUT_OPTS_VERSION);
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_fail(git_checkout_index(g_repo, NULL, NULL));
@@ -73,13 +69,15 @@ void test_checkout_index__cannot_checkout_a_bare_repository(void)
void test_checkout_index__can_create_missing_files(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/README", "hey there\n");
test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
@@ -88,34 +86,37 @@ void test_checkout_index__can_create_missing_files(void)
void test_checkout_index__can_remove_untracked_files(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
git_futils_mkdir("./testrepo/dir/subdir/subsubdir", NULL, 0755, GIT_MKDIR_PATH);
cl_git_mkfile("./testrepo/dir/one", "one\n");
cl_git_mkfile("./testrepo/dir/subdir/two", "two\n");
cl_assert_equal_i(true, git_path_isdir("./testrepo/dir/subdir/subsubdir"));
- g_opts.checkout_strategy =
+ opts.checkout_strategy =
GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_assert_equal_i(false, git_path_isdir("./testrepo/dir"));
}
void test_checkout_index__honor_the_specified_pathspecs(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
char *entries[] = { "*.txt" };
- g_opts.paths.strings = entries;
- g_opts.paths.count = 1;
+ opts.paths.strings = entries;
+ opts.paths.count = 1;
cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt"));
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
@@ -139,6 +140,7 @@ static void set_core_autocrlf_to(bool value)
void test_checkout_index__honor_the_gitattributes_directives(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
const char *attributes =
"branch_file.txt text eol=crlf\n"
"new.txt text eol=lf\n";
@@ -146,9 +148,9 @@ void test_checkout_index__honor_the_gitattributes_directives(void)
cl_git_mkfile("./testrepo/.gitattributes", attributes);
set_core_autocrlf_to(false);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/README", "hey there\n");
test_file_contents("./testrepo/new.txt", "my new file\n");
@@ -158,14 +160,15 @@ void test_checkout_index__honor_the_gitattributes_directives(void)
void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
{
#ifdef GIT_WIN32
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
const char *expected_readme_text = "hey there\r\n";
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
set_core_autocrlf_to(true);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/README", expected_readme_text);
#endif
@@ -178,11 +181,13 @@ static void set_repo_symlink_handling_cap_to(bool value)
void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
set_repo_symlink_handling_cap_to(true);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
#ifdef GIT_WIN32
test_file_contents("./testrepo/link_to_new.txt", "new.txt");
@@ -202,55 +207,63 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
set_repo_symlink_handling_cap_to(false);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/link_to_new.txt", "new.txt");
}
void test_checkout_index__donot_overwrite_modified_file_by_default(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
/* set this up to not return an error code on conflicts, but it
* still will not have permission to overwrite anything...
*/
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/new.txt", "This isn't what's stored!");
}
void test_checkout_index__can_overwrite_modified_file(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
- g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/new.txt", "my new file\n");
}
void test_checkout_index__options_disable_filters(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
cl_git_mkfile("./testrepo/.gitattributes", "*.txt text eol=crlf\n");
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- g_opts.disable_filters = false;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.disable_filters = false;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/new.txt", "my new file\r\n");
p_unlink("./testrepo/new.txt");
- g_opts.disable_filters = true;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ opts.disable_filters = true;
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/new.txt", "my new file\n");
}
@@ -258,6 +271,7 @@ void test_checkout_index__options_disable_filters(void)
void test_checkout_index__options_dir_modes(void)
{
#ifndef GIT_WIN32
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
git_oid oid;
git_commit *commit;
@@ -267,10 +281,10 @@ void test_checkout_index__options_dir_modes(void)
reset_index_to_treeish((git_object *)commit);
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- g_opts.dir_mode = 0701;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.dir_mode = 0701;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_git_pass(p_stat("./testrepo/a", &st));
cl_assert_equal_i(st.st_mode & 0777, 0701);
@@ -286,12 +300,13 @@ void test_checkout_index__options_dir_modes(void)
void test_checkout_index__options_override_file_modes(void)
{
#ifndef GIT_WIN32
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- g_opts.file_mode = 0700;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.file_mode = 0700;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_git_pass(p_stat("./testrepo/new.txt", &st));
cl_assert_equal_i(st.st_mode & 0777, 0700);
@@ -300,13 +315,15 @@ void test_checkout_index__options_override_file_modes(void)
void test_checkout_index__options_open_flags(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
cl_git_mkfile("./testrepo/new.txt", "hi\n");
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- g_opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND;
- g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
test_file_contents("./testrepo/new.txt", "hi\nmy new file\n");
}
@@ -316,28 +333,29 @@ struct notify_data {
const char *sha;
};
-static int notify_cb(
- const char *file,
- unsigned int status,
- const git_oid *blob_oid,
- unsigned int checkout_mode,
- unsigned int workdir_mode,
+static int test_checkout_notify_cb(
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *baseline,
+ const git_diff_file *target,
+ const git_diff_file *workdir,
void *payload)
{
struct notify_data *expectations = (struct notify_data *)payload;
- GIT_UNUSED(checkout_mode);
- GIT_UNUSED(workdir_mode);
- GIT_UNUSED(status);
+ GIT_UNUSED(workdir);
- cl_assert_equal_s(expectations->file, file);
- cl_assert_equal_i(0, git_oid_streq(blob_oid, expectations->sha));
+ cl_assert_equal_i(GIT_CHECKOUT_NOTIFY_CONFLICT, why);
+ cl_assert_equal_s(expectations->file, path);
+ cl_assert_equal_i(0, git_oid_streq(&baseline->oid, expectations->sha));
+ cl_assert_equal_i(0, git_oid_streq(&target->oid, expectations->sha));
return 0;
}
void test_checkout_index__can_notify_of_skipped_files(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct notify_data data;
cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!");
@@ -351,28 +369,28 @@ void test_checkout_index__can_notify_of_skipped_files(void)
data.file = "new.txt";
data.sha = "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd";
- g_opts.checkout_strategy =
+ opts.checkout_strategy =
GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- g_opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICTS;
- g_opts.notify_cb = notify_cb;
- g_opts.notify_payload = &data;
+ opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
+ opts.notify_cb = test_checkout_notify_cb;
+ opts.notify_payload = &data;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
}
static int dont_notify_cb(
- const char *file,
- unsigned int status,
- const git_oid *blob_oid,
- unsigned int checkout_mode,
- unsigned int workdir_mode,
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *baseline,
+ const git_diff_file *target,
+ const git_diff_file *workdir,
void *payload)
{
- GIT_UNUSED(file);
- GIT_UNUSED(status);
- GIT_UNUSED(blob_oid);
- GIT_UNUSED(checkout_mode);
- GIT_UNUSED(workdir_mode);
+ GIT_UNUSED(why);
+ GIT_UNUSED(path);
+ GIT_UNUSED(baseline);
+ GIT_UNUSED(target);
+ GIT_UNUSED(workdir);
GIT_UNUSED(payload);
cl_assert(false);
@@ -382,18 +400,20 @@ static int dont_notify_cb(
void test_checkout_index__wont_notify_of_expected_line_ending_changes(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+
cl_git_pass(p_unlink("./testrepo/.gitattributes"));
set_core_autocrlf_to(true);
cl_git_mkfile("./testrepo/new.txt", "my new file\r\n");
- g_opts.checkout_strategy =
+ opts.checkout_strategy =
GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- g_opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICTS;
- g_opts.notify_cb = dont_notify_cb;
- g_opts.notify_payload = NULL;
+ opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
+ opts.notify_cb = dont_notify_cb;
+ opts.notify_payload = NULL;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
}
static void checkout_progress_counter(
@@ -405,18 +425,20 @@ static void checkout_progress_counter(
void test_checkout_index__calls_progress_callback(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
int calls = 0;
- g_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
- g_opts.progress_cb = checkout_progress_counter;
- g_opts.progress_payload = &calls;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+ opts.progress_cb = checkout_progress_counter;
+ opts.progress_payload = &calls;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_assert(calls > 0);
}
void test_checkout_index__can_overcome_name_clashes(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
git_index *index;
cl_git_pass(git_repository_index(&index, g_repo));
@@ -440,15 +462,15 @@ void test_checkout_index__can_overcome_name_clashes(void)
cl_assert(git_path_isfile("./testrepo/path1"));
cl_assert(git_path_isfile("./testrepo/path0/file0"));
- g_opts.checkout_strategy =
+ opts.checkout_strategy =
GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_ALLOW_CONFLICTS;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_pass(git_checkout_index(g_repo, index, &opts));
cl_assert(git_path_isfile("./testrepo/path1"));
cl_assert(git_path_isfile("./testrepo/path0/file0"));
- g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_checkout_index(g_repo, NULL, &g_opts));
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_checkout_index(g_repo, index, &opts));
cl_assert(git_path_isfile("./testrepo/path0"));
cl_assert(git_path_isfile("./testrepo/path1/file1"));
@@ -458,17 +480,18 @@ void test_checkout_index__can_overcome_name_clashes(void)
void test_checkout_index__validates_struct_version(void)
{
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
const git_error *err;
- g_opts.version = 1024;
- cl_git_fail(git_checkout_index(g_repo, NULL, &g_opts));
+ opts.version = 1024;
+ cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
err = giterr_last();
cl_assert_equal_i(err->klass, GITERR_INVALID);
- g_opts.version = 0;
+ opts.version = 0;
giterr_clear();
- cl_git_fail(git_checkout_index(g_repo, NULL, &g_opts));
+ cl_git_fail(git_checkout_index(g_repo, NULL, &opts));
err = giterr_last();
cl_assert_equal_i(err->klass, GITERR_INVALID);