19
19
from bzrlib import (
24
from bzrlib.plugins.fastimport import (
29
from bzrlib.plugins.fastimport.processors import (
22
from bzrlib.plugins.fastimport.helpers import (
25
from bzrlib.plugins.fastimport.tests import (
30
from fastimport import commands
34
35
def load_tests(standard_tests, module, loader):
50
51
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
53
_test_needs_features = [FastimportFeature]
52
55
branch_format = "pack-0.92"
54
57
def get_handler(self):
58
from bzrlib.plugins.fastimport.processors import (
55
61
branch = self.make_branch('.', format=self.branch_format)
56
62
handler = generic_processor.GenericProcessor(branch.bzrdir)
57
63
return handler, branch
193
199
def file_command_iter(self, path, kind='file', content='aaa',
194
200
executable=False, to_kind=None, to_content='bbb', to_executable=None):
195
202
# Revno 1: create a file or symlink
196
203
# Revno 2: modify it
197
204
if to_kind is None:
199
206
if to_executable is None:
200
207
to_executable = executable
208
mode = kind_to_mode(kind, executable)
209
to_mode = kind_to_mode(to_kind, to_executable)
201
210
def command_list():
202
211
author = ['', 'bugs@a.com', time.time(), time.timezone]
203
212
committer = ['', 'elmer@a.com', time.time(), time.timezone]
205
yield commands.FileModifyCommand(path, kind, executable,
214
yield commands.FileModifyCommand(path, mode, None, content)
207
215
yield commands.CommitCommand('head', '1', author,
208
216
committer, "commit 1", None, [], files_one)
210
yield commands.FileModifyCommand(path, to_kind, to_executable,
218
yield commands.FileModifyCommand(path, to_mode, None, to_content)
212
219
yield commands.CommitCommand('head', '2', author,
213
220
committer, "commit 2", ":1", [], files_two)
214
221
return command_list
311
318
class TestImportToPackModifyTwice(TestCaseForGenericProcessor):
312
319
"""This tests when the same file is modified twice in the one commit.
314
321
Note: hg-fast-export produces data like this on occasions.
317
324
def file_command_iter(self, path, kind='file', content='aaa',
318
325
executable=False, to_kind=None, to_content='bbb', to_executable=None):
319
327
# Revno 1: create a file twice
320
328
if to_kind is None:
325
333
author = ['', 'bugs@a.com', time.time(), time.timezone]
326
334
committer = ['', 'elmer@a.com', time.time(), time.timezone]
328
yield commands.FileModifyCommand(path, kind, executable,
336
yield commands.FileModifyCommand(path, kind_to_mode(kind, executable),
330
yield commands.FileModifyCommand(path, to_kind, to_executable,
338
yield commands.FileModifyCommand(path, kind_to_mode(to_kind, to_executable),
331
339
None, to_content)
332
340
yield commands.CommitCommand('head', '1', author,
333
341
committer, "commit 1", None, [], files_one)
346
354
class TestImportToPackModifyTricky(TestCaseForGenericProcessor):
348
356
def file_command_iter(self, path1, path2, kind='file'):
349
358
# Revno 1: create a file or symlink in a directory
350
359
# Revno 2: create a second file that implicitly deletes the
351
360
# first one because either:
355
364
author = ['', 'bugs@a.com', time.time(), time.timezone]
356
365
committer = ['', 'elmer@a.com', time.time(), time.timezone]
358
yield commands.FileModifyCommand(path1, kind, False,
367
yield commands.FileModifyCommand(path1, kind_to_mode(kind, False),
360
369
yield commands.CommitCommand('head', '1', author,
361
370
committer, "commit 1", None, [], files_one)
363
yield commands.FileModifyCommand(path2, kind, False,
372
yield commands.FileModifyCommand(path2, kind_to_mode(kind, False),
365
374
yield commands.CommitCommand('head', '2', author,
366
375
committer, "commit 2", ":1", [], files_two)
423
432
class TestImportToPackDelete(TestCaseForGenericProcessor):
425
434
def file_command_iter(self, path, kind='file'):
426
436
# Revno 1: create a file or symlink
427
437
# Revno 2: delete it
428
438
def command_list():
429
439
author = ['', 'bugs@a.com', time.time(), time.timezone]
430
440
committer = ['', 'elmer@a.com', time.time(), time.timezone]
432
yield commands.FileModifyCommand(path, kind, False,
442
yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
434
444
yield commands.CommitCommand('head', '1', author,
435
445
committer, "commit 1", None, [], files_one)
494
504
"""Test deletion of a newly added file."""
496
506
def file_command_iter(self, path, kind='file'):
497
508
# Revno 1: create a file or symlink then delete it
498
509
def command_list():
499
510
author = ['', 'bugs@a.com', time.time(), time.timezone]
500
511
committer = ['', 'elmer@a.com', time.time(), time.timezone]
502
yield commands.FileModifyCommand(path, kind, False,
513
yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
504
515
yield commands.FileDeleteCommand(path)
505
516
yield commands.CommitCommand('head', '1', author,
540
551
class TestImportToPackDeleteMultiLevel(TestCaseForGenericProcessor):
542
553
def file_command_iter(self, paths, paths_to_delete):
543
555
# Revno 1: create multiple files
544
556
# Revno 2: delete multiple files
545
557
def command_list():
547
559
committer = ['', 'elmer@a.com', time.time(), time.timezone]
549
561
for i, path in enumerate(paths):
550
yield commands.FileModifyCommand(path, 'file', False,
562
yield commands.FileModifyCommand(path, kind_to_mode('file', False),
551
563
None, "aaa%d" % i)
552
564
yield commands.CommitCommand('head', '1', author,
553
565
committer, "commit 1", None, [], files_one)
616
628
def file_command_iter(self, path, kind='file', content='aaa',
617
629
executable=False, to_kind=None, to_content='bbb', to_executable=None):
618
631
# Revno 1: create a file or symlink
619
632
# Revno 2: delete it and add it
620
633
if to_kind is None:
625
638
author = ['', 'bugs@a.com', time.time(), time.timezone]
626
639
committer = ['', 'elmer@a.com', time.time(), time.timezone]
628
yield commands.FileModifyCommand(path, kind, executable,
641
yield commands.FileModifyCommand(path, kind_to_mode(kind, executable),
630
643
yield commands.CommitCommand('head', '1', author,
631
644
committer, "commit 1", None, [], files_one)
633
646
yield commands.FileDeleteCommand(path)
634
yield commands.FileModifyCommand(path, to_kind, to_executable,
647
yield commands.FileModifyCommand(path, kind_to_mode(to_kind, to_executable),
635
648
None, to_content)
636
649
yield commands.CommitCommand('head', '2', author,
637
650
committer, "commit 2", ":1", [], files_two)
691
704
class TestImportToPackDeleteDirectory(TestCaseForGenericProcessor):
693
706
def file_command_iter(self, paths, dir):
694
708
# Revno 1: create multiple files
695
709
# Revno 2: delete a directory holding those files
696
710
def command_list():
698
712
committer = ['', 'elmer@a.com', time.time(), time.timezone]
700
714
for i, path in enumerate(paths):
701
yield commands.FileModifyCommand(path, 'file', False,
715
yield commands.FileModifyCommand(path, kind_to_mode('file', False),
702
716
None, "aaa%d" % i)
703
717
yield commands.CommitCommand('head', '1', author,
704
718
committer, "commit 1", None, [], files_one)
732
746
"""Test deleting a directory then adding a file in the same commit."""
734
748
def file_command_iter(self, paths, dir, new_path, kind='file'):
735
750
# Revno 1: create files in a directory
736
751
# Revno 2: delete the directory then add a file into it
737
752
def command_list():
739
754
committer = ['', 'elmer@a.com', time.time(), time.timezone]
741
756
for i, path in enumerate(paths):
742
yield commands.FileModifyCommand(path, kind, False,
757
yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
743
758
None, "aaa%d" % i)
744
759
yield commands.CommitCommand('head', '1', author,
745
760
committer, "commit 1", None, [], files_one)
747
762
yield commands.FileDeleteCommand(dir)
748
yield commands.FileModifyCommand(new_path, kind, False,
763
yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
750
765
yield commands.CommitCommand('head', '2', author,
751
766
committer, "commit 2", ":1", [], files_two)
781
796
class TestImportToPackRename(TestCaseForGenericProcessor):
783
798
def get_command_iter(self, old_path, new_path, kind='file'):
784
800
# Revno 1: create a file or symlink
785
801
# Revno 2: rename it
786
802
def command_list():
787
803
author = ['', 'bugs@a.com', time.time(), time.timezone]
788
804
committer = ['', 'elmer@a.com', time.time(), time.timezone]
790
yield commands.FileModifyCommand(old_path, kind, False,
806
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
792
808
yield commands.CommitCommand('head', '1', author,
793
809
committer, "commit 1", None, [], files_one)
856
872
"""Test rename of a newly added file."""
858
874
def get_command_iter(self, old_path, new_path, kind='file'):
859
876
# Revno 1: create a file and rename it
860
877
def command_list():
861
878
author = ['', 'bugs@a.com', time.time(), time.timezone]
862
879
committer = ['', 'elmer@a.com', time.time(), time.timezone]
864
yield commands.FileModifyCommand(old_path, kind, False,
881
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
866
883
yield commands.FileRenameCommand(old_path, new_path)
867
884
yield commands.CommitCommand('head', '1', author,
907
924
"""Test rename to a destination path deleted in this commit."""
909
926
def get_command_iter(self, old_path, new_path, kind='file'):
910
928
# Revno 1: create two files
911
929
# Revno 2: delete one, rename the other one to that path
912
930
def command_list():
913
931
author = ['', 'bugs@a.com', time.time(), time.timezone]
914
932
committer = ['', 'elmer@a.com', time.time(), time.timezone]
916
yield commands.FileModifyCommand(old_path, kind, False,
934
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
918
yield commands.FileModifyCommand(new_path, kind, False,
936
yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
920
938
yield commands.CommitCommand('head', '1', author,
921
939
committer, "commit 1", None, [], files_one)
1019
1037
"""Test rename of a path previously modified in this commit."""
1021
1039
def get_command_iter(self, old_path, new_path, kind='file'):
1022
1041
# Revno 1: create a file or symlink
1023
1042
# Revno 2: modify then rename it
1024
1043
def command_list():
1025
1044
author = ['', 'bugs@a.com', time.time(), time.timezone]
1026
1045
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1027
1046
def files_one():
1028
yield commands.FileModifyCommand(old_path, kind, False,
1047
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1030
1049
yield commands.CommitCommand('head', '1', author,
1031
1050
committer, "commit 1", None, [], files_one)
1032
1051
def files_two():
1033
yield commands.FileModifyCommand(old_path, kind, False,
1052
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1035
1054
yield commands.FileRenameCommand(old_path, new_path)
1036
1055
yield commands.CommitCommand('head', '2', author,
1134
1153
"""Test rename of a path then modfy the new-path in the same commit."""
1136
1155
def get_command_iter(self, old_path, new_path, kind='file'):
1137
1157
# Revno 1: create a file or symlink
1138
1158
# Revno 2: rename it then modify the newly created path
1139
1159
def command_list():
1140
1160
author = ['', 'bugs@a.com', time.time(), time.timezone]
1141
1161
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1142
1162
def files_one():
1143
yield commands.FileModifyCommand(old_path, kind, False,
1163
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1145
1165
yield commands.CommitCommand('head', '1', author,
1146
1166
committer, "commit 1", None, [], files_one)
1147
1167
def files_two():
1148
1168
yield commands.FileRenameCommand(old_path, new_path)
1149
yield commands.FileModifyCommand(new_path, kind, False,
1169
yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1151
1171
yield commands.CommitCommand('head', '2', author,
1152
1172
committer, "commit 2", ":1", [], files_two)
1249
1269
"""Test rename of to a deleted path then modfy the new-path in the same commit."""
1251
1271
def get_command_iter(self, old_path, new_path, kind='file'):
1252
1273
# Revno 1: create two files or symlinks
1253
1274
# Revno 2: delete one, rename the other to it then modify the newly created path
1254
1275
def command_list():
1255
1276
author = ['', 'bugs@a.com', time.time(), time.timezone]
1256
1277
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1257
1278
def files_one():
1258
yield commands.FileModifyCommand(old_path, kind, False,
1279
yield commands.FileModifyCommand(old_path, kind_to_mode(kind, False),
1260
yield commands.FileModifyCommand(new_path, kind, False,
1281
yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1262
1283
yield commands.CommitCommand('head', '1', author,
1263
1284
committer, "commit 1", None, [], files_one)
1264
1285
def files_two():
1265
1286
yield commands.FileDeleteCommand(new_path)
1266
1287
yield commands.FileRenameCommand(old_path, new_path)
1267
yield commands.FileModifyCommand(new_path, kind, False,
1288
yield commands.FileModifyCommand(new_path, kind_to_mode(kind, False),
1269
1290
yield commands.CommitCommand('head', '2', author,
1270
1291
committer, "commit 2", ":1", [], files_two)
1376
1397
class TestImportToPackRenameTricky(TestCaseForGenericProcessor):
1378
1399
def file_command_iter(self, path1, old_path2, new_path2, kind='file'):
1379
1401
# Revno 1: create two files or symlinks in a directory
1380
1402
# Revno 2: rename the second file so that it implicitly deletes the
1381
1403
# first one because either:
1385
1407
author = ['', 'bugs@a.com', time.time(), time.timezone]
1386
1408
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1387
1409
def files_one():
1388
yield commands.FileModifyCommand(path1, kind, False,
1410
yield commands.FileModifyCommand(path1, kind_to_mode(kind, False),
1390
yield commands.FileModifyCommand(old_path2, kind, False,
1412
yield commands.FileModifyCommand(old_path2, kind_to_mode(kind, False),
1392
1414
yield commands.CommitCommand('head', '1', author,
1393
1415
committer, "commit 1", None, [], files_one)
1459
1481
class TestImportToPackCopy(TestCaseForGenericProcessor):
1461
1483
def file_command_iter(self, src_path, dest_path, kind='file'):
1462
1485
# Revno 1: create a file or symlink
1463
1486
# Revno 2: copy it
1464
1487
def command_list():
1465
1488
author = ['', 'bugs@a.com', time.time(), time.timezone]
1466
1489
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1467
1490
def files_one():
1468
yield commands.FileModifyCommand(src_path, kind, False,
1491
yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1470
1493
yield commands.CommitCommand('head', '1', author,
1471
1494
committer, "commit 1", None, [], files_one)
1550
1573
"""Test copy of a newly added file."""
1552
1575
def file_command_iter(self, src_path, dest_path, kind='file'):
1553
1577
# Revno 1: create a file or symlink and copy it
1554
1578
def command_list():
1555
1579
author = ['', 'bugs@a.com', time.time(), time.timezone]
1556
1580
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1557
1581
def files_one():
1558
yield commands.FileModifyCommand(src_path, kind, False,
1582
yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1560
1584
yield commands.FileCopyCommand(src_path, dest_path)
1561
1585
yield commands.CommitCommand('head', '1', author,
1630
1654
class TestImportToPackCopyToDeleted(TestCaseForGenericProcessor):
1632
1656
def file_command_iter(self, src_path, dest_path, kind='file'):
1633
1658
# Revno 1: create two files or symlinks
1634
1659
# Revno 2: delete one and copy the other one to its path
1635
1660
def command_list():
1636
1661
author = ['', 'bugs@a.com', time.time(), time.timezone]
1637
1662
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1638
1663
def files_one():
1639
yield commands.FileModifyCommand(src_path, kind, False,
1664
yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1641
yield commands.FileModifyCommand(dest_path, kind, False,
1666
yield commands.FileModifyCommand(dest_path, kind_to_mode(kind, False),
1643
1668
yield commands.CommitCommand('head', '1', author,
1644
1669
committer, "commit 1", None, [], files_one)
1718
1743
"""Test copy of file/symlink already modified in this commit."""
1720
1745
def file_command_iter(self, src_path, dest_path, kind='file'):
1721
1747
# Revno 1: create a file or symlink
1722
1748
# Revno 2: modify and copy it
1723
1749
def command_list():
1724
1750
author = ['', 'bugs@a.com', time.time(), time.timezone]
1725
1751
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1726
1752
def files_one():
1727
yield commands.FileModifyCommand(src_path, kind, False,
1753
yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1729
1755
yield commands.CommitCommand('head', '1', author,
1730
1756
committer, "commit 1", None, [], files_one)
1731
1757
def files_two():
1732
yield commands.FileModifyCommand(src_path, kind, False,
1758
yield commands.FileModifyCommand(src_path, kind_to_mode(kind, False),
1734
1760
yield commands.FileCopyCommand(src_path, dest_path)
1735
1761
yield commands.CommitCommand('head', '2', author,
1816
1842
class TestImportToPackFileKinds(TestCaseForGenericProcessor):
1818
1844
def get_command_iter(self, path, kind, content):
1819
1846
def command_list():
1820
1847
committer = ['', 'elmer@a.com', time.time(), time.timezone]
1821
1848
def files_one():
1822
yield commands.FileModifyCommand(path, kind, False,
1849
yield commands.FileModifyCommand(path, kind_to_mode(kind, False),
1824
1851
yield commands.CommitCommand('head', '1', None,
1825
1852
committer, "commit 1", None, [], files_one)
1850
1877
committer_c = ['', 'c@elmer.com', time.time(), time.timezone]
1851
1878
committer_d = ['', 'd@elmer.com', time.time(), time.timezone]
1852
1879
def files_one():
1853
yield commands.FileModifyCommand('foo', 'file', False,
1880
yield commands.FileModifyCommand('foo', kind_to_mode('file', False),
1854
1881
None, "content A\n")
1855
1882
yield commands.CommitCommand('head', '1', None,
1856
1883
committer_a, "commit 1", None, [], files_one)
1857
1884
def files_two():
1858
yield commands.FileModifyCommand('foo', 'file', False,
1885
yield commands.FileModifyCommand('foo', kind_to_mode('file', False),
1859
1886
None, "content B\n")
1860
1887
yield commands.CommitCommand('head', '2', None,
1861
1888
committer_b, "commit 2", ":1", [], files_two)
1862
1889
def files_three():
1863
yield commands.FileModifyCommand('foo', 'file', False,
1890
yield commands.FileModifyCommand('foo', kind_to_mode('file', False),
1864
1891
None, "content A\n")
1865
1892
yield commands.CommitCommand('head', '3', None,
1866
1893
committer_c, "commit 3", ":2", [], files_three)