3 test_description
='merging when a directory was replaced with a symlink'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'create a commit where dir a/b changed to symlink' '
11 mkdir -p a/b/c a/b-2/c &&
20 test_ln_s_add b-2 a/b &&
21 git commit -m "dir to symlink"
24 test_expect_success
'checkout does not clobber untracked symlink' '
25 git checkout HEAD^0 &&
26 git reset --hard main &&
27 git rm --cached a/b &&
28 git commit -m "untracked symlink remains" &&
29 test_must_fail git checkout start^0 &&
30 git clean -fd # Do not leave the untracked symlink in the way
33 test_expect_success
'a/b-2/c/d is kept when clobbering symlink b' '
34 git checkout HEAD^0 &&
35 git reset --hard main &&
36 git rm --cached a/b &&
37 git commit -m "untracked symlink remains" &&
38 git checkout -f start^0 &&
39 test_path_is_file a/b-2/c/d &&
40 git clean -fd # Do not leave the untracked symlink in the way
43 test_expect_success
'checkout should not have deleted a/b-2/c/d' '
44 git checkout HEAD^0 &&
45 git reset --hard main &&
46 git checkout start^0 &&
47 test_path_is_file a/b-2/c/d
50 test_expect_success
'setup for merge test' '
52 test_path_is_file a/b-2/c/d &&
59 test_expect_success
'Handle D/F conflict, do not lose a/b-2/c/d in merge (resolve)' '
61 git checkout baseline^0 &&
62 git merge -s resolve main &&
63 test_path_is_file a/b-2/c/d
66 test_expect_success SYMLINKS
'a/b was resolved as symlink' '
70 test_expect_success
'Handle D/F conflict, do not lose a/b-2/c/d in merge (recursive)' '
72 git checkout baseline^0 &&
73 git merge -s recursive main &&
74 test_path_is_file a/b-2/c/d
77 test_expect_success SYMLINKS
'a/b was resolved as symlink' '
81 test_expect_success
'Handle F/D conflict, do not lose a/b-2/c/d in merge (resolve)' '
83 git checkout main^0 &&
84 git merge -s resolve baseline^0 &&
85 test_path_is_file a/b-2/c/d
88 test_expect_success SYMLINKS
'a/b was resolved as symlink' '
92 test_expect_success
'Handle F/D conflict, do not lose a/b-2/c/d in merge (recursive)' '
94 git checkout main^0 &&
95 git merge -s recursive baseline^0 &&
96 test_path_is_file a/b-2/c/d
99 test_expect_success SYMLINKS
'a/b was resolved as symlink' '
103 test_expect_failure
'do not lose untracked in merge (resolve)' '
105 git checkout baseline^0 &&
107 test_must_fail git merge -s resolve main &&
108 test_path_is_file a/b/c/e &&
109 test_path_is_file a/b-2/c/d
112 test_expect_success
'do not lose untracked in merge (recursive)' '
114 git checkout baseline^0 &&
116 test_must_fail git merge -s recursive main &&
117 test_path_is_file a/b/c/e &&
118 test_path_is_file a/b-2/c/d
121 test_expect_success
'do not lose modifications in merge (resolve)' '
123 git checkout baseline^0 &&
124 echo more content >>a/b/c/d &&
125 test_must_fail git merge -s resolve main
128 test_expect_success
'do not lose modifications in merge (recursive)' '
130 git checkout baseline^0 &&
131 echo more content >>a/b/c/d &&
132 test_must_fail git merge -s recursive main
135 test_expect_success
'setup a merge where dir a/b-2 changed to symlink' '
137 git checkout start^0 &&
140 test_ln_s_add b a/b-2 &&
141 git commit -m "dir a/b-2 to symlink" &&
145 test_expect_success
'merge should not have D/F conflicts (resolve)' '
147 git checkout baseline^0 &&
148 git merge -s resolve test2 &&
149 test_path_is_file a/b/c/d
152 test_expect_success SYMLINKS
'a/b-2 was resolved as symlink' '
156 test_expect_success
'merge should not have D/F conflicts (recursive)' '
158 git checkout baseline^0 &&
159 git merge -s recursive test2 &&
160 test_path_is_file a/b/c/d
163 test_expect_success SYMLINKS
'a/b-2 was resolved as symlink' '
167 test_expect_success
'merge should not have F/D conflicts (recursive)' '
169 git checkout -b foo test2 &&
170 git merge -s recursive baseline^0 &&
171 test_path_is_file a/b/c/d
174 test_expect_success SYMLINKS
'a/b-2 was resolved as symlink' '