]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4200-rerere.sh
rerere: remove dubious "tail_optimization"
[thirdparty/git.git] / t / t4200-rerere.sh
CommitLineData
ad8e72cb
JS
1#!/bin/sh
2#
3# Copyright (c) 2006 Johannes E. Schindelin
4#
5
5be60078 6test_description='git rerere
ad8e72cb
JS
7'
8
9. ./test-lib.sh
10
11cat > a1 << EOF
12Whether 'tis nobler in the mind to suffer
13The slings and arrows of outrageous fortune,
14Or to take arms against a sea of troubles,
15And by opposing end them? To die: to sleep;
16No more; and by a sleep to say we end
17The heart-ache and the thousand natural shocks
18That flesh is heir to, 'tis a consummation
19Devoutly to be wish'd.
20EOF
21
22git add a1
23git commit -q -a -m initial
24
25git checkout -b first
26cat >> a1 << EOF
27To die, to sleep;
28To sleep: perchance to dream: ay, there's the rub;
29For in that sleep of death what dreams may come
30When we have shuffled off this mortal coil,
31Must give us pause: there's the respect
32That makes calamity of so long life;
33EOF
34git commit -q -a -m first
35
36git checkout -b second master
eb335966 37git show first:a1 |
2b93edbf
JH
38sed -e 's/To die, t/To die! T/' > a1
39echo "* END *" >>a1
ad8e72cb
JS
40git commit -q -a -m second
41
b4372ef1
JS
42test_expect_success 'nothing recorded without rerere' '
43 (rm -rf .git/rr-cache; git config rerere.enabled false) &&
44 ! git merge first &&
45 ! test -d .git/rr-cache
46'
ad8e72cb 47
b4372ef1
JS
48# activate rerere, old style
49test_expect_success 'conflicting merge' '
50 git reset --hard &&
51 mkdir .git/rr-cache &&
52 git config --unset rerere.enabled &&
53 ! git merge first
54'
ad8e72cb 55
c256acb8 56sha1=$(sed -e 's/ .*//' .git/rr-cache/MERGE_RR)
ad8e72cb
JS
57rr=.git/rr-cache/$sha1
58test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
59
b4372ef1
JS
60test_expect_success 'rerere.enabled works, too' '
61 rm -rf .git/rr-cache &&
62 git config rerere.enabled true &&
63 git reset --hard &&
64 ! git merge first &&
65 grep ======= $rr/preimage
66'
67
ad8e72cb
JS
68test_expect_success 'no postimage or thisimage yet' \
69 "test ! -f $rr/postimage -a ! -f $rr/thisimage"
70
364b8523 71test_expect_success 'preimage has right number of lines' '
eb335966
JH
72
73 cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
2b93edbf 74 test $cnt = 9
eb335966
JH
75
76'
77
ad8e72cb
JS
78git show first:a1 > a1
79
80cat > expect << EOF
81--- a/a1
82+++ b/a1
eb335966 83@@ -6,17 +6,9 @@
ad8e72cb
JS
84 The heart-ache and the thousand natural shocks
85 That flesh is heir to, 'tis a consummation
86 Devoutly to be wish'd.
87-<<<<<<<
88-To die! To sleep;
89-=======
90 To die, to sleep;
91->>>>>>>
92 To sleep: perchance to dream: ay, there's the rub;
93 For in that sleep of death what dreams may come
94 When we have shuffled off this mortal coil,
eb335966 95 Must give us pause: there's the respect
2b93edbf 96 That makes calamity of so long life;
eb335966 97-<<<<<<<
eb335966 98-=======
2b93edbf 99-* END *
eb335966 100->>>>>>>
ad8e72cb 101EOF
ad8e72cb
JS
102git rerere diff > out
103
3af82863 104test_expect_success 'rerere diff' 'test_cmp expect out'
ad8e72cb
JS
105
106cat > expect << EOF
107a1
108EOF
109
110git rerere status > out
111
3af82863 112test_expect_success 'rerere status' 'test_cmp expect out'
ad8e72cb
JS
113
114test_expect_success 'commit succeeds' \
115 "git commit -q -a -m 'prefer first over second'"
116
117test_expect_success 'recorded postimage' "test -f $rr/postimage"
118
52aaf649
JS
119test_expect_success 'another conflicting merge' '
120 git checkout -b third master &&
121 git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
122 git commit -q -a -m third &&
123 ! git pull . first
124'
ad8e72cb
JS
125
126git show first:a1 | sed 's/To die: t/To die! T/' > expect
127test_expect_success 'rerere kicked in' "! grep ======= a1"
128
3af82863 129test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
ad8e72cb
JS
130
131rm $rr/postimage
e85fe4d8 132echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/rr-cache/MERGE_RR
ad8e72cb
JS
133
134test_expect_success 'rerere clear' 'git rerere clear'
135
136test_expect_success 'clear removed the directory' "test ! -d $rr"
137
138mkdir $rr
139echo Hello > $rr/preimage
140echo World > $rr/postimage
141
142sha2=4000000000000000000000000000000000000000
143rr2=.git/rr-cache/$sha2
144mkdir $rr2
145echo Hello > $rr2/preimage
146
56cf9806
EW
147almost_15_days_ago=$((60-15*86400))
148just_over_15_days_ago=$((-1-15*86400))
149almost_60_days_ago=$((60-60*86400))
150just_over_60_days_ago=$((-1-60*86400))
151
152test-chmtime =$almost_60_days_ago $rr/preimage
153test-chmtime =$almost_15_days_ago $rr2/preimage
154
155test_expect_success 'garbage collection (part1)' 'git rerere gc'
156
157test_expect_success 'young records still live' \
158 "test -f $rr/preimage && test -f $rr2/preimage"
159
160test-chmtime =$just_over_60_days_ago $rr/preimage
161test-chmtime =$just_over_15_days_ago $rr2/preimage
162
163test_expect_success 'garbage collection (part2)' 'git rerere gc'
164
165test_expect_success 'old records rest in peace' \
166 "test ! -f $rr/preimage && test ! -f $rr2/preimage"
ad8e72cb 167
52aaf649
JS
168test_expect_success 'file2 added differently in two branches' '
169 git reset --hard &&
170 git checkout -b fourth &&
171 echo Hallo > file2 &&
172 git add file2 &&
173 git commit -m version1 &&
174 git checkout third &&
175 echo Bello > file2 &&
176 git add file2 &&
177 git commit -m version2 &&
178 ! git merge fourth &&
179 sha1=$(sed -e "s/ .*//" .git/rr-cache/MERGE_RR) &&
180 rr=.git/rr-cache/$sha1 &&
181 echo Cello > file2 &&
182 git add file2 &&
183 git commit -m resolution
184'
185
186test_expect_success 'resolution was recorded properly' '
187 git reset --hard HEAD~2 &&
188 git checkout -b fifth &&
189 echo Hallo > file3 &&
190 git add file3 &&
191 git commit -m version1 &&
192 git checkout third &&
193 echo Bello > file3 &&
194 git add file3 &&
195 git commit -m version2 &&
196 ! git merge fifth &&
197 git diff-files -q &&
198 test Cello = "$(cat file3)"
199'
200
ad8e72cb 201test_done