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