Commit 628dae8b by Edward Thomson

tests: provide symlink support helper function

parent df1733de
...@@ -136,25 +136,6 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void) ...@@ -136,25 +136,6 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
#endif #endif
} }
static bool supports_symlinks(const char *dir)
{
git_buf path = GIT_BUF_INIT;
struct stat st;
bool supports_symlinks = 1;
cl_git_pass(git_buf_joinpath(&path, dir, "test"));
/* see if symlinks are supported in the "symlink" directory */
if (p_symlink("target", path.ptr) < 0 ||
p_lstat(path.ptr, &st) < 0 ||
! (S_ISLNK(st.st_mode)))
supports_symlinks = 0;
git_buf_dispose(&path);
return supports_symlinks;
}
void test_checkout_index__honor_coresymlinks_default(void) void test_checkout_index__honor_coresymlinks_default(void)
{ {
git_repository *repo; git_repository *repo;
...@@ -181,7 +162,7 @@ void test_checkout_index__honor_coresymlinks_default(void) ...@@ -181,7 +162,7 @@ void test_checkout_index__honor_coresymlinks_default(void)
git_object_free(target); git_object_free(target);
git_repository_free(repo); git_repository_free(repo);
if (!supports_symlinks("symlink")) { if (!filesystem_supports_symlinks("symlink/test")) {
check_file_contents("./symlink/link_to_new.txt", "new.txt"); check_file_contents("./symlink/link_to_new.txt", "new.txt");
} else { } else {
char link_data[1024]; char link_data[1024];
...@@ -203,7 +184,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void) ...@@ -203,7 +184,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void)
{ {
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
if (supports_symlinks("testrepo")) { if (filesystem_supports_symlinks("testrepo/test")) {
cl_skip(); cl_skip();
} }
...@@ -219,7 +200,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void) ...@@ -219,7 +200,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
char link_data[GIT_PATH_MAX]; char link_data[GIT_PATH_MAX];
size_t link_size = GIT_PATH_MAX; size_t link_size = GIT_PATH_MAX;
if (!supports_symlinks("testrepo")) { if (!filesystem_supports_symlinks("testrepo/test")) {
cl_skip(); cl_skip();
} }
......
...@@ -249,15 +249,8 @@ void test_repo_init__detect_ignorecase(void) ...@@ -249,15 +249,8 @@ void test_repo_init__detect_ignorecase(void)
void test_repo_init__detect_symlinks(void) void test_repo_init__detect_symlinks(void)
{ {
struct stat st;
bool no_symlinks;
no_symlinks = (p_symlink("target", "link") < 0 ||
p_lstat("link", &st) < 0 ||
! (S_ISLNK(st.st_mode)));
assert_config_entry_on_init( assert_config_entry_on_init(
"core.symlinks", no_symlinks ? false : GIT_ENOTFOUND); "core.symlinks", filesystem_supports_symlinks("link") ? GIT_ENOTFOUND : false);
} }
void test_repo_init__detect_precompose_unicode_required(void) void test_repo_init__detect_precompose_unicode_required(void)
......
...@@ -20,3 +20,15 @@ void delete_head(git_repository* repo) ...@@ -20,3 +20,15 @@ void delete_head(git_repository* repo)
git_buf_dispose(&head_path); git_buf_dispose(&head_path);
} }
int filesystem_supports_symlinks(const char *path)
{
struct stat st;
if (p_symlink("target", path) < 0 ||
p_lstat(path, &st) < 0 ||
!(S_ISLNK(st.st_mode)))
return 0;
return 1;
}
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
extern void make_head_unborn(git_repository* repo, const char *target); extern void make_head_unborn(git_repository* repo, const char *target);
extern void delete_head(git_repository* repo); extern void delete_head(git_repository* repo);
extern int filesystem_supports_symlinks(const char *path);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment