tests: remove exit after test_done call
[git/ljr.git] / t / t4200-rerere.sh
blobb68ab11f2915789cd04ac6bd43363aeab2079198
1 #!/bin/sh
3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='git rerere
9 . ./test-lib.sh
11 cat > a1 << EOF
12 Some title
13 ==========
14 Whether 'tis nobler in the mind to suffer
15 The slings and arrows of outrageous fortune,
16 Or to take arms against a sea of troubles,
17 And by opposing end them? To die: to sleep;
18 No more; and by a sleep to say we end
19 The heart-ache and the thousand natural shocks
20 That flesh is heir to, 'tis a consummation
21 Devoutly to be wish'd.
22 EOF
24 git add a1
25 git commit -q -a -m initial
27 git checkout -b first
28 cat >> a1 << EOF
29 Some title
30 ==========
31 To die, to sleep;
32 To sleep: perchance to dream: ay, there's the rub;
33 For in that sleep of death what dreams may come
34 When we have shuffled off this mortal coil,
35 Must give us pause: there's the respect
36 That makes calamity of so long life;
37 EOF
38 git commit -q -a -m first
40 git checkout -b second master
41 git show first:a1 |
42 sed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1
43 echo "* END *" >>a1
44 git commit -q -a -m second
46 test_expect_success 'nothing recorded without rerere' '
47 (rm -rf .git/rr-cache; git config rerere.enabled false) &&
48 test_must_fail git merge first &&
49 ! test -d .git/rr-cache
52 # activate rerere, old style
53 test_expect_success 'conflicting merge' '
54 git reset --hard &&
55 mkdir .git/rr-cache &&
56 git config --unset rerere.enabled &&
57 test_must_fail git merge first
60 sha1=$(sed -e 's/ .*//' .git/MERGE_RR)
61 rr=.git/rr-cache/$sha1
62 test_expect_success 'recorded preimage' "grep ^=======$ $rr/preimage"
64 test_expect_success 'rerere.enabled works, too' '
65 rm -rf .git/rr-cache &&
66 git config rerere.enabled true &&
67 git reset --hard &&
68 test_must_fail git merge first &&
69 grep ^=======$ $rr/preimage
72 test_expect_success 'no postimage or thisimage yet' \
73 "test ! -f $rr/postimage -a ! -f $rr/thisimage"
75 test_expect_success 'preimage has right number of lines' '
77 cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
78 test $cnt = 13
82 git show first:a1 > a1
84 cat > expect << EOF
85 --- a/a1
86 +++ b/a1
87 @@ -1,4 +1,4 @@
88 -Some Title
89 +Some title
90 ==========
91 Whether 'tis nobler in the mind to suffer
92 The slings and arrows of outrageous fortune,
93 @@ -8,21 +8,11 @@
94 The heart-ache and the thousand natural shocks
95 That flesh is heir to, 'tis a consummation
96 Devoutly to be wish'd.
97 -<<<<<<<
98 -Some Title
99 -==========
100 -To die! To sleep;
101 -=======
102 Some title
103 ==========
104 To die, to sleep;
105 ->>>>>>>
106 To sleep: perchance to dream: ay, there's the rub;
107 For in that sleep of death what dreams may come
108 When we have shuffled off this mortal coil,
109 Must give us pause: there's the respect
110 That makes calamity of so long life;
111 -<<<<<<<
112 -=======
113 -* END *
114 ->>>>>>>
116 git rerere diff > out
118 test_expect_success 'rerere diff' 'test_cmp expect out'
120 cat > expect << EOF
124 git rerere status > out
126 test_expect_success 'rerere status' 'test_cmp expect out'
128 test_expect_success 'commit succeeds' \
129 "git commit -q -a -m 'prefer first over second'"
131 test_expect_success 'recorded postimage' "test -f $rr/postimage"
133 test_expect_success 'another conflicting merge' '
134 git checkout -b third master &&
135 git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
136 git commit -q -a -m third &&
137 test_must_fail git pull . first
140 git show first:a1 | sed 's/To die: t/To die! T/' > expect
141 test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
143 test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
145 rm $rr/postimage
146 echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
148 test_expect_success 'rerere clear' 'git rerere clear'
150 test_expect_success 'clear removed the directory' "test ! -d $rr"
152 mkdir $rr
153 echo Hello > $rr/preimage
154 echo World > $rr/postimage
156 sha2=4000000000000000000000000000000000000000
157 rr2=.git/rr-cache/$sha2
158 mkdir $rr2
159 echo Hello > $rr2/preimage
161 almost_15_days_ago=$((60-15*86400))
162 just_over_15_days_ago=$((-1-15*86400))
163 almost_60_days_ago=$((60-60*86400))
164 just_over_60_days_ago=$((-1-60*86400))
166 test-chmtime =$almost_60_days_ago $rr/preimage
167 test-chmtime =$almost_15_days_ago $rr2/preimage
169 test_expect_success 'garbage collection (part1)' 'git rerere gc'
171 test_expect_success 'young records still live' \
172 "test -f $rr/preimage && test -f $rr2/preimage"
174 test-chmtime =$just_over_60_days_ago $rr/preimage
175 test-chmtime =$just_over_15_days_ago $rr2/preimage
177 test_expect_success 'garbage collection (part2)' 'git rerere gc'
179 test_expect_success 'old records rest in peace' \
180 "test ! -f $rr/preimage && test ! -f $rr2/preimage"
182 test_expect_success 'file2 added differently in two branches' '
183 git reset --hard &&
184 git checkout -b fourth &&
185 echo Hallo > file2 &&
186 git add file2 &&
187 git commit -m version1 &&
188 git checkout third &&
189 echo Bello > file2 &&
190 git add file2 &&
191 git commit -m version2 &&
192 test_must_fail git merge fourth &&
193 sha1=$(sed -e "s/ .*//" .git/MERGE_RR) &&
194 rr=.git/rr-cache/$sha1 &&
195 echo Cello > file2 &&
196 git add file2 &&
197 git commit -m resolution
200 test_expect_success 'resolution was recorded properly' '
201 git reset --hard HEAD~2 &&
202 git checkout -b fifth &&
203 echo Hallo > file3 &&
204 git add file3 &&
205 git commit -m version1 &&
206 git checkout third &&
207 echo Bello > file3 &&
208 git add file3 &&
209 git commit -m version2 &&
210 git tag version2 &&
211 test_must_fail git merge fifth &&
212 test Cello = "$(cat file3)" &&
213 test 0 != $(git ls-files -u | wc -l)
216 test_expect_success 'rerere.autoupdate' '
217 git config rerere.autoupdate true
218 git reset --hard &&
219 git checkout version2 &&
220 test_must_fail git merge fifth &&
221 test 0 = $(git ls-files -u | wc -l)
225 test_done