|
1
|
# |
|
2
|
# Copyright (c) 2013 D. Richard Hipp |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
# Author contact information: |
|
13
|
# [email protected] |
|
14
|
# http://www.hwaci.com/drh/ |
|
15
|
# |
|
16
|
############################################################################ |
|
17
|
# |
|
18
|
# |
|
19
|
# Tests for 'fossil revert' |
|
20
|
# |
|
21
|
# |
|
22
|
|
|
23
|
# Test 'fossil revert' against expected results from 'fossil changes' and |
|
24
|
# 'fossil addremove -n', as well as by verifying the existence of files |
|
25
|
# on the file system. 'fossil undo' is called after each test |
|
26
|
# |
|
27
|
proc revert-test {testid revertArgs expectedRevertOutput args} { |
|
28
|
global RESULT |
|
29
|
set passed 1 |
|
30
|
|
|
31
|
set args [dict merge { |
|
32
|
-changes {} -addremove {} -exists {} -notexists {} |
|
33
|
} $args] |
|
34
|
|
|
35
|
set result [fossil revert {*}$revertArgs] |
|
36
|
test_status_list revert-$testid $result $expectedRevertOutput |
|
37
|
|
|
38
|
set statusListTests [list -changes changes -addremove {addremove -n}] |
|
39
|
foreach {key fossilArgs} $statusListTests { |
|
40
|
set expected [dict get $args $key] |
|
41
|
set result [fossil {*}$fossilArgs] |
|
42
|
test_status_list revert-$testid$key $result $expected |
|
43
|
} |
|
44
|
|
|
45
|
set fileExistsTests [list -exists 1 does -notexists 0 should] |
|
46
|
foreach {key expected verb} $fileExistsTests { |
|
47
|
foreach path [dict get $args $key] { |
|
48
|
if {[file exists $path] != $expected} { |
|
49
|
set passed 0 |
|
50
|
protOut " Failure: File $verb not exist: $path" |
|
51
|
} |
|
52
|
} |
|
53
|
test revert-$testid$key $passed |
|
54
|
} |
|
55
|
|
|
56
|
fossil undo |
|
57
|
} |
|
58
|
|
|
59
|
require_no_open_checkout |
|
60
|
test_setup |
|
61
|
|
|
62
|
# Prepare first commit |
|
63
|
# |
|
64
|
write_file f1 "f1" |
|
65
|
write_file f2 "f2" |
|
66
|
write_file f3 "f3" |
|
67
|
fossil add f1 f2 f3 |
|
68
|
fossil commit -m "c1" |
|
69
|
|
|
70
|
# Make changes to be reverted |
|
71
|
# |
|
72
|
# Add f0 |
|
73
|
write_file f0 "f0" |
|
74
|
fossil add f0 |
|
75
|
# Remove f1 |
|
76
|
file delete f1 |
|
77
|
fossil rm f1 |
|
78
|
# Edit f2 |
|
79
|
write_file f2 "f2.1" |
|
80
|
# Rename f3 to f3n |
|
81
|
file rename -force f3 f3n |
|
82
|
fossil mv f3 f3n |
|
83
|
|
|
84
|
# Test 'fossil revert' with no arguments |
|
85
|
# |
|
86
|
revert-test 1-1 {} { |
|
87
|
UNMANAGE f0 |
|
88
|
REVERT f1 |
|
89
|
REVERT f2 |
|
90
|
REVERT f3 |
|
91
|
DELETE f3n |
|
92
|
} -addremove { |
|
93
|
ADDED f0 |
|
94
|
} -exists {f0 f1 f2 f3} -notexists f3n |
|
95
|
|
|
96
|
# Test with a single filename argument |
|
97
|
# |
|
98
|
revert-test 1-2 f0 { |
|
99
|
UNMANAGE f0 |
|
100
|
} -changes { |
|
101
|
DELETED f1 |
|
102
|
EDITED f2 |
|
103
|
RENAMED f3 -> f3n |
|
104
|
} -addremove { |
|
105
|
ADDED f0 |
|
106
|
} -exists {f0 f2 f3n} -notexists f3 |
|
107
|
|
|
108
|
revert-test 1-3 f1 { |
|
109
|
REVERT f1 |
|
110
|
} -changes { |
|
111
|
ADDED f0 |
|
112
|
EDITED f2 |
|
113
|
RENAMED f3 -> f3n |
|
114
|
} -exists {f0 f1 f2 f3n} -notexists f3 |
|
115
|
|
|
116
|
revert-test 1-4 f2 { |
|
117
|
REVERT f2 |
|
118
|
} -changes { |
|
119
|
ADDED f0 |
|
120
|
DELETED f1 |
|
121
|
RENAMED f3 -> f3n |
|
122
|
} -exists {f0 f2 f3n} -notexists {f1 f3} |
|
123
|
|
|
124
|
# Both files involved in a rename are reverted regardless of which filename |
|
125
|
# is used as an argument to 'fossil revert' |
|
126
|
# |
|
127
|
revert-test 1-5 f3 { |
|
128
|
REVERT f3 |
|
129
|
DELETE f3n |
|
130
|
} -changes { |
|
131
|
ADDED f0 |
|
132
|
DELETED f1 |
|
133
|
EDITED f2 |
|
134
|
} -exists {f0 f2 f3} -notexists {f1 f3n} |
|
135
|
|
|
136
|
revert-test 1-6 f3n { |
|
137
|
REVERT f3 |
|
138
|
DELETE f3n |
|
139
|
} -changes { |
|
140
|
ADDED f0 |
|
141
|
DELETED f1 |
|
142
|
EDITED f2 |
|
143
|
} -exists {f0 f2 f3} -notexists {f1 f3n} |
|
144
|
|
|
145
|
# Test with multiple filename arguments |
|
146
|
# |
|
147
|
revert-test 1-7 {f0 f2 f3n} { |
|
148
|
UNMANAGE f0 |
|
149
|
REVERT f2 |
|
150
|
REVERT f3 |
|
151
|
DELETE f3n |
|
152
|
} -changes { |
|
153
|
DELETED f1 |
|
154
|
} -addremove { |
|
155
|
ADDED f0 |
|
156
|
} -exists {f0 f2 f3} -notexists {f1 f3n} |
|
157
|
|
|
158
|
|
|
159
|
# Test reverting the combination of a renamed file and an added file that |
|
160
|
# uses the renamed file's original filename. |
|
161
|
# |
|
162
|
test_setup |
|
163
|
write_file f1 "f1" |
|
164
|
fossil add f1 |
|
165
|
fossil commit -m "add f1" |
|
166
|
|
|
167
|
write_file f1n "f1n" |
|
168
|
fossil mv f1 f1n |
|
169
|
write_file f1 "f1b" |
|
170
|
fossil add f1 |
|
171
|
|
|
172
|
revert-test 2-1 {} { |
|
173
|
REVERT f1 |
|
174
|
DELETE f1n |
|
175
|
} -exists {f1} -notexists {f1n} |
|
176
|
|
|
177
|
|
|
178
|
# Test reverting a rename in the repo but not completed in the file |
|
179
|
# system |
|
180
|
test_setup |
|
181
|
write_file f1 "f1" |
|
182
|
fossil add f1 |
|
183
|
fossil commit -m "add f1" |
|
184
|
fossil mv --soft f1 f1new |
|
185
|
test 3-mv-1 {[file exists f1]} |
|
186
|
test 3-mv-2 {![file exists f1new]} |
|
187
|
revert-test 3-1 {} { |
|
188
|
REVERT f1 |
|
189
|
DELETE f1new |
|
190
|
} -exists {f1} -notexists {f1n} |
|
191
|
|
|
192
|
|
|
193
|
# Test reverting of files under a sub-directory |
|
194
|
test_setup |
|
195
|
file mkdir d |
|
196
|
write_file d/f1 "d/f1" |
|
197
|
write_file d/f2 "d/f2" |
|
198
|
write_file d/f3 "d/f3" |
|
199
|
write_file d/f4 "d/f4" |
|
200
|
|
|
201
|
fossil add d |
|
202
|
fossil delete d/f1 |
|
203
|
fossil commit -m "d/f2 d/f3 d/f4" |
|
204
|
|
|
205
|
## Changes to revert |
|
206
|
fossil add d/f1 |
|
207
|
write_file d/f2 "4-1:d/f2" |
|
208
|
fossil changes d/f2 |
|
209
|
fossil delete --soft d/f3 |
|
210
|
|
|
211
|
revert-test 4-1 {d/f1} { |
|
212
|
UNMANAGE d/f1 |
|
213
|
} -changes { |
|
214
|
EDITED d/f2 |
|
215
|
DELETED d/f3 |
|
216
|
} -addremove { |
|
217
|
ADDED d/f1 |
|
218
|
} -exists {d/f1 d/f2 d/f3} |
|
219
|
|
|
220
|
revert-test 4-2 {d/f2} { |
|
221
|
REVERT d/f2 |
|
222
|
} -changes { |
|
223
|
ADDED d/f1 |
|
224
|
DELETED d/f3 |
|
225
|
} -exists {d/f1 d/f2 d/f3} |
|
226
|
|
|
227
|
revert-test 4-3 {d/f3} { |
|
228
|
REVERT d/f3 |
|
229
|
} -changes { |
|
230
|
ADDED d/f1 |
|
231
|
EDITED d/f2 |
|
232
|
} -exists {d/f1 d/f2 d/f3} |
|
233
|
|
|
234
|
fossil mv --soft d/f4 d/f4new |
|
235
|
test 4-4-mv-1 {[file exists d/f4]} |
|
236
|
test 4-4-mv-2 {![file exists d/f4new]} |
|
237
|
revert-test 4-4 {d/f4} { |
|
238
|
DELETE d/f4new |
|
239
|
REVERT d/f4 |
|
240
|
} -changes { |
|
241
|
ADDED d/f1 |
|
242
|
EDITED d/f2 |
|
243
|
DELETED d/f3 |
|
244
|
} -exists {d/f4} -notexists {d/f4new} |
|
245
|
|
|
246
|
## Commit changes before testing reverting of directory rename, |
|
247
|
## otherwise there're could be sequencing issues |
|
248
|
fossil redo |
|
249
|
fossil commit -m "4-5:setup" |
|
250
|
|
|
251
|
fossil mv --soft d dnew |
|
252
|
revert-test 4-5 {d/f1 d/f2 d/f3 d/f4} { |
|
253
|
REVERT d/f1 |
|
254
|
REVERT d/f2 |
|
255
|
UNMANAGE d/f3 |
|
256
|
REVERT d/f4 |
|
257
|
DELETE dnew/f1 |
|
258
|
DELETE dnew/f2 |
|
259
|
DELETE dnew/f4 |
|
260
|
} -addremove { |
|
261
|
ADDED d/f3 |
|
262
|
} -exists {d/f1 d/f2 d/f3 d/f4} -notexists {dnew} |
|
263
|
|
|
264
|
|
|
265
|
## Test reverting of changes in whole sub-directory tree |
|
266
|
test_setup |
|
267
|
file mkdir d |
|
268
|
write_file f0 "f0" |
|
269
|
write_file d/f1 "d/f1" |
|
270
|
write_file d/f2 "d/f2" |
|
271
|
write_file d/f3 "d/f3" |
|
272
|
write_file d/f4 "d/f4" |
|
273
|
|
|
274
|
fossil add f0 d |
|
275
|
fossil delete d/f1 |
|
276
|
fossil commit -m "f0 d/f2 d/f3 d/f4" |
|
277
|
|
|
278
|
## Changes to revert |
|
279
|
fossil add d/f1 |
|
280
|
write_file d/f2 "5-1:d/f2" |
|
281
|
fossil changes d/f2 |
|
282
|
fossil delete --soft d/f3 |
|
283
|
|
|
284
|
revert-test 5-1 {d} { |
|
285
|
UNMANAGE d/f1 |
|
286
|
REVERT d/f2 |
|
287
|
REVERT d/f3 |
|
288
|
} -addremove { |
|
289
|
ADDED d/f1 |
|
290
|
} -exists {f0 d/f1 d/f2 d/f3} |
|
291
|
|
|
292
|
write_file f0 "5-2:f0" |
|
293
|
fossil changes f0 |
|
294
|
revert-test 5-2 {f0 d} { |
|
295
|
UNMANAGE d/f1 |
|
296
|
REVERT d/f2 |
|
297
|
REVERT d/f3 |
|
298
|
REVERT f0 |
|
299
|
} -addremove { |
|
300
|
ADDED d/f1 |
|
301
|
} -exists {f0 d/f1 d/f2 d/f3} |
|
302
|
|
|
303
|
## Commit changes before testing the revert of directory rename, |
|
304
|
## otherwise there're could be sequencing issues |
|
305
|
fossil commit -m "5-3:setup" |
|
306
|
|
|
307
|
fossil changes |
|
308
|
|
|
309
|
fossil mv --soft d dnew |
|
310
|
revert-test 5-3 {d} { |
|
311
|
REVERT d/f1 |
|
312
|
REVERT d/f2 |
|
313
|
REVERT d/f4 |
|
314
|
DELETE dnew/f1 |
|
315
|
DELETE dnew/f2 |
|
316
|
DELETE dnew/f4 |
|
317
|
} -addremove { |
|
318
|
ADDED d/f3 |
|
319
|
} -exists {f0 d/f1 d/f2 d/f3 d/f4} -notexists {dnew} |
|
320
|
|
|
321
|
## Reset/redo the undone results of revert to get to a clean checkout |
|
322
|
fossil redo |
|
323
|
|
|
324
|
file mkdir d/e |
|
325
|
file mkdir d/e/f |
|
326
|
write_file d/e/fe1 "d/e/fe1" |
|
327
|
write_file d/e/f/ff1 "d/e/f/ff1" |
|
328
|
|
|
329
|
file mkdir d1 |
|
330
|
file mkdir d1/e |
|
331
|
write_file d1/e/fe1 "d1/e/fe1" |
|
332
|
write_file d1/e/fe2 "d1/e/fe2" |
|
333
|
|
|
334
|
fossil add d1/e/fe1 |
|
335
|
fossil commit d1/e/fe1 -m "d1/e/fe1" |
|
336
|
|
|
337
|
write_file d1/e/fe1 "5-4:d1/e/fe1" |
|
338
|
fossil changes d1/e/fe1 |
|
339
|
fossil add d d1 |
|
340
|
|
|
341
|
revert-test 5-4 {d d1} { |
|
342
|
UNMANAGE d/f3 |
|
343
|
UNMANAGE d/e/fe1 |
|
344
|
UNMANAGE d/e/f/ff1 |
|
345
|
REVERT d1/e/fe1 |
|
346
|
UNMANAGE d1/e/fe2 |
|
347
|
} -addremove { |
|
348
|
ADDED d/f3 |
|
349
|
ADDED d/e/fe1 |
|
350
|
ADDED d/e/f/ff1 |
|
351
|
ADDED d1/e/fe2 |
|
352
|
} -exists {d/f1 d/f2 d/f3 d/f4 d/e/fe1 d/e/fe1 d/e/f/ff1 |
|
353
|
d1/e/fe1 d1/e/fe2} |
|
354
|
|
|
355
|
|
|
356
|
############################################################################### |
|
357
|
|
|
358
|
test_cleanup |
|
359
|
|