The eighth batch
[alt-git.git] / t / t1004-read-tree-m-u-wf.sh
blob2b9720b0feb465bb9c4651626c43829ec27cd7b8
1 #!/bin/sh
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
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-read-tree.sh
12 # two-tree test
14 test_expect_success 'two-way setup' '
16 mkdir subdir &&
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 &&
24 git branch side &&
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)
38 then
39 echo should have complained
40 false
41 else
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)
51 then
52 echo should have complained
53 false
54 else
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)
62 then
63 echo should have complained
64 false
65 else
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
75 rm -f .gitignore
77 # three-tree test
79 test_expect_success 'three-way not complaining on an untracked path in both' '
81 rm -f file2 subdir/file2 &&
82 git checkout side &&
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" &&
88 git checkout main &&
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' '
97 git reset --hard &&
98 rm -f file2 subdir/file2 file3 subdir/file3 &&
99 git checkout main &&
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)
103 then
104 echo should have complained
105 false
106 else
107 echo "happy to see $err"
111 echo >.gitignore file3
113 test_expect_success 'three-way not complaining on an untracked file' '
115 git reset --hard &&
116 rm -f file2 subdir/file2 file3 subdir/file3 &&
117 git checkout main &&
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)' '
126 git reset --hard &&
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" &&
133 git checkout side-a
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
140 # did not touch it.
142 git reset --hard &&
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
154 # did not touch it.
156 git reset --hard &&
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' '
167 git reset --hard &&
168 git checkout -b sym-b side-b &&
169 mkdir -p a &&
170 >a/b &&
171 git add a/b &&
172 git commit -m "side adds a/b" &&
174 rm -fr a &&
175 git checkout -b sym-a side-a &&
176 mkdir -p 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" &&
188 rm -fr a b &&
189 git reset --hard &&
191 git checkout sym-a &&
192 chmod a-w a &&
193 test_must_fail git read-tree -m -u sym-a sym-a sym-b
197 test_expect_success 'D/F setup' '
199 git reset --hard &&
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 &&
206 test_tick &&
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"
222 ) >expect &&
223 test_cmp expect actual
227 test_expect_success 'D/F resolve' '
229 git reset --hard &&
230 git checkout side-b &&
231 git merge-resolve branch-point -- side-b side-a
235 test_expect_success 'D/F recursive' '
237 git reset --hard &&
238 git checkout side-b &&
239 git merge-recursive branch-point -- side-b side-a
243 test_done