21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#
# Test 'fossil revert' against expected results from 'fossil changes' and
# 'fossil addremove -n', as well as by verifying the existence of files
# on the file system. 'fossil undo' is called after each test
#
proc revert-test {testid revertArgs expectedRevertOutput args} {
global RESULT
set passed 1
set args [dict merge {
-changes {} -addremove {} -exists {} -notexists {}
} $args]
set result [fossil revert {*}$revertArgs]
test_status_list revert-$testid $result $expectedRevertOutput
set statusListTests [list -changes changes -addremove {addremove -n}]
foreach {key fossilArgs} $statusListTests {
set expected [dict get $args $key]
set result [fossil {*}$fossilArgs]
test_status_list revert-$testid$key $result $expected
}
set fileExistsTests [list -exists 1 does -notexists 0 should]
foreach {key expected verb} $fileExistsTests {
foreach path [dict get $args $key] {
if {[file exists $path] != $expected} {
set passed 0
protOut " Failure: File $verb not exist: $path"
}
}
test revert-$testid$key $passed
}
fossil undo
}
require_no_open_checkout
test_setup
# Prepare first commit
#
write_file f1 "f1"
write_file f2 "f2"
write_file f3 "f3"
fossil add f1 f2 f3
fossil commit -m "c1"
# Make changes to be reverted
#
# Add f0
write_file f0 "f0"
fossil add f0
# Remove f1
|
<
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#
# Test 'fossil revert' against expected results from 'fossil changes' and
# 'fossil addremove -n', as well as by verifying the existence of files
# on the file system. 'fossil undo' is called after each test
#
proc revert-test {testid revertArgs expectedRevertOutput args} {
set passed 1
set args [dict merge {
-changes {} -addremove {} -exists {} -notexists {}
} $args]
set result [fossil revert {*}$revertArgs]
test_status_list revert-$testid $result $expectedRevertOutput
set statusListTests [list -changes changes -addremove {addremove -n}]
foreach {key fossilArgs} $statusListTests {
set expected [dict get $args $key]
set result [fossil {*}$fossilArgs]
test_status_list revert-$testid$key $result $expected
}
set fileExistsTests [list -exists 1 does -notexists 0 should]
foreach {key expected verb} $fileExistsTests {
set passed 1
foreach path [dict get $args $key] {
if {[file exists $path] != $expected} {
set passed 0
protOut " Failure: File $verb not exist: $path"
}
}
test revert-$testid$key $passed
}
fossil undo
}
# Test that a 'fossil revert' call is a no-op.
proc noop-revert-test {testid revertArgs} {
set changes [fossil changes]
set undo [fossil undo -n]
test revert-$testid {[fossil revert {*}$revertArgs] eq ""}
test revert-$testid-changes {[fossil changes] eq $changes}
test revert-$testid-undo {[fossil undo -n] eq $undo}
}
require_no_open_checkout
test_setup
# Prepare first commit
#
write_file f1 "f1"
write_file f2 "f2"
write_file f3 "f3"
write_file f4 "f4"
fossil add f1 f2 f3 f4
fossil commit -m "c1" --tag c1
write_file f4 "f4.1"
fossil commit -m "c2" --tag c2
# Make changes to be reverted
#
# Add f0
write_file f0 "f0"
fossil add f0
# Remove f1
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
UNMANAGE f0
REVERT f1
REVERT f2
REVERT f3
DELETE f3n
} -addremove {
ADDED f0
} -exists {f0 f1 f2 f3} -notexists f3n
# Test with a single filename argument
#
revert-test 1-2 f0 {
UNMANAGE f0
} -changes {
DELETED f1
EDITED f2
RENAMED f3n
} -addremove {
ADDED f0
} -exists {f0 f2 f3n} -notexists f3
revert-test 1-3 f1 {
REVERT f1
} -changes {
ADDED f0
EDITED f2
RENAMED f3n
} -exists {f0 f1 f2 f3n} -notexists f3
revert-test 1-4 f2 {
REVERT f2
} -changes {
ADDED f0
DELETED f1
RENAMED f3n
} -exists {f0 f2 f3n} -notexists {f1 f3}
# Both files involved in a rename are reverted regardless of which filename
# is used as an argument to 'fossil revert'
#
revert-test 1-5 f3 {
REVERT f3
DELETE f3n
} -changes {
ADDED f0
DELETED f1
EDITED f2
} -exists {f0 f2 f3} -notexists {f1 f3n}
revert-test 1-6 f3n {
REVERT f3
DELETE f3n
} -changes {
ADDED f0
DELETED f1
EDITED f2
} -exists {f0 f2 f3} -notexists {f1 f3n}
# Test with multiple filename arguments
#
revert-test 1-7 {f0 f2 f3n} {
UNMANAGE f0
REVERT f2
REVERT f3
DELETE f3n
} -changes {
DELETED f1
} -addremove {
ADDED f0
} -exists {f0 f2 f3} -notexists {f1 f3n}
# Test reverting the combination of a renamed file and an added file that
# uses the renamed file's original filename.
#
test_setup
write_file f1 "f1"
fossil add f1
fossil commit -m "add f1"
write_file f1n "f1n"
fossil mv f1 f1n
write_file f1 "f1b"
fossil add f1
revert-test 2-1 {} {
REVERT f1
DELETE f1n
} -exists {f1} -notexists {f1n}
# Test reverting a rename in the repo but not completed in the file
# system
test_setup
write_file f1 "f1"
fossil add f1
fossil commit -m "add f1"
fossil mv --soft f1 f1new
test 3-mv-1 {[file exists f1]}
test 3-mv-2 {![file exists f1new]}
revert-test 3-1 {} {
REVERT f1
DELETE f1new
} -exists {f1} -notexists {f1n}
###############################################################################
test_cleanup
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
UNMANAGE f0
REVERT f1
REVERT f2
REVERT f3
DELETE f3n
} -addremove {
ADDED f0
} -exists {f0 f1 f2 f3 f4} -notexists f3n
# Test with a single filename argument
#
revert-test 1-2 f0 {
UNMANAGE f0
} -changes {
DELETED f1
EDITED f2
RENAMED f3n
} -addremove {
ADDED f0
} -exists {f0 f2 f3n f4} -notexists {f1 f3}
revert-test 1-3 f1 {
REVERT f1
} -changes {
ADDED f0
EDITED f2
RENAMED f3n
} -exists {f0 f1 f2 f3n f4} -notexists f3
revert-test 1-4 f2 {
REVERT f2
} -changes {
ADDED f0
DELETED f1
RENAMED f3n
} -exists {f0 f2 f3n f4} -notexists {f1 f3}
# Both files involved in a rename are reverted regardless of which filename
# is used as an argument to 'fossil revert'
#
revert-test 1-5 f3 {
REVERT f3
DELETE f3n
} -changes {
ADDED f0
DELETED f1
EDITED f2
} -exists {f0 f2 f3 f4} -notexists {f1 f3n}
revert-test 1-6 f3n {
REVERT f3
DELETE f3n
} -changes {
ADDED f0
DELETED f1
EDITED f2
} -exists {f0 f2 f3 f4} -notexists {f1 f3n}
# Test with multiple filename arguments
#
revert-test 1-7 {f0 f2 f3n} {
UNMANAGE f0
REVERT f2
REVERT f3
DELETE f3n
} -changes {
DELETED f1
} -addremove {
ADDED f0
} -exists {f0 f2 f3 f4} -notexists {f1 f3n}
# Test with a revision specified
#
revert-test 1-8 {-r c1 f4} {
REVERT f4
} -changes {
ADDED f0
DELETED f1
EDITED f2
RENAMED f3n
EDITED f4
} -exists {f0 f2 f3n f4} -notexists {f1 f3}
# Revision specified, no-op revert
#
noop-revert-test 1-9 {-r c2 f4 z1}
# Invalid revision
#
fossil revert -r turnk f4
test revert-1-10 {$RESULT eq "not found: turnk"}
# Test case-sensitivity
#
fossil set case-sensitive 0
revert-test 1-11 F3 {
REVERT f3
DELETE f3n
} -changes {
ADDED f0
DELETED f1
EDITED f2
} -exists {f0 f2 f3 f4} -notexists {f1 f3n}
fossil set case-sensitive 1
noop-revert-test 1-12 {F1 f4}
fossil unset case-sensitive
# No-op revert, no files or revision specified
#
fossil revert
fossil clean -f
noop-revert-test 1-13 {}
# Reverting a no-op merge is not a no-op revert
#
fossil merge -f c1
revert-test 1-14 {} {}
# Test reverting the combination of a renamed file and an added file that
# uses the renamed file's original filename.
#
test_setup
write_file f1 "f1"
fossil add f1
fossil commit -m "add f1"
write_file f1n "f1n"
fossil mv f1 f1n
write_file f1 "f1b"
fossil add f1
foreach {testnum args} {1 {} 2 f1 3 {f1 f1n}} {
revert-test 2-$testnum $args {
REVERT f1
DELETE f1n
} -exists {f1} -notexists {f1n}
}
fossil revert f1n
test revert-2-2 {$RESULT eq "cannot revert 'f1n' without 'f1'"}
# Test reverting a rename in the repo but not completed in the file
# system
test_setup
write_file f1 "f1"
fossil add f1
fossil commit -m "add f1"
fossil mv --soft f1 f1new
test 3-mv-1 {[file exists f1]}
test 3-mv-2 {![file exists f1new]}
revert-test 3-1 {} {
REVERT f1
DELETE f1new
} -exists {f1} -notexists {f1n}
# Test chained renames
#
test_setup
write_file f1 "f1"
write_file f2 "f2"
write_file f3 "f3"
fossil add f1 f2 f3
fossil commit -m "add files"
fossil mv --hard f1 f0
fossil mv --hard f2 f1
fossil mv --hard f3 f2
revert-test 4-1 f2 {
DELETE f1
REVERT f2
REVERT f3
} -changes {
RENAMED f0
} -exists {f0 f2 f3} -notexists {f1}
fossil revert f1
test revert-4-2 {$RESULT eq "cannot revert 'f1' without 'f2'"}
###############################################################################
test_cleanup
|