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 test_expect_success
'another conflicting merge' '
136 git checkout -b third master &&
137 git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
138 git commit -q -a -m third &&
139 test_must_fail git pull . first
142 git show first
:a1 |
sed 's/To die: t/To die! T/' > expect
143 test_expect_success
'rerere kicked in' "! grep ^=======$ a1"
145 test_expect_success
'rerere prefers first change' 'test_cmp a1 expect'
148 echo "$sha1 a1" | perl
-pe 'y/\012/\000/' > .git
/MERGE_RR
150 test_expect_success
'rerere clear' 'git rerere clear'
152 test_expect_success
'clear removed the directory' "test ! -d $rr"
155 echo Hello
> $rr/preimage
156 echo World
> $rr/postimage
158 sha2
=4000000000000000000000000000000000000000
159 rr2
=.git
/rr-cache
/$sha2
161 echo Hello
> $rr2/preimage
163 almost_15_days_ago
=$
((60-15*86400))
164 just_over_15_days_ago
=$
((-1-15*86400))
165 almost_60_days_ago
=$
((60-60*86400))
166 just_over_60_days_ago
=$
((-1-60*86400))
168 test-chmtime
=$almost_60_days_ago $rr/preimage
169 test-chmtime
=$almost_15_days_ago $rr2/preimage
171 test_expect_success
'garbage collection (part1)' 'git rerere gc'
173 test_expect_success
'young records still live' \
174 "test -f $rr/preimage && test -f $rr2/preimage"
176 test-chmtime
=$just_over_60_days_ago $rr/preimage
177 test-chmtime
=$just_over_15_days_ago $rr2/preimage
179 test_expect_success
'garbage collection (part2)' 'git rerere gc'
181 test_expect_success
'old records rest in peace' \
182 "test ! -f $rr/preimage && test ! -f $rr2/preimage"
184 test_expect_success
'file2 added differently in two branches' '
186 git checkout -b fourth &&
187 echo Hallo > file2 &&
189 git commit -m version1 &&
190 git checkout third &&
191 echo Bello > file2 &&
193 git commit -m version2 &&
194 test_must_fail git merge fourth &&
195 echo Cello > 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 &&
205 git commit -m version1 &&
206 git checkout third &&
207 echo Bello > file3 &&
209 git commit -m 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
219 git checkout version2 &&
220 test_must_fail git merge fifth &&
221 test 0 = $(git ls-files -u | wc -l)
224 test_expect_success
'merge --rerere-autoupdate' '
225 git config --unset rerere.autoupdate
227 git checkout version2 &&
228 test_must_fail git merge --rerere-autoupdate fifth &&
229 test 0 = $(git ls-files -u | wc -l)
232 test_expect_success
'merge --no-rerere-autoupdate' '
233 git config rerere.autoupdate true
235 git checkout version2 &&
236 test_must_fail git merge --no-rerere-autoupdate fifth &&
237 test 2 = $(git ls-files -u | wc -l)