]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1004-read-tree-m-u-wf.sh
The third batch
[thirdparty/git.git] / t / t1004-read-tree-m-u-wf.sh
CommitLineData
ed93b449
JH
1#!/bin/sh
2
3test_description='read-tree -m -u checks working tree files'
4
06d53148 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
ed93b449 8. ./test-lib.sh
ea5070c9 9. "$TEST_DIRECTORY"/lib-read-tree.sh
ed93b449
JH
10
11# two-tree test
12
13test_expect_success 'two-way setup' '
14
f8a9d428 15 mkdir subdir &&
ed93b449
JH
16 echo >file1 file one &&
17 echo >file2 file two &&
f8a9d428
JH
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 &&
ed93b449
JH
21 git commit -m initial &&
22
23 git branch side &&
24 git tag -f branch-point &&
25
06d53148 26 echo file2 is not tracked on the main branch anymore &&
f8a9d428
JH
27 rm -f file2 subdir/file2 &&
28 git update-index --remove file2 subdir/file2 &&
06d53148 29 git commit -a -m "main removes file2 and subdir/file2"
ed93b449
JH
30'
31
32test_expect_success 'two-way not clobbering' '
33
06d53148
JS
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)
ed93b449
JH
37 then
38 echo should have complained
39 false
40 else
41 echo "happy to see $err"
42 fi
43'
44
f8a9d428
JH
45echo file2 >.gitignore
46
47test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
48
06d53148 49 if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore main side 2>&1)
f8a9d428
JH
50 then
51 echo should have complained
52 false
53 else
54 echo "happy to see $err"
55 fi
56'
57
58test_expect_success 'two-way with incorrect --exclude-per-directory (2)' '
59
06d53148 60 if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore main side 2>&1)
f8a9d428
JH
61 then
62 echo should have complained
63 false
64 else
65 echo "happy to see $err"
66 fi
67'
68
69test_expect_success 'two-way clobbering a ignored file' '
70
06d53148 71 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore main side
f8a9d428
JH
72'
73
74rm -f .gitignore
75
ed93b449
JH
76# three-tree test
77
f8a9d428 78test_expect_success 'three-way not complaining on an untracked path in both' '
ed93b449 79
f8a9d428 80 rm -f file2 subdir/file2 &&
ed93b449
JH
81 git checkout side &&
82 echo >file3 file three &&
f8a9d428
JH
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" &&
ed93b449 86
06d53148
JS
87 git checkout main &&
88 echo >file2 file two is untracked on the main side &&
89 echo >subdir/file2 file two is untracked on the main side &&
ed93b449 90
06d53148 91 read_tree_u_must_succeed -m -u branch-point main side
ed93b449
JH
92'
93
3dff5379 94test_expect_success 'three-way not clobbering a working tree file' '
f8a9d428
JH
95
96 git reset --hard &&
97 rm -f file2 subdir/file2 file3 subdir/file3 &&
06d53148
JS
98 git checkout main &&
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)
f8a9d428
JH
102 then
103 echo should have complained
104 false
105 else
106 echo "happy to see $err"
107 fi
108'
109
110echo >.gitignore file3
111
112test_expect_success 'three-way not complaining on an untracked file' '
113
114 git reset --hard &&
115 rm -f file2 subdir/file2 file3 subdir/file3 &&
06d53148
JS
116 git checkout main &&
117 echo >file3 file three created in main, untracked &&
118 echo >subdir/file3 file three created in main, untracked &&
f8a9d428 119
06d53148 120 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point main side
f8a9d428
JH
121'
122
7f8ab8dc
LT
123test_expect_success '3-way not overwriting local changes (setup)' '
124
125 git reset --hard &&
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" &&
132 git checkout side-a
133
134'
135
136test_expect_success '3-way not overwriting local changes (our side)' '
137
138 # At this point, file1 from side-a should be kept as side-b
139 # did not touch it.
140
141 git reset --hard &&
142
143 echo >>file1 "local changes" &&
ea5070c9 144 read_tree_u_must_succeed -m -u branch-point side-a side-b &&
7f8ab8dc
LT
145 grep "new line to be kept" file1 &&
146 grep "local changes" file1
147
148'
149
150test_expect_success '3-way not overwriting local changes (their side)' '
151
152 # At this point, file2 from side-b should be taken as side-a
153 # did not touch it.
154
155 git reset --hard &&
156
157 echo >>file2 "local changes" &&
ea5070c9 158 read_tree_u_must_fail -m -u branch-point side-a side-b &&
7f8ab8dc
LT
159 ! grep "new line to be kept" file2 &&
160 grep "local changes" file2
161
162'
163
889c6f0e 164test_expect_success 'funny symlink in work tree' '
8a785dc9
JH
165
166 git reset --hard &&
167 git checkout -b sym-b side-b &&
168 mkdir -p a &&
169 >a/b &&
170 git add a/b &&
171 git commit -m "side adds a/b" &&
172
173 rm -fr a &&
174 git checkout -b sym-a side-a &&
175 mkdir -p a &&
889c6f0e 176 test_ln_s_add ../b a/b &&
8a785dc9
JH
177 git commit -m "we add a/b" &&
178
ea5070c9 179 read_tree_u_must_succeed -m -u sym-a sym-a sym-b
8a785dc9
JH
180
181'
182
889c6f0e 183test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' '
8a785dc9 184
03771425
JH
185 test_when_finished "chmod u+w a 2>/dev/null; rm -fr a b" &&
186
8a785dc9
JH
187 rm -fr a b &&
188 git reset --hard &&
189
190 git checkout sym-a &&
191 chmod a-w a &&
192 test_must_fail git read-tree -m -u sym-a sym-a sym-b
193
194'
195
29dc1331
JH
196test_expect_success 'D/F setup' '
197
198 git reset --hard &&
199
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 &&
205 test_tick &&
206 git commit -m "side-a changes file2 to directory"
207
208'
209
210test_expect_success 'D/F' '
211
212 git checkout side-b &&
ea5070c9 213 read_tree_u_must_succeed -m -u branch-point side-b side-a &&
29dc1331
JH
214 git ls-files -u >actual &&
215 (
f2deabfc
ES
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" &&
29dc1331
JH
220 echo "100644 $b 3 subdir/file2/another"
221 ) >expect &&
9c5b2fab 222 test_cmp expect actual
29dc1331
JH
223
224'
225
226test_expect_success 'D/F resolve' '
227
228 git reset --hard &&
229 git checkout side-b &&
230 git merge-resolve branch-point -- side-b side-a
231
232'
233
234test_expect_success 'D/F recursive' '
235
236 git reset --hard &&
237 git checkout side-b &&
238 git merge-recursive branch-point -- side-b side-a
239
240'
241
ed93b449 242test_done