diff options
Diffstat (limited to 'tests/checkout/index.c')
-rw-r--r-- | tests/checkout/index.c | 98 |
1 files changed, 67 insertions, 31 deletions
diff --git a/tests/checkout/index.c b/tests/checkout/index.c index 4d86ba196..65a121d76 100644 --- a/tests/checkout/index.c +++ b/tests/checkout/index.c @@ -5,8 +5,10 @@ #include "fileops.h" #include "repository.h" #include "remote.h" +#include "repo/repo_helpers.h" static git_repository *g_repo; +static git_buf g_global_path = GIT_BUF_INIT; void test_checkout_index__initialize(void) { @@ -22,21 +24,29 @@ void test_checkout_index__initialize(void) cl_git_rewritefile( "./testrepo/.gitattributes", "* text eol=lf\n"); + + git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, + &g_global_path); } void test_checkout_index__cleanup(void) { + git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, + g_global_path.ptr); + git_buf_dispose(&g_global_path); + cl_git_sandbox_cleanup(); - /* try to remove alternative dir */ - if (git_path_isdir("alternative")) - git_futils_rmdir_r("alternative", NULL, GIT_RMDIR_REMOVE_FILES); + /* try to remove directories created by tests */ + cl_fixture_cleanup("alternative"); + cl_fixture_cleanup("symlink"); + cl_fixture_cleanup("symlink.git"); + cl_fixture_cleanup("tmp_global_path"); } void test_checkout_index__cannot_checkout_a_bare_repository(void) { - test_checkout_index__cleanup(); - + cl_git_sandbox_cleanup(); g_repo = cl_git_sandbox_init("testrepo.git"); cl_git_fail(git_checkout_index(g_repo, NULL, NULL)); @@ -136,23 +146,20 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void) #endif } -void test_checkout_index__honor_coresymlinks_default(void) +static void populate_symlink_workdir(void) { git_repository *repo; git_remote *origin; git_object *target; - char cwd[GIT_PATH_MAX]; const char *url = git_repository_path(g_repo); - cl_assert(getcwd(cwd, sizeof(cwd)) != NULL); - cl_assert_equal_i(0, p_mkdir("readonly", 0555)); /* Read-only directory */ - cl_assert_equal_i(0, chdir("readonly")); cl_git_pass(git_repository_init(&repo, "../symlink.git", true)); - cl_assert_equal_i(0, chdir(cwd)); - cl_assert_equal_i(0, p_mkdir("symlink", 0777)); cl_git_pass(git_repository_set_workdir(repo, "symlink", 1)); + /* Delete the `origin` repo (if it exists) so we can recreate it. */ + git_remote_delete(repo, GIT_REMOTE_ORIGIN); + cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url)); cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL)); git_remote_free(origin); @@ -161,23 +168,54 @@ void test_checkout_index__honor_coresymlinks_default(void) cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL)); git_object_free(target); git_repository_free(repo); +} - if (!filesystem_supports_symlinks("symlink/test")) { - check_file_contents("./symlink/link_to_new.txt", "new.txt"); - } else { - char link_data[1024]; - int link_size = 1024; +void test_checkout_index__honor_coresymlinks_default_true(void) +{ + char link_data[GIT_PATH_MAX]; + int link_size = GIT_PATH_MAX; - link_size = p_readlink("./symlink/link_to_new.txt", link_data, link_size); - cl_assert(link_size >= 0); + cl_must_pass(p_mkdir("symlink", 0777)); - link_data[link_size] = '\0'; - cl_assert_equal_i(link_size, strlen("new.txt")); - cl_assert_equal_s(link_data, "new.txt"); - check_file_contents("./symlink/link_to_new.txt", "my new file\n"); - } + if (!filesystem_supports_symlinks("symlink/test")) + cl_skip(); - cl_fixture_cleanup("symlink"); +#ifdef GIT_WIN32 + /* + * Windows explicitly requires the global configuration to have + * core.symlinks=true in addition to actual filesystem support. + */ + create_tmp_global_config("tmp_global_path", "core.symlinks", "true"); +#endif + + populate_symlink_workdir(); + + link_size = p_readlink("./symlink/link_to_new.txt", link_data, link_size); + cl_assert(link_size >= 0); + + link_data[link_size] = '\0'; + cl_assert_equal_i(link_size, strlen("new.txt")); + cl_assert_equal_s(link_data, "new.txt"); + check_file_contents("./symlink/link_to_new.txt", "my new file\n"); +} + +void test_checkout_index__honor_coresymlinks_default_false(void) +{ + cl_must_pass(p_mkdir("symlink", 0777)); + +#ifndef GIT_WIN32 + /* + * This test is largely for Windows platforms to ensure that + * we respect an unset core.symlinks even when the platform + * supports symlinks. Bail entirely on POSIX platforms that + * do support symlinks. + */ + if (filesystem_supports_symlinks("symlink/test")) + cl_skip(); +#endif + + populate_symlink_workdir(); + check_file_contents("./symlink/link_to_new.txt", "new.txt"); } void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void) @@ -558,9 +596,9 @@ void test_checkout_index__can_update_prefixed_files(void) void test_checkout_index__can_checkout_a_newly_initialized_repository(void) { - test_checkout_index__cleanup(); - + cl_git_sandbox_cleanup(); g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt"); cl_git_pass(git_checkout_index(g_repo, NULL, NULL)); @@ -570,8 +608,7 @@ void test_checkout_index__issue_1397(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - test_checkout_index__cleanup(); - + cl_git_sandbox_cleanup(); g_repo = cl_git_sandbox_init("issue_1397"); cl_repo_set_bool(g_repo, "core.autocrlf", true); @@ -624,8 +661,7 @@ void test_checkout_index__target_directory_from_bare(void) checkout_counts cts; memset(&cts, 0, sizeof(cts)); - test_checkout_index__cleanup(); - + cl_git_sandbox_cleanup(); g_repo = cl_git_sandbox_init("testrepo.git"); cl_assert(git_repository_is_bare(g_repo)); |