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); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); #ifdef GIT_WIN32 test_file_contents("./testrepo/link_to_new.txt", "new.txt"); #else { char link_data[1024]; size_t link_size = 1024; link_size = p_readlink("./testrepo/link_to_new.txt", link_data, link_size); link_data[link_size] = '\0'; cl_assert_equal_i(link_size, strlen("new.txt")); cl_assert_equal_s(link_data, "new.txt"); test_file_contents("./testrepo/link_to_new.txt", "my new file\n"); } #endif }
void test_checkout_index__can_create_missing_files(void) { 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_CREATE_MISSING; cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/README", "hey there\n"); test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n"); test_file_contents("./testrepo/new.txt", "my new file\n"); }
void test_checkout_index__honor_the_gitattributes_directives(void) { const char *attributes = "branch_file.txt text eol=crlf\n" "new.txt text eol=lf\n"; cl_git_mkfile("./testrepo/.gitattributes", attributes); set_core_autocrlf_to(false); cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/README", "hey there\n"); test_file_contents("./testrepo/new.txt", "my new file\n"); test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n"); }
void test_checkout_index__options_disable_filters(void) { cl_git_mkfile("./testrepo/.gitattributes", "*.txt text eol=crlf\n"); g_opts.disable_filters = false; cl_git_pass(git_checkout_index(g_repo, &g_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, &g_opts)); test_file_contents("./testrepo/new.txt", "my new file\n"); }
void test_checkout_index__honor_the_specified_pathspecs(void) { char *entries[] = { "*.txt" }; g_opts.paths.strings = entries; g_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")); cl_git_pass(git_checkout_index(g_repo, &g_opts)); cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n"); test_file_contents("./testrepo/new.txt", "my new file\n"); }
void test_checkout_index__honor_coresymlinks_setting_set_to_false(void) { set_repo_symlink_handling_cap_to(false); cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/link_to_new.txt", "new.txt"); }
void test_checkout_index__can_overwrite_modified_file(void) { cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!"); g_opts.checkout_strategy = GIT_CHECKOUT_OVERWRITE_MODIFIED; cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/new.txt", "my new file\n"); }
void test_checkout_index__donot_overwrite_modified_file_by_default(void) { cl_git_mkfile("./testrepo/new.txt", "This isn't what's stored!"); g_opts.checkout_strategy = 0; cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/new.txt", "This isn't what's stored!"); }
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"; cl_git_mkfile("./testrepo/.gitattributes", attributes); set_core_autocrlf_to(false); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; 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"); test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n"); }
void test_checkout_index__options_open_flags(void) { cl_git_mkfile("./testrepo/new.txt", "hi\n"); g_opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND; g_opts.checkout_strategy |= GIT_CHECKOUT_OVERWRITE_MODIFIED; cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/new.txt", "hi\nmy new file\n"); }
void test_checkout_index__honor_the_specified_pathspecs(void) { git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; char *entries[] = { "*.txt" }; 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")); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; 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"); 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"); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.disable_filters = false; 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"); opts.disable_filters = true; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); test_file_contents("./testrepo/new.txt", "my new file\n"); }
void test_checkout_index__honor_coresymlinks_setting_set_to_true(void) { set_repo_symlink_handling_cap_to(true); cl_git_pass(git_checkout_index(g_repo, &g_opts, NULL)); #ifdef GIT_WIN32 test_file_contents("./testrepo/link_to_new.txt", "new.txt"); #else { char link_data[1024]; size_t link_size = 1024; link_size = p_readlink("./testrepo/link_to_new.txt", link_data, link_size); link_data[link_size] = '\0'; cl_assert_equal_i(link_size, strlen("new.txt")); cl_assert_equal_s(link_data, "new.txt"); test_file_contents("./testrepo/link_to_new.txt", "my new file\n"); } #endif }
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!"); opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); test_file_contents("./testrepo/new.txt", "my new file\n"); }
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); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); test_file_contents("./testrepo/link_to_new.txt", "new.txt"); }
void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void) { #ifdef GIT_WIN32 const char *expected_readme_text = "hey there\r\n"; cl_git_pass(p_unlink("./testrepo/.gitattributes")); set_core_autocrlf_to(true); cl_git_pass(git_checkout_index(g_repo, &g_opts)); test_file_contents("./testrepo/README", expected_readme_text); #endif }
void test_checkout_index__options_open_flags(void) { git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; cl_git_mkfile("./testrepo/new.txt", "hi\n"); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.file_open_flags = O_CREAT | O_RDWR | O_APPEND; 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"); }
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... */ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS; 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__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); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); test_file_contents("./testrepo/README", expected_readme_text); #endif }