t4200 (rerere): modernize style
Guard all test code with test_expect_success to make the script easier to follow. While at it, pick some other nits: - use test_tick (more than we have to, to be realistic); - 'single quotes' and \escaped HERE documents where possible simplify review for escaping problems; - omit whitespace after >redirection operators for consistency with other tests; - use "update-index --refresh" instead of testing that "ls-files -u" output is empty, since the former produces nicer output on failure; - compare to expected nonempty "ls-files -u" output instead of counting lines when it is expected to be nonempty. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Aug 5, 2010 at 06:25 UTC
f7314882c26b34c4c1039b65b1c8e6b380d30674
1 file changed
+180
-125
t/t4200-rerere.sh
+180
-125
@@ -4,237 +4,292 @@
4
#
5
6
test_description='git rerere
7
+
8
+! [fifth] version1
9
+ ! [first] first
10
+ ! [fourth] version1
11
+ ! [master] initial
12
+ ! [second] prefer first over second
13
+ ! [third] version2
14
+------
15
+ + [third] version2
16
++ [fifth] version1
17
+ + [fourth] version1
18
++ + + [third^] third
19
+ - [second] prefer first over second
20
+ + + [first] first
21
+ + [second^] second
22
+++++++ [master] initial
23
'
24
25
. ./test-lib.sh
26
11
-test_expect_success 'setup' "
12
- cat > a1 <<- EOF &&
27
+test_expect_success 'setup' '
28
+ cat >a1 <<-\EOF &&
29
Some title
30
==========
15
- Whether 'tis nobler in the mind to suffer
31
+ Whether '\''tis nobler in the mind to suffer
32
The slings and arrows of outrageous fortune,
33
Or to take arms against a sea of troubles,
34
And by opposing end them? To die: to sleep;
35
No more; and by a sleep to say we end
36
The heart-ache and the thousand natural shocks
21
- That flesh is heir to, 'tis a consummation
22
- Devoutly to be wish'd.
37
+ That flesh is heir to, '\''tis a consummation
38
+ Devoutly to be wish'\''d.
39
EOF
40
41
git add a1 &&
42
+ test_tick &&
43
git commit -q -a -m initial &&
44
28
- git checkout -b first &&
29
- cat >> a1 <<- EOF &&
45
+ cat >>a1 <<-\EOF &&
46
Some title
47
==========
48
To die, to sleep;
33
- To sleep: perchance to dream: ay, there's the rub;
49
+ To sleep: perchance to dream: ay, there'\''s the rub;
50
For in that sleep of death what dreams may come
51
When we have shuffled off this mortal coil,
36
- Must give us pause: there's the respect
52
+ Must give us pause: there'\''s the respect
53
That makes calamity of so long life;
54
EOF
55
+
56
+ git checkout -b first &&
57
+ test_tick &&
58
git commit -q -a -m first &&
59
60
git checkout -b second master &&
61
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 &&
62
+ sed -e "s/To die, t/To die! T/" -e "s/Some title/Some Title/" >a1 &&
63
+ echo "* END *" >>a1 &&
64
+ test_tick &&
65
git commit -q -a -m second
46
-"
66
+'
67
68
test_expect_success 'nothing recorded without rerere' '
49
- (rm -rf .git/rr-cache; git config rerere.enabled false) &&
69
+ rm -rf .git/rr-cache &&
70
+ git config rerere.enabled false &&
71
test_must_fail git merge first &&
72
! test -d .git/rr-cache
73
'
74
54
-# activate rerere, old style
55
-test_expect_success 'conflicting merge' '
75
+test_expect_success 'activate rerere, old style (conflicting merge)' '
76
git reset --hard &&
77
mkdir .git/rr-cache &&
58
- git config --unset rerere.enabled &&
59
- test_must_fail git merge first
60
-'
78
+ test_might_fail git config --unset rerere.enabled &&
79
+ test_must_fail git merge first &&
80
62
-sha1=$(perl -pe 's/ .*//' .git/MERGE_RR)
63
-rr=.git/rr-cache/$sha1
64
-test_expect_success 'recorded preimage' "grep ^=======$ $rr/preimage"
81
+ sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
82
+ rr=.git/rr-cache/$sha1 &&
83
+ grep "^=======\$" $rr/preimage &&
84
+ ! test -f $rr/postimage &&
85
+ ! test -f $rr/thisimage
86
+'
87
88
test_expect_success 'rerere.enabled works, too' '
89
rm -rf .git/rr-cache &&
90
git config rerere.enabled true &&
91
git reset --hard &&
92
test_must_fail git merge first &&
93
+
94
+ sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
95
+ rr=.git/rr-cache/$sha1 &&
96
grep ^=======$ $rr/preimage
97
'
98
74
-test_expect_success 'no postimage or thisimage yet' \
75
- "test ! -f $rr/postimage -a ! -f $rr/thisimage"
99
+test_expect_success 'set up rr-cache' '
100
+ rm -rf .git/rr-cache &&
101
+ git config rerere.enabled true &&
102
+ git reset --hard &&
103
+ test_must_fail git merge first &&
104
+ sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
105
+ rr=.git/rr-cache/$sha1
106
+'
107
77
-test_expect_success 'preimage has right number of lines' '
108
+test_expect_success 'rr-cache looks sane' '
109
+ # no postimage or thisimage yet
110
+ ! test -f $rr/postimage &&
111
+ ! test -f $rr/thisimage &&
112
113
+ # preimage has right number of lines
114
cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
115
+ echo $cnt &&
116
test $cnt = 13
81
-
117
'
118
84
-git show first:a1 > a1
85
-
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
-->>>>>>>
117
-EOF
118
-git rerere diff > out
119
-
120
-test_expect_success 'rerere diff' 'test_cmp expect out'
121
-
122
-cat > expect << EOF
123
-a1
124
-EOF
125
-
126
-git rerere status > out
127
-
128
-test_expect_success 'rerere status' 'test_cmp expect out'
129
-
130
-test_expect_success 'commit succeeds' \
131
- "git commit -q -a -m 'prefer first over second'"
132
-
133
-test_expect_success 'recorded postimage' "test -f $rr/postimage"
134
-
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
119
+test_expect_success 'rerere diff' '
120
+ git show first:a1 >a1 &&
121
+ cat >expect <<-\EOF &&
122
+ --- a/a1
123
+ +++ b/a1
124
+ @@ -1,4 +1,4 @@
125
+ -Some Title
126
+ +Some title
127
+ ==========
128
+ Whether '\''tis nobler in the mind to suffer
129
+ The slings and arrows of outrageous fortune,
130
+ @@ -8,21 +8,11 @@
131
+ The heart-ache and the thousand natural shocks
132
+ That flesh is heir to, '\''tis a consummation
133
+ Devoutly to be wish'\''d.
134
+ -<<<<<<<
135
+ -Some Title
136
+ -==========
137
+ -To die! To sleep;
138
+ -=======
139
+ Some title
140
+ ==========
141
+ To die, to sleep;
142
+ ->>>>>>>
143
+ To sleep: perchance to dream: ay, there'\''s the rub;
144
+ For in that sleep of death what dreams may come
145
+ When we have shuffled off this mortal coil,
146
+ Must give us pause: there'\''s the respect
147
+ That makes calamity of so long life;
148
+ -<<<<<<<
149
+ -=======
150
+ -* END *
151
+ ->>>>>>>
152
+ EOF
153
+ git rerere diff >out &&
154
+ test_cmp expect out
155
'
156
142
-git show first:a1 | sed 's/To die: t/To die! T/' > expect
143
-test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
144
-
145
-test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
146
-
147
-rm $rr/postimage
148
-echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
157
+test_expect_success 'rerere status' '
158
+ echo a1 >expect &&
159
+ git rerere status >out &&
160
+ test_cmp expect out
161
+'
162
150
-test_expect_success 'rerere clear' 'git rerere clear'
163
+test_expect_success 'first postimage wins' '
164
+ git show first:a1 | sed "s/To die: t/To die! T/" >expect &&
165
152
-test_expect_success 'clear removed the directory' "test ! -d $rr"
166
+ git commit -q -a -m "prefer first over second" &&
167
+ test -f $rr/postimage &&
168
154
-mkdir $rr
155
-echo Hello > $rr/preimage
156
-echo World > $rr/postimage
169
+ git checkout -b third master &&
170
+ git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
171
+ git commit -q -a -m third &&
172
158
-sha2=4000000000000000000000000000000000000000
159
-rr2=.git/rr-cache/$sha2
160
-mkdir $rr2
161
-echo Hello > $rr2/preimage
173
+ test_must_fail git pull . first &&
174
+ # rerere kicked in
175
+ ! grep "^=======\$" a1 &&
176
+ test_cmp expect a1
177
+'
178
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))
179
+test_expect_success 'rerere clear' '
180
+ rm $rr/postimage &&
181
+ echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
182
+ git rerere clear &&
183
+ ! test -d $rr
184
+'
185
168
-test-chmtime =$almost_60_days_ago $rr/preimage
169
-test-chmtime =$almost_15_days_ago $rr2/preimage
186
+test_expect_success 'set up for garbage collection tests' '
187
+ mkdir -p $rr &&
188
+ echo Hello >$rr/preimage &&
189
+ echo World >$rr/postimage &&
190
171
-test_expect_success 'garbage collection (part1)' 'git rerere gc'
191
+ sha2=4000000000000000000000000000000000000000 &&
192
+ rr2=.git/rr-cache/$sha2 &&
193
+ mkdir $rr2 &&
194
+ echo Hello >$rr2/preimage &&
195
173
-test_expect_success 'young records still live' \
174
- "test -f $rr/preimage && test -f $rr2/preimage"
196
+ almost_15_days_ago=$((60-15*86400)) &&
197
+ just_over_15_days_ago=$((-1-15*86400)) &&
198
+ almost_60_days_ago=$((60-60*86400)) &&
199
+ just_over_60_days_ago=$((-1-60*86400)) &&
200
176
-test-chmtime =$just_over_60_days_ago $rr/preimage
177
-test-chmtime =$just_over_15_days_ago $rr2/preimage
201
+ test-chmtime =$almost_60_days_ago $rr/preimage &&
202
+ test-chmtime =$almost_15_days_ago $rr2/preimage
203
+'
204
179
-test_expect_success 'garbage collection (part2)' 'git rerere gc'
205
+test_expect_success 'garbage collection preserves young records' '
206
+ git rerere gc &&
207
+ test -f $rr/preimage &&
208
+ test -f $rr2/preimage
209
+'
210
181
-test_expect_success 'old records rest in peace' \
182
- "test ! -f $rr/preimage && test ! -f $rr2/preimage"
211
+test_expect_success 'old records rest in peace' '
212
+ test-chmtime =$just_over_60_days_ago $rr/preimage &&
213
+ test-chmtime =$just_over_15_days_ago $rr2/preimage &&
214
+ git rerere gc &&
215
+ ! test -f $rr/preimage &&
216
+ ! test -f $rr2/preimage
217
+'
218
184
-test_expect_success 'file2 added differently in two branches' '
219
+test_expect_success 'setup: file2 added differently in two branches' '
220
git reset --hard &&
221
+
222
git checkout -b fourth &&
187
- echo Hallo > file2 &&
223
+ echo Hallo >file2 &&
224
git add file2 &&
225
+ test_tick &&
226
git commit -m version1 &&
227
+
228
git checkout third &&
191
- echo Bello > file2 &&
229
+ echo Bello >file2 &&
230
git add file2 &&
231
+ test_tick &&
232
git commit -m version2 &&
233
+
234
test_must_fail git merge fourth &&
195
- echo Cello > file2 &&
235
+ echo Cello >file2 &&
236
git add file2 &&
237
git commit -m resolution
238
'
239
240
test_expect_success 'resolution was recorded properly' '
241
+ echo Cello >expected &&
242
+
243
git reset --hard HEAD~2 &&
244
git checkout -b fifth &&
203
- echo Hallo > file3 &&
245
+
246
+ echo Hallo >file3 &&
247
git add file3 &&
248
+ test_tick &&
249
git commit -m version1 &&
250
+
251
git checkout third &&
207
- echo Bello > file3 &&
252
+ echo Bello >file3 &&
253
git add file3 &&
254
+ test_tick &&
255
git commit -m version2 &&
256
git tag version2 &&
257
+
258
test_must_fail git merge fifth &&
212
- test Cello = "$(cat file3)" &&
213
- test 0 != $(git ls-files -u | wc -l)
259
+ test_cmp expected file3 &&
260
+ test_must_fail git update-index --refresh
261
'
262
263
test_expect_success 'rerere.autoupdate' '
217
- git config rerere.autoupdate true
264
+ git config rerere.autoupdate true &&
265
git reset --hard &&
266
git checkout version2 &&
267
test_must_fail git merge fifth &&
221
- test 0 = $(git ls-files -u | wc -l)
268
+ git update-index --refresh
269
'
270
271
test_expect_success 'merge --rerere-autoupdate' '
225
- git config --unset rerere.autoupdate
272
+ test_might_fail git config --unset rerere.autoupdate &&
273
git reset --hard &&
274
git checkout version2 &&
275
test_must_fail git merge --rerere-autoupdate fifth &&
229
- test 0 = $(git ls-files -u | wc -l)
276
+ git update-index --refresh
277
'
278
279
test_expect_success 'merge --no-rerere-autoupdate' '
233
- git config rerere.autoupdate true
280
+ headblob=$(git rev-parse version2:file3) &&
281
+ mergeblob=$(git rev-parse fifth:file3) &&
282
+ cat >expected <<-EOF &&
283
+ 100644 $headblob 2 file3
284
+ 100644 $mergeblob 3 file3
285
+ EOF
286
+
287
+ git config rerere.autoupdate true &&
288
git reset --hard &&
289
git checkout version2 &&
290
test_must_fail git merge --no-rerere-autoupdate fifth &&
237
- test 2 = $(git ls-files -u | wc -l)
291
+ git ls-files -u >actual &&
292
+ test_cmp expected actual
293
'
294
295
test_done