]>
Commit | Line | Data |
---|---|---|
ad8e72cb JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Johannes E. Schindelin | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git rerere |
f7314882 JN |
7 | |
8 | ! [fifth] version1 | |
9 | ! [first] first | |
10 | ! [fourth] version1 | |
11 | ! [master] initial | |
12 | ! [second] prefer first over second | |
13 | ! [third] version2 | |
14 | ------ | |
15 | + [third] version2 | |
16 | + [fifth] version1 | |
17 | + [fourth] version1 | |
18 | + + + [third^] third | |
19 | - [second] prefer first over second | |
20 | + + [first] first | |
21 | + [second^] second | |
22 | ++++++ [master] initial | |
ad8e72cb JS |
23 | ' |
24 | ||
25 | . ./test-lib.sh | |
26 | ||
f7314882 JN |
27 | test_expect_success 'setup' ' |
28 | cat >a1 <<-\EOF && | |
4a45f7dd BG |
29 | Some title |
30 | ========== | |
f7314882 | 31 | Whether '\''tis nobler in the mind to suffer |
4a45f7dd BG |
32 | The slings and arrows of outrageous fortune, |
33 | Or to take arms against a sea of troubles, | |
34 | And by opposing end them? To die: to sleep; | |
35 | No more; and by a sleep to say we end | |
36 | The heart-ache and the thousand natural shocks | |
f7314882 JN |
37 | That flesh is heir to, '\''tis a consummation |
38 | Devoutly to be wish'\''d. | |
4a45f7dd | 39 | EOF |
ad8e72cb | 40 | |
4a45f7dd | 41 | git add a1 && |
f7314882 | 42 | test_tick && |
4a45f7dd | 43 | git commit -q -a -m initial && |
ad8e72cb | 44 | |
f7314882 | 45 | cat >>a1 <<-\EOF && |
4a45f7dd BG |
46 | Some title |
47 | ========== | |
48 | To die, to sleep; | |
f7314882 | 49 | To sleep: perchance to dream: ay, there'\''s the rub; |
4a45f7dd BG |
50 | For in that sleep of death what dreams may come |
51 | When we have shuffled off this mortal coil, | |
f7314882 | 52 | Must give us pause: there'\''s the respect |
4a45f7dd BG |
53 | That makes calamity of so long life; |
54 | EOF | |
f7314882 JN |
55 | |
56 | git checkout -b first && | |
57 | test_tick && | |
4a45f7dd | 58 | git commit -q -a -m first && |
ad8e72cb | 59 | |
4a45f7dd BG |
60 | git checkout -b second master && |
61 | git show first:a1 | | |
f7314882 JN |
62 | sed -e "s/To die, t/To die! T/" -e "s/Some title/Some Title/" >a1 && |
63 | echo "* END *" >>a1 && | |
64 | test_tick && | |
4a45f7dd | 65 | git commit -q -a -m second |
f7314882 | 66 | ' |
ad8e72cb | 67 | |
b4372ef1 | 68 | test_expect_success 'nothing recorded without rerere' ' |
f7314882 JN |
69 | rm -rf .git/rr-cache && |
70 | git config rerere.enabled false && | |
d492b31c | 71 | test_must_fail git merge first && |
b4372ef1 JS |
72 | ! test -d .git/rr-cache |
73 | ' | |
ad8e72cb | 74 | |
f7314882 | 75 | test_expect_success 'activate rerere, old style (conflicting merge)' ' |
b4372ef1 JS |
76 | git reset --hard && |
77 | mkdir .git/rr-cache && | |
f7314882 JN |
78 | test_might_fail git config --unset rerere.enabled && |
79 | test_must_fail git merge first && | |
ad8e72cb | 80 | |
7096b648 | 81 | sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) && |
f7314882 JN |
82 | rr=.git/rr-cache/$sha1 && |
83 | grep "^=======\$" $rr/preimage && | |
84 | ! test -f $rr/postimage && | |
85 | ! test -f $rr/thisimage | |
86 | ' | |
ad8e72cb | 87 | |
b4372ef1 JS |
88 | test_expect_success 'rerere.enabled works, too' ' |
89 | rm -rf .git/rr-cache && | |
90 | git config rerere.enabled true && | |
91 | git reset --hard && | |
d492b31c | 92 | test_must_fail git merge first && |
f7314882 | 93 | |
7096b648 | 94 | sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) && |
f7314882 | 95 | rr=.git/rr-cache/$sha1 && |
99d698f1 | 96 | grep ^=======$ $rr/preimage |
b4372ef1 JS |
97 | ' |
98 | ||
f7314882 JN |
99 | test_expect_success 'set up rr-cache' ' |
100 | rm -rf .git/rr-cache && | |
101 | git config rerere.enabled true && | |
102 | git reset --hard && | |
103 | test_must_fail git merge first && | |
7096b648 | 104 | sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) && |
f7314882 JN |
105 | rr=.git/rr-cache/$sha1 |
106 | ' | |
ad8e72cb | 107 | |
f7314882 JN |
108 | test_expect_success 'rr-cache looks sane' ' |
109 | # no postimage or thisimage yet | |
110 | ! test -f $rr/postimage && | |
111 | ! test -f $rr/thisimage && | |
eb335966 | 112 | |
f7314882 | 113 | # preimage has right number of lines |
eb335966 | 114 | cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) && |
f7314882 | 115 | echo $cnt && |
99d698f1 | 116 | test $cnt = 13 |
eb335966 JH |
117 | ' |
118 | ||
f7314882 JN |
119 | test_expect_success 'rerere diff' ' |
120 | git show first:a1 >a1 && | |
121 | cat >expect <<-\EOF && | |
122 | --- a/a1 | |
123 | +++ b/a1 | |
124 | @@ -1,4 +1,4 @@ | |
125 | -Some Title | |
126 | +Some title | |
127 | ========== | |
128 | Whether '\''tis nobler in the mind to suffer | |
129 | The slings and arrows of outrageous fortune, | |
130 | @@ -8,21 +8,11 @@ | |
131 | The heart-ache and the thousand natural shocks | |
132 | That flesh is heir to, '\''tis a consummation | |
133 | Devoutly to be wish'\''d. | |
134 | -<<<<<<< | |
135 | -Some Title | |
136 | -========== | |
137 | -To die! To sleep; | |
138 | -======= | |
139 | Some title | |
140 | ========== | |
141 | To die, to sleep; | |
142 | ->>>>>>> | |
143 | To sleep: perchance to dream: ay, there'\''s the rub; | |
144 | For in that sleep of death what dreams may come | |
145 | When we have shuffled off this mortal coil, | |
146 | Must give us pause: there'\''s the respect | |
147 | That makes calamity of so long life; | |
148 | -<<<<<<< | |
149 | -======= | |
150 | -* END * | |
151 | ->>>>>>> | |
152 | EOF | |
153 | git rerere diff >out && | |
154 | test_cmp expect out | |
52aaf649 | 155 | ' |
ad8e72cb | 156 | |
f7314882 JN |
157 | test_expect_success 'rerere status' ' |
158 | echo a1 >expect && | |
159 | git rerere status >out && | |
160 | test_cmp expect out | |
7d7ff15b SG |
161 | ' |
162 | ||
f7314882 JN |
163 | test_expect_success 'first postimage wins' ' |
164 | git show first:a1 | sed "s/To die: t/To die! T/" >expect && | |
ad8e72cb | 165 | |
f7314882 JN |
166 | git commit -q -a -m "prefer first over second" && |
167 | test -f $rr/postimage && | |
ad8e72cb | 168 | |
8aed4a5e | 169 | oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) && |
ad8e72cb | 170 | |
f7314882 JN |
171 | git checkout -b third master && |
172 | git show second^:a1 | sed "s/To die: t/To die! T/" >a1 && | |
173 | git commit -q -a -m third && | |
ad8e72cb | 174 | |
f7314882 JN |
175 | test_must_fail git pull . first && |
176 | # rerere kicked in | |
177 | ! grep "^=======\$" a1 && | |
178 | test_cmp expect a1 | |
179 | ' | |
ad8e72cb | 180 | |
8aed4a5e JH |
181 | test_expect_success 'rerere updates postimage timestamp' ' |
182 | newmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) && | |
183 | test $oldmtimepost -lt $newmtimepost | |
184 | ' | |
56cf9806 | 185 | |
f7314882 JN |
186 | test_expect_success 'rerere clear' ' |
187 | rm $rr/postimage && | |
7096b648 | 188 | echo "$sha1 a1" | "$PERL_PATH" -pe "y/\012/\000/" >.git/MERGE_RR && |
f7314882 JN |
189 | git rerere clear && |
190 | ! test -d $rr | |
191 | ' | |
56cf9806 | 192 | |
f7314882 JN |
193 | test_expect_success 'set up for garbage collection tests' ' |
194 | mkdir -p $rr && | |
195 | echo Hello >$rr/preimage && | |
196 | echo World >$rr/postimage && | |
56cf9806 | 197 | |
f7314882 JN |
198 | sha2=4000000000000000000000000000000000000000 && |
199 | rr2=.git/rr-cache/$sha2 && | |
200 | mkdir $rr2 && | |
201 | echo Hello >$rr2/preimage && | |
56cf9806 | 202 | |
f7314882 JN |
203 | almost_15_days_ago=$((60-15*86400)) && |
204 | just_over_15_days_ago=$((-1-15*86400)) && | |
205 | almost_60_days_ago=$((60-60*86400)) && | |
206 | just_over_60_days_ago=$((-1-60*86400)) && | |
56cf9806 | 207 | |
8aed4a5e JH |
208 | test-chmtime =$just_over_60_days_ago $rr/preimage && |
209 | test-chmtime =$almost_60_days_ago $rr/postimage && | |
f7314882 JN |
210 | test-chmtime =$almost_15_days_ago $rr2/preimage |
211 | ' | |
56cf9806 | 212 | |
8aed4a5e | 213 | test_expect_success 'gc preserves young or recently used records' ' |
f7314882 JN |
214 | git rerere gc && |
215 | test -f $rr/preimage && | |
216 | test -f $rr2/preimage | |
217 | ' | |
ad8e72cb | 218 | |
f7314882 | 219 | test_expect_success 'old records rest in peace' ' |
8aed4a5e | 220 | test-chmtime =$just_over_60_days_ago $rr/postimage && |
f7314882 JN |
221 | test-chmtime =$just_over_15_days_ago $rr2/preimage && |
222 | git rerere gc && | |
223 | ! test -f $rr/preimage && | |
224 | ! test -f $rr2/preimage | |
225 | ' | |
ad8e72cb | 226 | |
f7314882 | 227 | test_expect_success 'setup: file2 added differently in two branches' ' |
52aaf649 | 228 | git reset --hard && |
f7314882 | 229 | |
52aaf649 | 230 | git checkout -b fourth && |
f7314882 | 231 | echo Hallo >file2 && |
52aaf649 | 232 | git add file2 && |
f7314882 | 233 | test_tick && |
52aaf649 | 234 | git commit -m version1 && |
f7314882 | 235 | |
52aaf649 | 236 | git checkout third && |
f7314882 | 237 | echo Bello >file2 && |
52aaf649 | 238 | git add file2 && |
f7314882 | 239 | test_tick && |
52aaf649 | 240 | git commit -m version2 && |
f7314882 | 241 | |
d492b31c | 242 | test_must_fail git merge fourth && |
f7314882 | 243 | echo Cello >file2 && |
52aaf649 JS |
244 | git add file2 && |
245 | git commit -m resolution | |
246 | ' | |
247 | ||
248 | test_expect_success 'resolution was recorded properly' ' | |
f7314882 JN |
249 | echo Cello >expected && |
250 | ||
52aaf649 JS |
251 | git reset --hard HEAD~2 && |
252 | git checkout -b fifth && | |
f7314882 JN |
253 | |
254 | echo Hallo >file3 && | |
52aaf649 | 255 | git add file3 && |
f7314882 | 256 | test_tick && |
52aaf649 | 257 | git commit -m version1 && |
f7314882 | 258 | |
52aaf649 | 259 | git checkout third && |
f7314882 | 260 | echo Bello >file3 && |
52aaf649 | 261 | git add file3 && |
f7314882 | 262 | test_tick && |
52aaf649 | 263 | git commit -m version2 && |
121c813f | 264 | git tag version2 && |
f7314882 | 265 | |
7f8365f8 | 266 | test_must_fail git merge fifth && |
f7314882 JN |
267 | test_cmp expected file3 && |
268 | test_must_fail git update-index --refresh | |
52aaf649 JS |
269 | ' |
270 | ||
121c813f | 271 | test_expect_success 'rerere.autoupdate' ' |
f7314882 | 272 | git config rerere.autoupdate true && |
121c813f JH |
273 | git reset --hard && |
274 | git checkout version2 && | |
275 | test_must_fail git merge fifth && | |
f7314882 | 276 | git update-index --refresh |
cb6020bb | 277 | ' |
121c813f | 278 | |
cb6020bb | 279 | test_expect_success 'merge --rerere-autoupdate' ' |
f7314882 | 280 | test_might_fail git config --unset rerere.autoupdate && |
cb6020bb JH |
281 | git reset --hard && |
282 | git checkout version2 && | |
283 | test_must_fail git merge --rerere-autoupdate fifth && | |
f7314882 | 284 | git update-index --refresh |
cb6020bb JH |
285 | ' |
286 | ||
287 | test_expect_success 'merge --no-rerere-autoupdate' ' | |
f7314882 JN |
288 | headblob=$(git rev-parse version2:file3) && |
289 | mergeblob=$(git rev-parse fifth:file3) && | |
290 | cat >expected <<-EOF && | |
291 | 100644 $headblob 2 file3 | |
292 | 100644 $mergeblob 3 file3 | |
293 | EOF | |
294 | ||
295 | git config rerere.autoupdate true && | |
cb6020bb JH |
296 | git reset --hard && |
297 | git checkout version2 && | |
298 | test_must_fail git merge --no-rerere-autoupdate fifth && | |
f7314882 JN |
299 | git ls-files -u >actual && |
300 | test_cmp expected actual | |
121c813f JH |
301 | ' |
302 | ||
672d1b78 JN |
303 | test_expect_success 'set up an unresolved merge' ' |
304 | headblob=$(git rev-parse version2:file3) && | |
305 | mergeblob=$(git rev-parse fifth:file3) && | |
306 | cat >expected.unresolved <<-EOF && | |
307 | 100644 $headblob 2 file3 | |
308 | 100644 $mergeblob 3 file3 | |
309 | EOF | |
310 | ||
311 | test_might_fail git config --unset rerere.autoupdate && | |
312 | git reset --hard && | |
313 | git checkout version2 && | |
314 | fifth=$(git rev-parse fifth) && | |
315 | echo "$fifth branch 'fifth' of ." | | |
316 | git fmt-merge-msg >msg && | |
317 | ancestor=$(git merge-base version2 fifth) && | |
318 | test_must_fail git merge-recursive "$ancestor" -- HEAD fifth && | |
319 | ||
320 | git ls-files --stage >failedmerge && | |
321 | cp file3 file3.conflict && | |
322 | ||
323 | git ls-files -u >actual && | |
324 | test_cmp expected.unresolved actual | |
325 | ' | |
326 | ||
327 | test_expect_success 'explicit rerere' ' | |
328 | test_might_fail git config --unset rerere.autoupdate && | |
329 | git rm -fr --cached . && | |
330 | git update-index --index-info <failedmerge && | |
331 | cp file3.conflict file3 && | |
332 | test_must_fail git update-index --refresh -q && | |
333 | ||
334 | git rerere && | |
335 | git ls-files -u >actual && | |
336 | test_cmp expected.unresolved actual | |
337 | ' | |
338 | ||
339 | test_expect_success 'explicit rerere with autoupdate' ' | |
340 | git config rerere.autoupdate true && | |
341 | git rm -fr --cached . && | |
342 | git update-index --index-info <failedmerge && | |
343 | cp file3.conflict file3 && | |
344 | test_must_fail git update-index --refresh -q && | |
345 | ||
346 | git rerere && | |
347 | git update-index --refresh | |
348 | ' | |
349 | ||
350 | test_expect_success 'explicit rerere --rerere-autoupdate overrides' ' | |
351 | git config rerere.autoupdate false && | |
352 | git rm -fr --cached . && | |
353 | git update-index --index-info <failedmerge && | |
354 | cp file3.conflict file3 && | |
355 | git rerere && | |
356 | git ls-files -u >actual1 && | |
357 | ||
358 | git rm -fr --cached . && | |
359 | git update-index --index-info <failedmerge && | |
360 | cp file3.conflict file3 && | |
361 | git rerere --rerere-autoupdate && | |
362 | git update-index --refresh && | |
363 | ||
364 | git rm -fr --cached . && | |
365 | git update-index --index-info <failedmerge && | |
366 | cp file3.conflict file3 && | |
367 | git rerere --rerere-autoupdate --no-rerere-autoupdate && | |
368 | git ls-files -u >actual2 && | |
369 | ||
370 | git rm -fr --cached . && | |
371 | git update-index --index-info <failedmerge && | |
372 | cp file3.conflict file3 && | |
373 | git rerere --rerere-autoupdate --no-rerere-autoupdate --rerere-autoupdate && | |
374 | git update-index --refresh && | |
375 | ||
376 | test_cmp expected.unresolved actual1 && | |
377 | test_cmp expected.unresolved actual2 | |
378 | ' | |
379 | ||
380 | test_expect_success 'rerere --no-no-rerere-autoupdate' ' | |
381 | git rm -fr --cached . && | |
382 | git update-index --index-info <failedmerge && | |
383 | cp file3.conflict file3 && | |
384 | test_must_fail git rerere --no-no-rerere-autoupdate 2>err && | |
9a001381 | 385 | test_i18ngrep [Uu]sage err && |
672d1b78 JN |
386 | test_must_fail git update-index --refresh |
387 | ' | |
388 | ||
389 | test_expect_success 'rerere -h' ' | |
390 | test_must_fail git rerere -h >help && | |
9a001381 | 391 | test_i18ngrep [Uu]sage help |
121c813f JH |
392 | ' |
393 | ||
ad8e72cb | 394 | test_done |