Skip to content

Commit 628dae8

Browse files
committed
tests: provide symlink support helper function
1 parent df1733d commit 628dae8

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

tests/checkout/index.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,6 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
136136
#endif
137137
}
138138

139-
static bool supports_symlinks(const char *dir)
140-
{
141-
git_buf path = GIT_BUF_INIT;
142-
struct stat st;
143-
bool supports_symlinks = 1;
144-
145-
cl_git_pass(git_buf_joinpath(&path, dir, "test"));
146-
147-
/* see if symlinks are supported in the "symlink" directory */
148-
if (p_symlink("target", path.ptr) < 0 ||
149-
p_lstat(path.ptr, &st) < 0 ||
150-
! (S_ISLNK(st.st_mode)))
151-
supports_symlinks = 0;
152-
153-
git_buf_dispose(&path);
154-
155-
return supports_symlinks;
156-
}
157-
158139
void test_checkout_index__honor_coresymlinks_default(void)
159140
{
160141
git_repository *repo;
@@ -181,7 +162,7 @@ void test_checkout_index__honor_coresymlinks_default(void)
181162
git_object_free(target);
182163
git_repository_free(repo);
183164

184-
if (!supports_symlinks("symlink")) {
165+
if (!filesystem_supports_symlinks("symlink/test")) {
185166
check_file_contents("./symlink/link_to_new.txt", "new.txt");
186167
} else {
187168
char link_data[1024];
@@ -203,7 +184,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void)
203184
{
204185
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
205186

206-
if (supports_symlinks("testrepo")) {
187+
if (filesystem_supports_symlinks("testrepo/test")) {
207188
cl_skip();
208189
}
209190

@@ -219,7 +200,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
219200
char link_data[GIT_PATH_MAX];
220201
size_t link_size = GIT_PATH_MAX;
221202

222-
if (!supports_symlinks("testrepo")) {
203+
if (!filesystem_supports_symlinks("testrepo/test")) {
223204
cl_skip();
224205
}
225206

tests/repo/init.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,8 @@ void test_repo_init__detect_ignorecase(void)
249249

250250
void test_repo_init__detect_symlinks(void)
251251
{
252-
struct stat st;
253-
bool no_symlinks;
254-
255-
no_symlinks = (p_symlink("target", "link") < 0 ||
256-
p_lstat("link", &st) < 0 ||
257-
! (S_ISLNK(st.st_mode)));
258-
259252
assert_config_entry_on_init(
260-
"core.symlinks", no_symlinks ? false : GIT_ENOTFOUND);
253+
"core.symlinks", filesystem_supports_symlinks("link") ? GIT_ENOTFOUND : false);
261254
}
262255

263256
void test_repo_init__detect_precompose_unicode_required(void)

tests/repo/repo_helpers.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ void delete_head(git_repository* repo)
2020

2121
git_buf_dispose(&head_path);
2222
}
23+
24+
int filesystem_supports_symlinks(const char *path)
25+
{
26+
struct stat st;
27+
28+
if (p_symlink("target", path) < 0 ||
29+
p_lstat(path, &st) < 0 ||
30+
!(S_ISLNK(st.st_mode)))
31+
return 0;
32+
33+
return 1;
34+
}

tests/repo/repo_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
extern void make_head_unborn(git_repository* repo, const char *target);
66
extern void delete_head(git_repository* repo);
7+
extern int filesystem_supports_symlinks(const char *path);

0 commit comments

Comments
 (0)