Merge branch 'master' into next
[git/wpalmer.git] / t / t4200-rerere.sh
blob70856d07ed113b731d149bde73fe7b4eb25a72f2
1 #!/bin/sh
3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='git rerere
9 . ./test-lib.sh
11 test_expect_success 'setup' "
12 cat > a1 <<- EOF &&
13 Some title
14 ==========
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.
23 EOF
25 git add a1 &&
26 git commit -q -a -m initial &&
28 git checkout -b first &&
29 cat >> a1 <<- EOF &&
30 Some title
31 ==========
32 To die, to sleep;
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;
38 EOF
39 git commit -q -a -m first &&
41 git checkout -b second master &&
42 git show first:a1 |
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' '
56 git reset --hard &&
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 &&
69 git reset --hard &&
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) &&
80 test $cnt = 13
84 git show first:a1 > a1
86 cat > expect << EOF
87 --- a/a1
88 +++ b/a1
89 @@ -1,4 +1,4 @@
90 -Some Title
91 +Some title
92 ==========
93 Whether 'tis nobler in the mind to suffer
94 The slings and arrows of outrageous fortune,
95 @@ -8,21 +8,11 @@
96 The heart-ache and the thousand natural shocks
97 That flesh is heir to, 'tis a consummation
98 Devoutly to be wish'd.
99 -<<<<<<<
100 -Some Title
101 -==========
102 -To die! To sleep;
103 -=======
104 Some title
105 ==========
106 To die, to sleep;
107 ->>>>>>>
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;
113 -<<<<<<<
114 -=======
115 -* END *
116 ->>>>>>>
118 git rerere diff > out
120 test_expect_success 'rerere diff' 'test_cmp expect out'
122 cat > expect << EOF
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'
147 rm $rr/postimage
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"
154 mkdir $rr
155 echo Hello > $rr/preimage
156 echo World > $rr/postimage
158 sha2=4000000000000000000000000000000000000000
159 rr2=.git/rr-cache/$sha2
160 mkdir $rr2
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' '
185 git reset --hard &&
186 git checkout -b fourth &&
187 echo Hallo > file2 &&
188 git add file2 &&
189 git commit -m version1 &&
190 git checkout third &&
191 echo Bello > file2 &&
192 git add file2 &&
193 git commit -m version2 &&
194 test_must_fail git merge fourth &&
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)
224 test_expect_success 'merge --rerere-autoupdate' '
225 git config --unset rerere.autoupdate
226 git reset --hard &&
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
234 git reset --hard &&
235 git checkout version2 &&
236 test_must_fail git merge --no-rerere-autoupdate fifth &&
237 test 2 = $(git ls-files -u | wc -l)
240 test_done