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

Skip to content

Commit f20480a

Browse files
author
Edward Thomson
committed
diff: test "symlinks" in wd are respected on win32
When `core.symlinks = false`, we write the symlinks content (target) to a regular file. We should ensure that when we later see that regular file, we treat it specially - and that changing that regular file would actually change the symlink target. (For compatibility with Git for Windows).
1 parent db1edf9 commit f20480a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/diff/workdir.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,3 +2097,64 @@ void test_diff_workdir__to_index_pathlist(void)
20972097
git_vector_free(&pathlist);
20982098
}
20992099

2100+
void test_diff_workdir__symlink_changed_on_non_symlink_platform(void)
2101+
{
2102+
git_tree *tree;
2103+
git_diff *diff;
2104+
diff_expects exp = {0};
2105+
const git_diff_delta *delta;
2106+
const char *commit = "7fccd7";
2107+
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
2108+
git_vector pathlist = GIT_VECTOR_INIT;
2109+
int symlinks;
2110+
2111+
g_repo = cl_git_sandbox_init("unsymlinked.git");
2112+
2113+
cl_git_pass(git_repository__cvar(&symlinks, g_repo, GIT_CVAR_SYMLINKS));
2114+
2115+
if (symlinks)
2116+
cl_skip();
2117+
2118+
cl_git_pass(git_vector_insert(&pathlist, "include/Nu/Nu.h"));
2119+
2120+
opts.pathspec.strings = (char **)pathlist.contents;
2121+
opts.pathspec.count = pathlist.length;
2122+
2123+
cl_must_pass(p_mkdir("symlink", 0777));
2124+
cl_git_pass(git_repository_set_workdir(g_repo, "symlink", false));
2125+
2126+
cl_assert((tree = resolve_commit_oid_to_tree(g_repo, commit)) != NULL);
2127+
2128+
/* first, do the diff with the original contents */
2129+
2130+
cl_git_pass(git_futils_mkpath2file("symlink/include/Nu/Nu.h", 0755));
2131+
cl_git_mkfile("symlink/include/Nu/Nu.h", "../../objc/Nu.h");
2132+
2133+
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
2134+
cl_assert_equal_i(0, git_diff_num_deltas(diff));
2135+
git_diff_free(diff);
2136+
2137+
/* now update the contents and expect a difference, but that the file
2138+
* mode has persisted as a symbolic link.
2139+
*/
2140+
2141+
cl_git_rewritefile("symlink/include/Nu/Nu.h", "awesome content\n");
2142+
2143+
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
2144+
2145+
cl_git_pass(git_diff_foreach(
2146+
diff, diff_file_cb, diff_binary_cb, diff_hunk_cb, diff_line_cb, &exp));
2147+
cl_assert_equal_i(1, exp.files);
2148+
2149+
cl_assert_equal_i(1, git_diff_num_deltas(diff));
2150+
delta = git_diff_get_delta(diff, 0);
2151+
cl_assert_equal_i(GIT_FILEMODE_LINK, delta->old_file.mode);
2152+
cl_assert_equal_i(GIT_FILEMODE_LINK, delta->new_file.mode);
2153+
2154+
git_diff_free(diff);
2155+
2156+
cl_git_pass(git_futils_rmdir_r("symlink", NULL, GIT_RMDIR_REMOVE_FILES));
2157+
2158+
git_tree_free(tree);
2159+
git_vector_free(&pathlist);
2160+
}

0 commit comments

Comments
 (0)