3 test_description
='read-tree -m -u checks working tree files'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
10 .
"$TEST_DIRECTORY"/lib-read-tree.sh
14 test_expect_success
'two-way setup' '
17 echo >file1 file one &&
18 echo >file2 file two &&
19 echo >subdir/file1 file one in subdirectory &&
20 echo >subdir/file2 file two in subdirectory &&
21 git update-index --add file1 file2 subdir/file1 subdir/file2 &&
22 git commit -m initial &&
25 git tag -f branch-point &&
27 echo file2 is not tracked on the main branch anymore &&
28 rm -f file2 subdir/file2 &&
29 git update-index --remove file2 subdir/file2 &&
30 git commit -a -m "main removes file2 and subdir/file2"
33 test_expect_success
'two-way not clobbering' '
35 echo >file2 main creates untracked file2 &&
36 echo >subdir/file2 main creates untracked subdir/file2 &&
37 if err=$(read_tree_u_must_succeed -m -u main side 2>&1)
39 echo should have complained
42 echo "happy to see $err"
46 echo file2
>.gitignore
48 test_expect_success
'two-way with incorrect --exclude-per-directory (1)' '
50 if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore main side 2>&1)
52 echo should have complained
55 echo "happy to see $err"
59 test_expect_success
'two-way with incorrect --exclude-per-directory (2)' '
61 if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore main side 2>&1)
63 echo should have complained
66 echo "happy to see $err"
70 test_expect_success
'two-way clobbering a ignored file' '
72 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore main side
79 test_expect_success
'three-way not complaining on an untracked path in both' '
81 rm -f file2 subdir/file2 &&
83 echo >file3 file three &&
84 echo >subdir/file3 file three &&
85 git update-index --add file3 subdir/file3 &&
86 git commit -a -m "side adds file3 and removes file2" &&
89 echo >file2 file two is untracked on the main side &&
90 echo >subdir/file2 file two is untracked on the main side &&
92 read_tree_u_must_succeed -m -u branch-point main side
95 test_expect_success
'three-way not clobbering a working tree file' '
98 rm -f file2 subdir/file2 file3 subdir/file3 &&
100 echo >file3 file three created in main, untracked &&
101 echo >subdir/file3 file three created in main, untracked &&
102 if err=$(read_tree_u_must_succeed -m -u branch-point main side 2>&1)
104 echo should have complained
107 echo "happy to see $err"
111 echo >.gitignore file3
113 test_expect_success
'three-way not complaining on an untracked file' '
116 rm -f file2 subdir/file2 file3 subdir/file3 &&
118 echo >file3 file three created in main, untracked &&
119 echo >subdir/file3 file three created in main, untracked &&
121 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point main side
124 test_expect_success
'3-way not overwriting local changes (setup)' '
127 git checkout -b side-a branch-point &&
128 echo >>file1 "new line to be kept in the merge result" &&
129 git commit -a -m "side-a changes file1" &&
130 git checkout -b side-b branch-point &&
131 echo >>file2 "new line to be kept in the merge result" &&
132 git commit -a -m "side-b changes file2" &&
137 test_expect_success
'3-way not overwriting local changes (our side)' '
139 # At this point, file1 from side-a should be kept as side-b
144 echo >>file1 "local changes" &&
145 read_tree_u_must_succeed -m -u branch-point side-a side-b &&
146 grep "new line to be kept" file1 &&
147 grep "local changes" file1
151 test_expect_success
'3-way not overwriting local changes (their side)' '
153 # At this point, file2 from side-b should be taken as side-a
158 echo >>file2 "local changes" &&
159 read_tree_u_must_fail -m -u branch-point side-a side-b &&
160 ! grep "new line to be kept" file2 &&
161 grep "local changes" file2
165 test_expect_success
'funny symlink in work tree' '
168 git checkout -b sym-b side-b &&
172 git commit -m "side adds a/b" &&
175 git checkout -b sym-a side-a &&
177 test_ln_s_add ../b a/b &&
178 git commit -m "we add a/b" &&
180 read_tree_u_must_succeed -m -u sym-a sym-a sym-b
184 test_expect_success SANITY
'funny symlink in work tree, un-unlink-able' '
186 test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
191 git checkout sym-a &&
193 test_must_fail git read-tree -m -u sym-a sym-a sym-b
197 test_expect_success
'D/F setup' '
201 git checkout side-a &&
202 rm -f subdir/file2 &&
203 mkdir subdir/file2 &&
204 echo qfwfq >subdir/file2/another &&
205 git add subdir/file2/another &&
207 git commit -m "side-a changes file2 to directory"
211 test_expect_success
'D/F' '
213 git checkout side-b &&
214 read_tree_u_must_succeed -m -u branch-point side-b side-a &&
215 git ls-files -u >actual &&
217 a=$(git rev-parse branch-point:subdir/file2) &&
218 b=$(git rev-parse side-a:subdir/file2/another) &&
219 echo "100644 $a 1 subdir/file2" &&
220 echo "100644 $a 2 subdir/file2" &&
221 echo "100644 $b 3 subdir/file2/another"
223 test_cmp expect actual
227 test_expect_success
'D/F resolve' '
230 git checkout side-b &&
231 git merge-resolve branch-point -- side-b side-a
235 test_expect_success
'D/F recursive' '
238 git checkout side-b &&
239 git merge-recursive branch-point -- side-b side-a