blob: 8f318a6b57f204776842c210ae3b4254f3bde503 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
#
# Copyright (c) 2011 D. Richard Hipp
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Simplified BSD License (also
# known as the "2-Clause License" or "FreeBSD License".)
#
# This program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of
# merchantability or fitness for a particular purpose.
#
# Author contact information:
# drh@hwaci.com
# http://www.hwaci.com/drh/
#
############################################################################
#
# MV / RM Commands
#
set path [file dirname [info script]]
require_no_open_checkout
########################################
# Setup: Add Files and Commit #
########################################
test_setup; set rootDir [file normalize [pwd]]
set undoMsg "\n \"fossil undo\" is\
available to undo changes to the\
working checkout."
write_file f1 "f1"
write_file f2 "f2"
write_file f3 "f3"
write_file f4 "f4"
write_file f5 "f5"
write_file f6 "f6"
write_file f7 "f7"
write_file f8 "f8"
file mkdir [file join $rootDir subdirA]
# NOTE: There are no files in subdirA.
file mkdir [file join $rootDir subdirB]
write_file [file join $rootDir subdirB f9] "f9"
file mkdir [file join $rootDir subdirC]
write_file [file join $rootDir subdirC f10] "f10"
write_file [file join $rootDir subdirC f11] "f11"
write_file f12 "f12"
file mkdir [file join $rootDir subdirE a]
write_file [file join $rootDir subdirE a f14] "f14"
fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11 f12
fossil add subdirE/a/f14
fossil commit -m "c1"
########################################
# Test 1: Soft Move Relative Directory #
########################################
file mkdir [file join $rootDir subdir1]
cd [file join $rootDir subdir1]
fossil mv ../f1 .
test mv-soft-relative-1 {$RESULT eq "RENAME f1 subdir1/f1"}
fossil revert
test mv-soft-relative-2 {
[normalize_result] eq "DELETE subdir1/f1\nREVERT f1${undoMsg}"
}
cd $rootDir
###################################
# Test 2: Soft Move Relative File #
###################################
file mkdir [file join $rootDir subdir2]
cd [file join $rootDir subdir2]
fossil mv ../f2 ./f2
test mv-soft-relative-3 {$RESULT eq "RENAME f2 subdir2/f2"}
fossil revert
test mv-soft-relative-4 {
[normalize_result] eq "DELETE subdir2/f2\nREVERT f2${undoMsg}"
}
cd $rootDir
########################################
# Test 3: Hard Move Relative Directory #
########################################
file mkdir [file join $rootDir subdir3]
cd [file join $rootDir subdir3]
fossil mv --hard ../f3 .
test mv-hard-relative-1 {
[normalize_result] eq "RENAME f3 subdir3/f3\nMOVED_FILE ${rootDir}/f3"
}
fossil revert
test mv-hard-relative-2 {
[normalize_result] eq "DELETE subdir3/f3\nREVERT f3${undoMsg}"
}
cd $rootDir
###################################
# Test 4: Hard Move Relative File #
###################################
file mkdir [file join $rootDir subdir4]
cd [file join $rootDir subdir4]
fossil mv --hard ../f4 ./f4
test mv-hard-relative-3 {
[normalize_result] eq "RENAME f4 subdir4/f4\nMOVED_FILE ${rootDir}/f4"
}
fossil revert
test mv-hard-relative-4 {
[normalize_result] eq "DELETE subdir4/f4\nREVERT f4${undoMsg}"
}
cd $rootDir
########################################
# Test 5: Soft Move Absolute Directory #
########################################
file mkdir [file join $rootDir subdir5]
cd [file join $rootDir subdir5]
fossil mv [file join $rootDir f5] [file join $rootDir subdir5]
test mv-soft-absolute-1 {$RESULT eq "RENAME f5 subdir5/f5"}
fossil revert
test mv-soft-absolute-2 {
[normalize_result] eq "DELETE subdir5/f5\nREVERT f5${undoMsg}"
}
cd $rootDir
###################################
# Test 6: Soft Move Absolute File #
###################################
file mkdir [file join $rootDir subdir6]
cd [file join $rootDir subdir6]
fossil mv [file join $rootDir f6] [file join $rootDir subdir6 f6]
test mv-soft-absolute-3 {$RESULT eq "RENAME f6 subdir6/f6"}
fossil revert
test mv-soft-absolute-4 {
[normalize_result] eq "DELETE subdir6/f6\nREVERT f6${undoMsg}"
}
cd $rootDir
########################################
# Test 7: Hard Move Absolute Directory #
########################################
file mkdir [file join $rootDir subdir7]
cd [file join $rootDir subdir7]
fossil mv --hard [file join $rootDir f7] [file join $rootDir subdir7]
test mv-hard-absolute-1 {
[normalize_result] eq "RENAME f7 subdir7/f7\nMOVED_FILE ${rootDir}/f7"
}
fossil revert
test mv-hard-absolute-2 {
[normalize_result] eq "DELETE subdir7/f7\nREVERT f7${undoMsg}"
}
cd $rootDir
###################################
# Test 8: Hard Move Absolute File #
###################################
file mkdir [file join $rootDir subdir8]
cd [file join $rootDir subdir8]
fossil mv --hard [file join $rootDir f8] [file join $rootDir subdir8 f8]
test mv-hard-absolute-3 {
[normalize_result] eq "RENAME f8 subdir8/f8\nMOVED_FILE ${rootDir}/f8"
}
fossil revert
test mv-hard-absolute-4 {
[normalize_result] eq "DELETE subdir8/f8\nREVERT f8${undoMsg}"
}
cd $rootDir
##########################################
# Test 9: Soft Remove Relative Directory #
##########################################
file mkdir [file join $rootDir subdir1]
cd [file join $rootDir subdir1]
fossil rm ../subdirA
test rm-soft-relative-1 {$RESULT eq ""}
fossil rm ../subdirB
test rm-soft-relative-2 {$RESULT eq "DELETED subdirB/f9"}
fossil rm ../subdirC
test rm-soft-relative-3 {
[normalize_result] eq "DELETED subdirC/f10\nDELETED subdirC/f11"
}
fossil revert
test rm-soft-relative-4 {
[normalize_result] eq \
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
}
cd $rootDir
######################################
# Test 10: Soft Remove Relative File #
######################################
file mkdir [file join $rootDir subdir2]
cd [file join $rootDir subdir2]
fossil rm ../f2
test rm-soft-relative-5 {$RESULT eq "DELETED f2"}
fossil revert
test rm-soft-relative-6 {
[normalize_result] eq "REVERT f2${undoMsg}"
}
cd $rootDir
###########################################
# Test 11: Hard Remove Relative Directory #
###########################################
file mkdir [file join $rootDir subdir3]
cd [file join $rootDir subdir3]
fossil rm --hard ../subdirA
test rm-hard-relative-1 {
[normalize_result] eq ""
}
fossil rm --hard ../subdirB
test rm-hard-relative-2 {
[normalize_result] eq \
"DELETED subdirB/f9\nDELETED_FILE ${rootDir}/subdirB/f9"
}
fossil rm --hard ../subdirC
test rm-hard-relative-3 {
[normalize_result] eq \
"DELETED subdirC/f10\nDELETED subdirC/f11\nDELETED_FILE\
${rootDir}/subdirC/f10\nDELETED_FILE ${rootDir}/subdirC/f11"
}
fossil revert
test rm-hard-relative-4 {
[normalize_result] eq \
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
}
cd $rootDir
######################################
# Test 12: Hard Remove Relative File #
######################################
file mkdir [file join $rootDir subdir4]
cd [file join $rootDir subdir4]
fossil rm --hard ../f4
test rm-hard-relative-5 {
[normalize_result] eq "DELETED f4\nDELETED_FILE ${rootDir}/f4"
}
fossil revert
test rm-hard-relative-6 {
[normalize_result] eq "REVERT f4${undoMsg}"
}
cd $rootDir
###########################################
# Test 13: Soft Remove Absolute Directory #
###########################################
file mkdir [file join $rootDir subdir5]
cd [file join $rootDir subdir5]
fossil rm [file join $rootDir subdirA]
test rm-soft-absolute-1 {$RESULT eq ""}
fossil rm [file join $rootDir subdirB]
test rm-soft-absolute-2 {$RESULT eq "DELETED subdirB/f9"}
fossil rm [file join $rootDir subdirC]
test rm-soft-absolute-3 {
[normalize_result] eq "DELETED subdirC/f10\nDELETED subdirC/f11"
}
fossil revert
test rm-soft-absolute-4 {
[normalize_result] eq \
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
}
cd $rootDir
######################################
# Test 14: Soft Remove Absolute File #
######################################
file mkdir [file join $rootDir subdir6]
cd [file join $rootDir subdir6]
fossil rm [file join $rootDir f6]
test rm-soft-absolute-5 {$RESULT eq "DELETED f6"}
fossil revert
test rm-soft-absolute-6 {
[normalize_result] eq "REVERT f6${undoMsg}"
}
cd $rootDir
###########################################
# Test 15: Hard Remove Absolute Directory #
###########################################
file mkdir [file join $rootDir subdir7]
cd [file join $rootDir subdir7]
fossil rm --hard [file join $rootDir subdirA]
test rm-hard-absolute-1 {$RESULT eq ""}
fossil rm --hard [file join $rootDir subdirB]
test rm-hard-absolute-2 {
[normalize_result] eq \
"DELETED subdirB/f9\nDELETED_FILE ${rootDir}/subdirB/f9"
}
fossil rm --hard [file join $rootDir subdirC]
test rm-hard-absolute-3 {
[normalize_result] eq \
"DELETED subdirC/f10\nDELETED subdirC/f11\nDELETED_FILE\
${rootDir}/subdirC/f10\nDELETED_FILE ${rootDir}/subdirC/f11"
}
fossil revert
test rm-hard-absolute-4 {
[normalize_result] eq \
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
}
cd $rootDir
######################################
# Test 16: Hard Remove Absolute File #
######################################
file mkdir [file join $rootDir subdir8]
cd [file join $rootDir subdir8]
fossil rm --hard [file join $rootDir f8]
test rm-hard-absolute-5 {
[normalize_result] eq "DELETED f8\nDELETED_FILE ${rootDir}/f8"
}
fossil revert
test rm-hard-absolute-6 {
[normalize_result] eq "REVERT f8${undoMsg}"
}
cd $rootDir
#######################################
# Test 17: Move File to New Directory #
#######################################
fossil mv --hard f12 d2/f13
test mv-file-new-directory-1 {
[normalize_result] eq "RENAME f12 d2/f13\nMOVED_FILE ${rootDir}/f12"
}
test mv-file-new-directory-2 {[file size d2/f13] == 3}
test mv-file-new-directory-3 {[read_file d2/f13] eq "f12"}
fossil revert
test mv-file-new-directory-4 {
[normalize_result] eq "DELETE d2/f13\nREVERT f12${undoMsg}"
}
test mv-file-new-directory-5 {[file size f12] == 3}
test mv-file-new-directory-6 {[read_file f12] eq "f12"}
cd $rootDir
############################################
# Test 18: Move Directory to New Directory #
############################################
fossil mv --hard subdirC subdirD
test mv-file-new-directory-7 {
[normalize_result] eq "RENAME subdirC/f10 subdirD/f10\nRENAME subdirC/f11 subdirD/f11\nMOVED_FILE ${rootDir}/subdirC/f10\nMOVED_FILE ${rootDir}/subdirC/f11"
}
test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}
fossil revert
test mv-file-new-directory-12 {
[normalize_result] eq "DELETE subdirD/f10\nDELETE subdirD/f11\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
}
test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
test mv-file-new-directory-15 {[file size subdirC/f11] == 3}
test mv-file-new-directory-16 {[read_file subdirC/f11] eq "f11"}
cd $rootDir
###############################################################################
# Test 19: Follow-up Soft Rename of a Directory Already Renamed on Filesystem #
###############################################################################
file rename [file join $rootDir subdirE/a] [file join $rootDir subdirE/a_renamed]
fossil mv subdirE/a subdirE/a_renamed
test mv-soft-already-renamed-directory-1 {
[normalize_result] eq "RENAME subdirE/a/f14 subdirE/a_renamed/f14"
}
test mv-soft-already-renamed-directory-2 {[file size subdirE/a_renamed/f14] == 3}
test mv-soft-already-renamed-directory-3 {[read_file subdirE/a_renamed/f14] eq "f14"}
fossil revert
test mv-soft-already-renamed-directory-4 {
[normalize_result] eq "DELETE subdirE/a_renamed/f14\nREVERT subdirE/a/f14${undoMsg}"
}
test mv-soft-already-renamed-directory-5 {[file size subdirE/a/f14] == 3}
test mv-soft-already-renamed-directory-6 {[read_file subdirE/a/f14] eq "f14"}
file delete -force [file join $rootDir subdirE/a_renamed]
cd $rootDir
###############################################################################
test_cleanup
|