summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-06-29 09:58:34 +0200
committerPatrick Steinhardt <ps@pks.im>2019-07-20 19:11:20 +0200
commitded77bb1f18c6cb7a0371b3f66c92387413a161d (patch)
tree44b95bb7a1998304a57b86f9892e92e2da0a2cb6 /tests
parente54343a4024e75dfaa940e652c2c9799d33634b2 (diff)
downloadlibgit2-ded77bb1f18c6cb7a0371b3f66c92387413a161d.tar.gz
path: extract function to check whether a path supports symlinks
When initializing a repository, we need to check whether its working directory supports symlinks to correctly set the initial value of the "core.symlinks" config variable. The code to check the filesystem is reusable in other parts of our codebase, like for example in our tests to determine whether certain tests can be expected to succeed or not. Extract the code into a new function `git_path_supports_symlinks` to avoid duplicate implementations. Remove a duplicate implementation in the repo test helper code.
Diffstat (limited to 'tests')
-rw-r--r--tests/checkout/index.c8
-rw-r--r--tests/repo/init.c4
-rw-r--r--tests/repo/repo_helpers.c15
-rw-r--r--tests/repo/repo_helpers.h1
4 files changed, 6 insertions, 22 deletions
diff --git a/tests/checkout/index.c b/tests/checkout/index.c
index dcacdd5d3..a76c471e8 100644
--- a/tests/checkout/index.c
+++ b/tests/checkout/index.c
@@ -181,7 +181,7 @@ void test_checkout_index__honor_coresymlinks_default_true(void)
cl_must_pass(p_mkdir("symlink", 0777));
- if (!filesystem_supports_symlinks("symlink/test"))
+ if (!git_path_supports_symlinks("symlink/test"))
cl_skip();
#ifdef GIT_WIN32
@@ -214,7 +214,7 @@ void test_checkout_index__honor_coresymlinks_default_false(void)
* supports symlinks. Bail entirely on POSIX platforms that
* do support symlinks.
*/
- if (filesystem_supports_symlinks("symlink/test"))
+ if (git_path_supports_symlinks("symlink/test"))
cl_skip();
#endif
@@ -226,7 +226,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void)
{
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- if (filesystem_supports_symlinks("testrepo/test")) {
+ if (git_path_supports_symlinks("testrepo/test")) {
cl_skip();
}
@@ -242,7 +242,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
char link_data[GIT_PATH_MAX];
size_t link_size = GIT_PATH_MAX;
- if (!filesystem_supports_symlinks("testrepo/test")) {
+ if (!git_path_supports_symlinks("testrepo/test")) {
cl_skip();
}
diff --git a/tests/repo/init.c b/tests/repo/init.c
index 9eee830e2..5a95229e6 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -253,7 +253,7 @@ void test_repo_init__symlinks_win32_enabled_by_global_config(void)
git_config *config, *repo_config;
int val;
- if (!filesystem_supports_symlinks("link"))
+ if (!git_path_supports_symlinks("link"))
cl_skip();
create_tmp_global_config("tmp_global_config", "core.symlinks", "true");
@@ -296,7 +296,7 @@ void test_repo_init__symlinks_posix_detected(void)
cl_skip();
#else
assert_config_entry_on_init(
- "core.symlinks", filesystem_supports_symlinks("link") ? GIT_ENOTFOUND : false);
+ "core.symlinks", git_path_supports_symlinks("link") ? GIT_ENOTFOUND : false);
#endif
}
diff --git a/tests/repo/repo_helpers.c b/tests/repo/repo_helpers.c
index 4256314f1..b22f3f6ba 100644
--- a/tests/repo/repo_helpers.c
+++ b/tests/repo/repo_helpers.c
@@ -21,21 +21,6 @@ void delete_head(git_repository* repo)
git_buf_dispose(&head_path);
}
-int filesystem_supports_symlinks(const char *path)
-{
- struct stat st;
- bool support = 0;
-
- if (p_symlink("target", path) == 0) {
- if (p_lstat(path, &st) == 0 && S_ISLNK(st.st_mode))
- support = 1;
-
- p_unlink(path);
- }
-
- return support;
-}
-
void create_tmp_global_config(const char *dirname, const char *key, const char *val)
{
git_buf path = GIT_BUF_INIT;
diff --git a/tests/repo/repo_helpers.h b/tests/repo/repo_helpers.h
index 2c9aeabee..a93bf36ae 100644
--- a/tests/repo/repo_helpers.h
+++ b/tests/repo/repo_helpers.h
@@ -4,5 +4,4 @@
extern void make_head_unborn(git_repository* repo, const char *target);
extern void delete_head(git_repository* repo);
-extern int filesystem_supports_symlinks(const char *path);
extern void create_tmp_global_config(const char *path, const char *key, const char *val);