Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6cc5023

Browse files
author
Edward Thomson
committed
index: test that add_bypath preserves symlinks
Test that on platforms without `core.symlinks`, we preserve symlinks in `git_index_add_bypath`. (Users should correct the actual index entry's mode to change a link to a regular file.)
1 parent 6b0fc6a commit 6cc5023

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/index/bypath.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,32 @@ void test_index_bypath__add_honors_conflict_case(void)
328328
cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL);
329329
cl_assert_equal_i(GIT_FILEMODE_BLOB_EXECUTABLE, entry->mode);
330330
}
331+
332+
void test_index_bypath__add_honors_symlink(void)
333+
{
334+
const git_index_entry *entry;
335+
git_index_entry new_entry;
336+
int symlinks;
337+
338+
cl_git_pass(git_repository__cvar(&symlinks, g_repo, GIT_CVAR_SYMLINKS));
339+
340+
if (symlinks)
341+
cl_skip();
342+
343+
cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL);
344+
345+
memcpy(&new_entry, entry, sizeof(git_index_entry));
346+
new_entry.path = "README.txt";
347+
new_entry.mode = GIT_FILEMODE_LINK;
348+
349+
cl_git_pass(git_index_add(g_idx, &new_entry));
350+
cl_git_pass(git_index_write(g_idx));
351+
352+
cl_git_rewritefile("submod2/README.txt", "Modified but still a (fake) symlink");
353+
354+
cl_git_pass(git_index_add_bypath(g_idx, "README.txt"));
355+
cl_git_pass(git_index_write(g_idx));
356+
357+
cl_assert((entry = git_index_get_bypath(g_idx, "README.txt", 0)) != NULL);
358+
cl_assert_equal_i(GIT_FILEMODE_LINK, entry->mode);
359+
}

0 commit comments

Comments
 (0)