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