3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description
='git rerere
11 test_expect_success
'setup' "
15 Whether 'tis nobler in the mind to suffer
16 The slings and arrows of outrageous fortune,
17 Or to take arms against a sea of troubles,
18 And by opposing end them? To die: to sleep;
19 No more; and by a sleep to say we end
20 The heart-ache and the thousand natural shocks
21 That flesh is heir to, 'tis a consummation
22 Devoutly to be wish'd.
26 git commit -q -a -m initial &&
28 git checkout -b first &&
33 To sleep: perchance to dream: ay, there's the rub;
34 For in that sleep of death what dreams may come
35 When we have shuffled off this mortal coil,
36 Must give us pause: there's the respect
37 That makes calamity of so long life;
39 git commit -q -a -m first &&
41 git checkout -b second master &&
43 sed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1 &&
44 echo '* END *' >>a1 &&
45 git commit -q -a -m second
48 test_expect_success
'nothing recorded without rerere' '
49 (rm -rf .git/rr-cache; git config rerere.enabled false) &&
50 test_must_fail git merge first &&
51 ! test -d .git/rr-cache
54 # activate rerere, old style
55 test_expect_success
'conflicting merge' '
57 mkdir .git/rr-cache &&
58 git config --unset rerere.enabled &&
59 test_must_fail git merge first
62 sha1
=$
(perl
-pe 's/ .*//' .git
/MERGE_RR
)
63 rr
=.git
/rr-cache
/$sha1
64 test_expect_success
'recorded preimage' "grep ^=======$ $rr/preimage"
66 test_expect_success
'rerere.enabled works, too' '
67 rm -rf .git/rr-cache &&
68 git config rerere.enabled true &&
70 test_must_fail git merge first &&
71 grep ^=======$ $rr/preimage
74 test_expect_success
'no postimage or thisimage yet' \
75 "test ! -f $rr/postimage -a ! -f $rr/thisimage"
77 test_expect_success
'preimage has right number of lines' '
79 cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
84 git show first
:a1
> a1
93 Whether 'tis nobler in the mind to suffer
94 The slings and arrows of outrageous fortune,
96 The heart-ache and the thousand natural shocks
97 That flesh is heir to, 'tis a consummation
98 Devoutly to be wish'd.
108 To sleep: perchance to dream: ay, there's the rub;
109 For in that sleep of death what dreams may come
110 When we have shuffled off this mortal coil,
111 Must give us pause: there's the respect
112 That makes calamity of so long life;
118 git rerere
diff > out
120 test_expect_success
'rerere diff' 'test_cmp expect out'
126 git rerere status
> out
128 test_expect_success
'rerere status' 'test_cmp expect out'
130 test_expect_success
'commit succeeds' \
131 "git commit -q -a -m 'prefer first over second'"
133 test_expect_success
'recorded postimage' "test -f $rr/postimage"
135 oldmtimepost
=$
(test-chmtime
-v -60 $rr/postimage |cut
-f 1)
137 test_expect_success
'another conflicting merge' '
138 git checkout -b third master &&
139 git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
140 git commit -q -a -m third &&
141 test_must_fail git pull . first
144 git show first
:a1 |
sed 's/To die: t/To die! T/' > expect
145 test_expect_success
'rerere kicked in' "! grep ^=======$ a1"
147 test_expect_success
'rerere prefers first change' 'test_cmp a1 expect'
149 test_expect_success
'rerere updates postimage timestamp' '
150 newmtimepost=$(test-chmtime -v +0 $rr/postimage |cut -f 1) &&
151 test $oldmtimepost -lt $newmtimepost
155 echo "$sha1 a1" | perl
-pe 'y/\012/\000/' > .git
/MERGE_RR
157 test_expect_success
'rerere clear' 'git rerere clear'
159 test_expect_success
'clear removed the directory' "test ! -d $rr"
162 echo Hello
> $rr/preimage
163 echo World
> $rr/postimage
165 sha2
=4000000000000000000000000000000000000000
166 rr2
=.git
/rr-cache
/$sha2
168 echo Hello
> $rr2/preimage
170 almost_15_days_ago
=$
((60-15*86400))
171 just_over_15_days_ago
=$
((-1-15*86400))
172 almost_60_days_ago
=$
((60-60*86400))
173 just_over_60_days_ago
=$
((-1-60*86400))
175 test-chmtime
=$just_over_60_days_ago $rr/preimage
176 test-chmtime
=$almost_60_days_ago $rr/postimage
177 test-chmtime
=$almost_15_days_ago $rr2/preimage
179 test_expect_success
'garbage collection (part1)' 'git rerere gc'
181 test_expect_success
'young or recently used records still live' \
182 "test -f $rr/preimage && test -f $rr2/preimage"
184 test-chmtime
=$just_over_60_days_ago $rr/postimage
185 test-chmtime
=$just_over_15_days_ago $rr2/preimage
187 test_expect_success
'garbage collection (part2)' 'git rerere gc'
189 test_expect_success
'old records rest in peace' \
190 "test ! -f $rr/preimage && test ! -f $rr2/preimage"
192 test_expect_success
'file2 added differently in two branches' '
194 git checkout -b fourth &&
195 echo Hallo > file2 &&
197 git commit -m version1 &&
198 git checkout third &&
199 echo Bello > file2 &&
201 git commit -m version2 &&
202 test_must_fail git merge fourth &&
203 echo Cello > file2 &&
205 git commit -m resolution
208 test_expect_success
'resolution was recorded properly' '
209 git reset --hard HEAD~2 &&
210 git checkout -b fifth &&
211 echo Hallo > file3 &&
213 git commit -m version1 &&
214 git checkout third &&
215 echo Bello > file3 &&
217 git commit -m version2 &&
219 test_must_fail git merge fifth &&
220 test Cello = "$(cat file3)" &&
221 test 0 != $(git ls-files -u | wc -l)
224 test_expect_success
'rerere.autoupdate' '
225 git config rerere.autoupdate true
227 git checkout version2 &&
228 test_must_fail git merge fifth &&
229 test 0 = $(git ls-files -u | wc -l)
232 test_expect_success
'merge --rerere-autoupdate' '
233 git config --unset rerere.autoupdate
235 git checkout version2 &&
236 test_must_fail git merge --rerere-autoupdate fifth &&
237 test 0 = $(git ls-files -u | wc -l)
240 test_expect_success
'merge --no-rerere-autoupdate' '
241 git config rerere.autoupdate true
243 git checkout version2 &&
244 test_must_fail git merge --no-rerere-autoupdate fifth &&
245 test 2 = $(git ls-files -u | wc -l)