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
9 .
"$TEST_DIRECTORY"/lib-read-tree.sh
13 test_expect_success
'two-way setup' '
16 echo >file1 file one &&
17 echo >file2 file two &&
18 echo >subdir/file1 file one in subdirectory &&
19 echo >subdir/file2 file two in subdirectory &&
20 git update-index --add file1 file2 subdir/file1 subdir/file2 &&
21 git commit -m initial &&
24 git tag -f branch-point &&
26 echo file2 is not tracked on the main branch anymore &&
27 rm -f file2 subdir/file2 &&
28 git update-index --remove file2 subdir/file2 &&
29 git commit -a -m "main removes file2 and subdir/file2"
32 test_expect_success
'two-way not clobbering' '
34 echo >file2 main creates untracked file2 &&
35 echo >subdir/file2 main creates untracked subdir/file2 &&
36 if err=$(read_tree_u_must_succeed -m -u main side 2>&1)
38 echo should have complained
41 echo "happy to see $err"
45 echo file2
>.gitignore
47 test_expect_success
'two-way with incorrect --exclude-per-directory (1)' '
49 if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore main side 2>&1)
51 echo should have complained
54 echo "happy to see $err"
58 test_expect_success
'two-way with incorrect --exclude-per-directory (2)' '
60 if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore main side 2>&1)
62 echo should have complained
65 echo "happy to see $err"
69 test_expect_success
'two-way clobbering a ignored file' '
71 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore main side
78 test_expect_success
'three-way not complaining on an untracked path in both' '
80 rm -f file2 subdir/file2 &&
82 echo >file3 file three &&
83 echo >subdir/file3 file three &&
84 git update-index --add file3 subdir/file3 &&
85 git commit -a -m "side adds file3 and removes file2" &&
88 echo >file2 file two is untracked on the main side &&
89 echo >subdir/file2 file two is untracked on the main side &&
91 read_tree_u_must_succeed -m -u branch-point main side
94 test_expect_success
'three-way not clobbering a working tree file' '
97 rm -f file2 subdir/file2 file3 subdir/file3 &&
99 echo >file3 file three created in main, untracked &&
100 echo >subdir/file3 file three created in main, untracked &&
101 if err=$(read_tree_u_must_succeed -m -u branch-point main side 2>&1)
103 echo should have complained
106 echo "happy to see $err"
110 echo >.gitignore file3
112 test_expect_success
'three-way not complaining on an untracked file' '
115 rm -f file2 subdir/file2 file3 subdir/file3 &&
117 echo >file3 file three created in main, untracked &&
118 echo >subdir/file3 file three created in main, untracked &&
120 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point main side
123 test_expect_success
'3-way not overwriting local changes (setup)' '
126 git checkout -b side-a branch-point &&
127 echo >>file1 "new line to be kept in the merge result" &&
128 git commit -a -m "side-a changes file1" &&
129 git checkout -b side-b branch-point &&
130 echo >>file2 "new line to be kept in the merge result" &&
131 git commit -a -m "side-b changes file2" &&
136 test_expect_success
'3-way not overwriting local changes (our side)' '
138 # At this point, file1 from side-a should be kept as side-b
143 echo >>file1 "local changes" &&
144 read_tree_u_must_succeed -m -u branch-point side-a side-b &&
145 grep "new line to be kept" file1 &&
146 grep "local changes" file1
150 test_expect_success
'3-way not overwriting local changes (their side)' '
152 # At this point, file2 from side-b should be taken as side-a
157 echo >>file2 "local changes" &&
158 read_tree_u_must_fail -m -u branch-point side-a side-b &&
159 ! grep "new line to be kept" file2 &&
160 grep "local changes" file2
164 test_expect_success
'funny symlink in work tree' '
167 git checkout -b sym-b side-b &&
171 git commit -m "side adds a/b" &&
174 git checkout -b sym-a side-a &&
176 test_ln_s_add ../b a/b &&
177 git commit -m "we add a/b" &&
179 read_tree_u_must_succeed -m -u sym-a sym-a sym-b
183 test_expect_success SANITY
'funny symlink in work tree, un-unlink-able' '
185 test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
190 git checkout sym-a &&
192 test_must_fail git read-tree -m -u sym-a sym-a sym-b
196 test_expect_success
'D/F setup' '
200 git checkout side-a &&
201 rm -f subdir/file2 &&
202 mkdir subdir/file2 &&
203 echo qfwfq >subdir/file2/another &&
204 git add subdir/file2/another &&
206 git commit -m "side-a changes file2 to directory"
210 test_expect_success
'D/F' '
212 git checkout side-b &&
213 read_tree_u_must_succeed -m -u branch-point side-b side-a &&
214 git ls-files -u >actual &&
216 a=$(git rev-parse branch-point:subdir/file2) &&
217 b=$(git rev-parse side-a:subdir/file2/another) &&
218 echo "100644 $a 1 subdir/file2" &&
219 echo "100644 $a 2 subdir/file2" &&
220 echo "100644 $b 3 subdir/file2/another"
222 test_cmp expect actual
226 test_expect_success
'D/F resolve' '
229 git checkout side-b &&
230 git merge-resolve branch-point -- side-b side-a
234 test_expect_success
'D/F recursive' '
237 git checkout side-b &&
238 git merge-recursive branch-point -- side-b side-a