Fossil SCM

fossil-scm / test / mv-rm.test
Blame History Raw 471 lines
1
#
2
# Copyright (c) 2011 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
# MV / RM Commands
19
#
20
21
set path [file dirname [info script]]
22
23
require_no_open_checkout
24
25
########################################
26
# Setup: Add Files and Commit #
27
########################################
28
29
test_setup; set rootDir [file normalize [pwd]]
30
31
set undoMsg "\n \"fossil undo\" is\
32
available to undo changes to the\
33
working checkout."
34
35
write_file f1 "f1"
36
write_file f2 "f2"
37
write_file f3 "f3"
38
write_file f4 "f4"
39
write_file f5 "f5"
40
write_file f6 "f6"
41
write_file f7 "f7"
42
write_file f8 "f8"
43
44
file mkdir [file join $rootDir subdirA]
45
# NOTE: There are no files in subdirA.
46
47
file mkdir [file join $rootDir subdirB]
48
write_file [file join $rootDir subdirB f9] "f9"
49
50
file mkdir [file join $rootDir subdirC]
51
write_file [file join $rootDir subdirC f10] "f10"
52
write_file [file join $rootDir subdirC f11] "f11"
53
write_file f12 "f12"
54
55
file mkdir [file join $rootDir subdirE a]
56
write_file [file join $rootDir subdirE a f14] "f14"
57
58
fossil add f1 f2 f3 f4 f5 f6 f7 f8 subdirB/f9 subdirC/f10 subdirC/f11 f12
59
fossil add subdirE/a/f14
60
fossil commit -m "c1"
61
62
########################################
63
# Test 1: Soft Move Relative Directory #
64
########################################
65
66
file mkdir [file join $rootDir subdir1]
67
cd [file join $rootDir subdir1]
68
69
fossil mv ../f1 .
70
test mv-soft-relative-1 {$RESULT eq "RENAME f1 subdir1/f1"}
71
72
fossil revert
73
test mv-soft-relative-2 {
74
[normalize_result] eq "DELETE subdir1/f1\nREVERT f1${undoMsg}"
75
}
76
77
cd $rootDir
78
79
###################################
80
# Test 2: Soft Move Relative File #
81
###################################
82
83
file mkdir [file join $rootDir subdir2]
84
cd [file join $rootDir subdir2]
85
86
fossil mv ../f2 ./f2
87
test mv-soft-relative-3 {$RESULT eq "RENAME f2 subdir2/f2"}
88
89
fossil revert
90
test mv-soft-relative-4 {
91
[normalize_result] eq "DELETE subdir2/f2\nREVERT f2${undoMsg}"
92
}
93
94
cd $rootDir
95
96
########################################
97
# Test 3: Hard Move Relative Directory #
98
########################################
99
100
file mkdir [file join $rootDir subdir3]
101
cd [file join $rootDir subdir3]
102
103
fossil mv --hard ../f3 .
104
test mv-hard-relative-1 {
105
[normalize_result] eq "RENAME f3 subdir3/f3\nMOVED_FILE ${rootDir}/f3"
106
}
107
108
fossil revert
109
test mv-hard-relative-2 {
110
[normalize_result] eq "DELETE subdir3/f3\nREVERT f3${undoMsg}"
111
}
112
113
cd $rootDir
114
115
###################################
116
# Test 4: Hard Move Relative File #
117
###################################
118
119
file mkdir [file join $rootDir subdir4]
120
cd [file join $rootDir subdir4]
121
122
fossil mv --hard ../f4 ./f4
123
test mv-hard-relative-3 {
124
[normalize_result] eq "RENAME f4 subdir4/f4\nMOVED_FILE ${rootDir}/f4"
125
}
126
127
fossil revert
128
test mv-hard-relative-4 {
129
[normalize_result] eq "DELETE subdir4/f4\nREVERT f4${undoMsg}"
130
}
131
132
cd $rootDir
133
134
########################################
135
# Test 5: Soft Move Absolute Directory #
136
########################################
137
138
file mkdir [file join $rootDir subdir5]
139
cd [file join $rootDir subdir5]
140
141
fossil mv [file join $rootDir f5] [file join $rootDir subdir5]
142
test mv-soft-absolute-1 {$RESULT eq "RENAME f5 subdir5/f5"}
143
144
fossil revert
145
test mv-soft-absolute-2 {
146
[normalize_result] eq "DELETE subdir5/f5\nREVERT f5${undoMsg}"
147
}
148
149
cd $rootDir
150
151
###################################
152
# Test 6: Soft Move Absolute File #
153
###################################
154
155
file mkdir [file join $rootDir subdir6]
156
cd [file join $rootDir subdir6]
157
158
fossil mv [file join $rootDir f6] [file join $rootDir subdir6 f6]
159
test mv-soft-absolute-3 {$RESULT eq "RENAME f6 subdir6/f6"}
160
161
fossil revert
162
test mv-soft-absolute-4 {
163
[normalize_result] eq "DELETE subdir6/f6\nREVERT f6${undoMsg}"
164
}
165
166
cd $rootDir
167
168
########################################
169
# Test 7: Hard Move Absolute Directory #
170
########################################
171
172
file mkdir [file join $rootDir subdir7]
173
cd [file join $rootDir subdir7]
174
175
fossil mv --hard [file join $rootDir f7] [file join $rootDir subdir7]
176
test mv-hard-absolute-1 {
177
[normalize_result] eq "RENAME f7 subdir7/f7\nMOVED_FILE ${rootDir}/f7"
178
}
179
180
fossil revert
181
test mv-hard-absolute-2 {
182
[normalize_result] eq "DELETE subdir7/f7\nREVERT f7${undoMsg}"
183
}
184
185
cd $rootDir
186
187
###################################
188
# Test 8: Hard Move Absolute File #
189
###################################
190
191
file mkdir [file join $rootDir subdir8]
192
cd [file join $rootDir subdir8]
193
194
fossil mv --hard [file join $rootDir f8] [file join $rootDir subdir8 f8]
195
test mv-hard-absolute-3 {
196
[normalize_result] eq "RENAME f8 subdir8/f8\nMOVED_FILE ${rootDir}/f8"
197
}
198
199
fossil revert
200
test mv-hard-absolute-4 {
201
[normalize_result] eq "DELETE subdir8/f8\nREVERT f8${undoMsg}"
202
}
203
204
cd $rootDir
205
206
##########################################
207
# Test 9: Soft Remove Relative Directory #
208
##########################################
209
210
file mkdir [file join $rootDir subdir1]
211
cd [file join $rootDir subdir1]
212
213
fossil rm ../subdirA
214
test rm-soft-relative-1 {$RESULT eq ""}
215
216
fossil rm ../subdirB
217
test rm-soft-relative-2 {$RESULT eq "DELETED subdirB/f9"}
218
219
fossil rm ../subdirC
220
test rm-soft-relative-3 {
221
[normalize_result] eq "DELETED subdirC/f10\nDELETED subdirC/f11"
222
}
223
224
fossil revert
225
test rm-soft-relative-4 {
226
[normalize_result] eq \
227
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
228
}
229
230
cd $rootDir
231
232
######################################
233
# Test 10: Soft Remove Relative File #
234
######################################
235
236
file mkdir [file join $rootDir subdir2]
237
cd [file join $rootDir subdir2]
238
239
fossil rm ../f2
240
test rm-soft-relative-5 {$RESULT eq "DELETED f2"}
241
242
fossil revert
243
test rm-soft-relative-6 {
244
[normalize_result] eq "REVERT f2${undoMsg}"
245
}
246
247
cd $rootDir
248
249
###########################################
250
# Test 11: Hard Remove Relative Directory #
251
###########################################
252
253
file mkdir [file join $rootDir subdir3]
254
cd [file join $rootDir subdir3]
255
256
fossil rm --hard ../subdirA
257
test rm-hard-relative-1 {
258
[normalize_result] eq ""
259
}
260
261
fossil rm --hard ../subdirB
262
test rm-hard-relative-2 {
263
[normalize_result] eq \
264
"DELETED subdirB/f9\nDELETED_FILE ${rootDir}/subdirB/f9"
265
}
266
267
fossil rm --hard ../subdirC
268
test rm-hard-relative-3 {
269
[normalize_result] eq \
270
"DELETED subdirC/f10\nDELETED subdirC/f11\nDELETED_FILE\
271
${rootDir}/subdirC/f10\nDELETED_FILE ${rootDir}/subdirC/f11"
272
}
273
274
fossil revert
275
test rm-hard-relative-4 {
276
[normalize_result] eq \
277
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
278
}
279
280
cd $rootDir
281
282
######################################
283
# Test 12: Hard Remove Relative File #
284
######################################
285
286
file mkdir [file join $rootDir subdir4]
287
cd [file join $rootDir subdir4]
288
289
fossil rm --hard ../f4
290
test rm-hard-relative-5 {
291
[normalize_result] eq "DELETED f4\nDELETED_FILE ${rootDir}/f4"
292
}
293
294
fossil revert
295
test rm-hard-relative-6 {
296
[normalize_result] eq "REVERT f4${undoMsg}"
297
}
298
299
cd $rootDir
300
301
###########################################
302
# Test 13: Soft Remove Absolute Directory #
303
###########################################
304
305
file mkdir [file join $rootDir subdir5]
306
cd [file join $rootDir subdir5]
307
308
fossil rm [file join $rootDir subdirA]
309
test rm-soft-absolute-1 {$RESULT eq ""}
310
311
fossil rm [file join $rootDir subdirB]
312
test rm-soft-absolute-2 {$RESULT eq "DELETED subdirB/f9"}
313
314
fossil rm [file join $rootDir subdirC]
315
test rm-soft-absolute-3 {
316
[normalize_result] eq "DELETED subdirC/f10\nDELETED subdirC/f11"
317
}
318
319
fossil revert
320
test rm-soft-absolute-4 {
321
[normalize_result] eq \
322
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
323
}
324
325
cd $rootDir
326
327
######################################
328
# Test 14: Soft Remove Absolute File #
329
######################################
330
331
file mkdir [file join $rootDir subdir6]
332
cd [file join $rootDir subdir6]
333
334
fossil rm [file join $rootDir f6]
335
test rm-soft-absolute-5 {$RESULT eq "DELETED f6"}
336
337
fossil revert
338
test rm-soft-absolute-6 {
339
[normalize_result] eq "REVERT f6${undoMsg}"
340
}
341
342
cd $rootDir
343
344
###########################################
345
# Test 15: Hard Remove Absolute Directory #
346
###########################################
347
348
file mkdir [file join $rootDir subdir7]
349
cd [file join $rootDir subdir7]
350
351
fossil rm --hard [file join $rootDir subdirA]
352
test rm-hard-absolute-1 {$RESULT eq ""}
353
354
fossil rm --hard [file join $rootDir subdirB]
355
test rm-hard-absolute-2 {
356
[normalize_result] eq \
357
"DELETED subdirB/f9\nDELETED_FILE ${rootDir}/subdirB/f9"
358
}
359
360
fossil rm --hard [file join $rootDir subdirC]
361
test rm-hard-absolute-3 {
362
[normalize_result] eq \
363
"DELETED subdirC/f10\nDELETED subdirC/f11\nDELETED_FILE\
364
${rootDir}/subdirC/f10\nDELETED_FILE ${rootDir}/subdirC/f11"
365
}
366
367
fossil revert
368
test rm-hard-absolute-4 {
369
[normalize_result] eq \
370
"REVERT subdirB/f9\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
371
}
372
373
cd $rootDir
374
375
######################################
376
# Test 16: Hard Remove Absolute File #
377
######################################
378
379
file mkdir [file join $rootDir subdir8]
380
cd [file join $rootDir subdir8]
381
382
fossil rm --hard [file join $rootDir f8]
383
test rm-hard-absolute-5 {
384
[normalize_result] eq "DELETED f8\nDELETED_FILE ${rootDir}/f8"
385
}
386
387
fossil revert
388
test rm-hard-absolute-6 {
389
[normalize_result] eq "REVERT f8${undoMsg}"
390
}
391
392
cd $rootDir
393
394
#######################################
395
# Test 17: Move File to New Directory #
396
#######################################
397
398
fossil mv --hard f12 d2/f13
399
test mv-file-new-directory-1 {
400
[normalize_result] eq "RENAME f12 d2/f13\nMOVED_FILE ${rootDir}/f12"
401
}
402
403
test mv-file-new-directory-2 {[file size d2/f13] == 3}
404
test mv-file-new-directory-3 {[read_file d2/f13] eq "f12"}
405
406
fossil revert
407
test mv-file-new-directory-4 {
408
[normalize_result] eq "DELETE d2/f13\nREVERT f12${undoMsg}"
409
}
410
411
test mv-file-new-directory-5 {[file size f12] == 3}
412
test mv-file-new-directory-6 {[read_file f12] eq "f12"}
413
414
cd $rootDir
415
416
############################################
417
# Test 18: Move Directory to New Directory #
418
############################################
419
420
fossil mv --hard subdirC subdirD
421
test mv-file-new-directory-7 {
422
[normalize_result] eq "RENAME subdirC/f10 subdirD/f10\nRENAME subdirC/f11 subdirD/f11\nMOVED_FILE ${rootDir}/subdirC/f10\nMOVED_FILE ${rootDir}/subdirC/f11"
423
}
424
425
test mv-file-new-directory-8 {[file size subdirD/f10] == 3}
426
test mv-file-new-directory-9 {[read_file subdirD/f10] eq "f10"}
427
test mv-file-new-directory-10 {[file size subdirD/f11] == 3}
428
test mv-file-new-directory-11 {[read_file subdirD/f11] eq "f11"}
429
430
fossil revert
431
test mv-file-new-directory-12 {
432
[normalize_result] eq "DELETE subdirD/f10\nDELETE subdirD/f11\nREVERT subdirC/f10\nREVERT subdirC/f11${undoMsg}"
433
}
434
435
test mv-file-new-directory-13 {[file size subdirC/f10] == 3}
436
test mv-file-new-directory-14 {[read_file subdirC/f10] eq "f10"}
437
test mv-file-new-directory-15 {[file size subdirC/f11] == 3}
438
test mv-file-new-directory-16 {[read_file subdirC/f11] eq "f11"}
439
440
cd $rootDir
441
442
###############################################################################
443
# Test 19: Follow-up Soft Rename of a Directory Already Renamed on Filesystem #
444
###############################################################################
445
446
file rename [file join $rootDir subdirE/a] [file join $rootDir subdirE/a_renamed]
447
448
fossil mv subdirE/a subdirE/a_renamed
449
test mv-soft-already-renamed-directory-1 {
450
[normalize_result] eq "RENAME subdirE/a/f14 subdirE/a_renamed/f14"
451
}
452
453
test mv-soft-already-renamed-directory-2 {[file size subdirE/a_renamed/f14] == 3}
454
test mv-soft-already-renamed-directory-3 {[read_file subdirE/a_renamed/f14] eq "f14"}
455
456
fossil revert
457
test mv-soft-already-renamed-directory-4 {
458
[normalize_result] eq "DELETE subdirE/a_renamed/f14\nREVERT subdirE/a/f14${undoMsg}"
459
}
460
461
test mv-soft-already-renamed-directory-5 {[file size subdirE/a/f14] == 3}
462
test mv-soft-already-renamed-directory-6 {[read_file subdirE/a/f14] eq "f14"}
463
464
file delete -force [file join $rootDir subdirE/a_renamed]
465
466
cd $rootDir
467
468
###############################################################################
469
470
test_cleanup
471

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button