]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1004-read-tree-m-u-wf.sh
t1300: put git invocations inside test function
[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
5. ./test-lib.sh
ea5070c9 6. "$TEST_DIRECTORY"/lib-read-tree.sh
ed93b449
JH
7
8# two-tree test
9
10test_expect_success 'two-way setup' '
11
f8a9d428 12 mkdir subdir &&
ed93b449
JH
13 echo >file1 file one &&
14 echo >file2 file two &&
f8a9d428
JH
15 echo >subdir/file1 file one in subdirectory &&
16 echo >subdir/file2 file two in subdirectory &&
17 git update-index --add file1 file2 subdir/file1 subdir/file2 &&
ed93b449
JH
18 git commit -m initial &&
19
20 git branch side &&
21 git tag -f branch-point &&
22
23 echo file2 is not tracked on the master anymore &&
f8a9d428
JH
24 rm -f file2 subdir/file2 &&
25 git update-index --remove file2 subdir/file2 &&
26 git commit -a -m "master removes file2 and subdir/file2"
ed93b449
JH
27'
28
29test_expect_success 'two-way not clobbering' '
30
31 echo >file2 master creates untracked file2 &&
f8a9d428 32 echo >subdir/file2 master creates untracked subdir/file2 &&
ea5070c9 33 if err=`read_tree_u_must_succeed -m -u master side 2>&1`
ed93b449
JH
34 then
35 echo should have complained
36 false
37 else
38 echo "happy to see $err"
39 fi
40'
41
f8a9d428
JH
42echo file2 >.gitignore
43
44test_expect_success 'two-way with incorrect --exclude-per-directory (1)' '
45
ea5070c9 46 if err=`read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1`
f8a9d428
JH
47 then
48 echo should have complained
49 false
50 else
51 echo "happy to see $err"
52 fi
53'
54
55test_expect_success 'two-way with incorrect --exclude-per-directory (2)' '
56
ea5070c9 57 if err=`read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1`
f8a9d428
JH
58 then
59 echo should have complained
60 false
61 else
62 echo "happy to see $err"
63 fi
64'
65
66test_expect_success 'two-way clobbering a ignored file' '
67
ea5070c9 68 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore master side
f8a9d428
JH
69'
70
71rm -f .gitignore
72
ed93b449
JH
73# three-tree test
74
f8a9d428 75test_expect_success 'three-way not complaining on an untracked path in both' '
ed93b449 76
f8a9d428 77 rm -f file2 subdir/file2 &&
ed93b449
JH
78 git checkout side &&
79 echo >file3 file three &&
f8a9d428
JH
80 echo >subdir/file3 file three &&
81 git update-index --add file3 subdir/file3 &&
82 git commit -a -m "side adds file3 and removes file2" &&
ed93b449
JH
83
84 git checkout master &&
85 echo >file2 file two is untracked on the master side &&
f8a9d428 86 echo >subdir/file2 file two is untracked on the master side &&
ed93b449 87
ea5070c9 88 read_tree_u_must_succeed -m -u branch-point master side
ed93b449
JH
89'
90
3dff5379 91test_expect_success 'three-way not clobbering a working tree file' '
f8a9d428
JH
92
93 git reset --hard &&
94 rm -f file2 subdir/file2 file3 subdir/file3 &&
95 git checkout master &&
96 echo >file3 file three created in master, untracked &&
97 echo >subdir/file3 file three created in master, untracked &&
ea5070c9 98 if err=`read_tree_u_must_succeed -m -u branch-point master side 2>&1`
f8a9d428
JH
99 then
100 echo should have complained
101 false
102 else
103 echo "happy to see $err"
104 fi
105'
106
107echo >.gitignore file3
108
109test_expect_success 'three-way not complaining on an untracked file' '
110
111 git reset --hard &&
112 rm -f file2 subdir/file2 file3 subdir/file3 &&
113 git checkout master &&
114 echo >file3 file three created in master, untracked &&
115 echo >subdir/file3 file three created in master, untracked &&
116
ea5070c9 117 read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point master side
f8a9d428
JH
118'
119
7f8ab8dc
LT
120test_expect_success '3-way not overwriting local changes (setup)' '
121
122 git reset --hard &&
123 git checkout -b side-a branch-point &&
124 echo >>file1 "new line to be kept in the merge result" &&
125 git commit -a -m "side-a changes file1" &&
126 git checkout -b side-b branch-point &&
127 echo >>file2 "new line to be kept in the merge result" &&
128 git commit -a -m "side-b changes file2" &&
129 git checkout side-a
130
131'
132
133test_expect_success '3-way not overwriting local changes (our side)' '
134
135 # At this point, file1 from side-a should be kept as side-b
136 # did not touch it.
137
138 git reset --hard &&
139
140 echo >>file1 "local changes" &&
ea5070c9 141 read_tree_u_must_succeed -m -u branch-point side-a side-b &&
7f8ab8dc
LT
142 grep "new line to be kept" file1 &&
143 grep "local changes" file1
144
145'
146
147test_expect_success '3-way not overwriting local changes (their side)' '
148
149 # At this point, file2 from side-b should be taken as side-a
150 # did not touch it.
151
152 git reset --hard &&
153
154 echo >>file2 "local changes" &&
ea5070c9 155 read_tree_u_must_fail -m -u branch-point side-a side-b &&
7f8ab8dc
LT
156 ! grep "new line to be kept" file2 &&
157 grep "local changes" file2
158
159'
160
704a3143 161test_expect_success SYMLINKS 'funny symlink in work tree' '
8a785dc9
JH
162
163 git reset --hard &&
164 git checkout -b sym-b side-b &&
165 mkdir -p a &&
166 >a/b &&
167 git add a/b &&
168 git commit -m "side adds a/b" &&
169
170 rm -fr a &&
171 git checkout -b sym-a side-a &&
172 mkdir -p a &&
173 ln -s ../b a/b &&
174 git add a/b &&
175 git commit -m "we add a/b" &&
176
ea5070c9 177 read_tree_u_must_succeed -m -u sym-a sym-a sym-b
8a785dc9
JH
178
179'
180
c91cfd19 181test_expect_success SYMLINKS,SANITY 'funny symlink in work tree, un-unlink-able' '
8a785dc9
JH
182
183 rm -fr a b &&
184 git reset --hard &&
185
186 git checkout sym-a &&
187 chmod a-w a &&
188 test_must_fail git read-tree -m -u sym-a sym-a sym-b
189
190'
191
192# clean-up from the above test
704a3143 193chmod a+w a 2>/dev/null
8a785dc9
JH
194rm -fr a b
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 (
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"
221 ) >expect &&
222 test_cmp actual expect
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