/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.65.4 by James Westby
Make the rename handling more robust.
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
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.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
import time
18
19
from bzrlib import (
20
    branch,
21
    tests,
22
    )
23
24
from bzrlib.plugins.fastimport import (
25
    commands,
26
    errors,
27
    )
28
29
from bzrlib.plugins.fastimport.processors import (
30
    generic_processor,
31
    )
32
33
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
34
class TestCaseForGenericProcessor(tests.TestCaseWithTransport):
0.65.4 by James Westby
Make the rename handling more robust.
35
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
36
    branch_format = "pack-0.92"
37
0.65.4 by James Westby
Make the rename handling more robust.
38
    def get_handler(self):
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
39
        branch = self.make_branch('.', format=self.branch_format)
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
40
        handler = generic_processor.GenericProcessor(branch.bzrdir)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
41
        return handler, branch
0.65.4 by James Westby
Make the rename handling more robust.
42
43
    # FIXME: [] as a default is bad, as it is mutable, but I want
44
    # to use None to mean "don't check this".
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
45
    def assertChanges(self, branch, revno, expected_added=[],
46
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
47
            expected_renamed=[], expected_kind_changed=[]):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
48
        """Check the changes introduced in a revision of a branch.
49
50
        This method checks that a revision introduces expected changes.
51
        The required changes are passed in as a list, where
52
        each entry contains the needed information about the change.
53
54
        If you do not wish to assert anything about a particular
55
        category then pass None instead.
56
57
        branch: The branch.
58
        revno: revision number of revision to check.
59
        expected_added: a list of (filename,) tuples that must have
60
            been added in the delta.
61
        expected_removed: a list of (filename,) tuples that must have
62
            been removed in the delta.
63
        expected_modified: a list of (filename,) tuples that must have
64
            been modified in the delta.
65
        expected_renamed: a list of (old_path, new_path) tuples that
66
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
67
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
68
            that must have been changed in the delta.
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
69
        :return: revtree1, revtree2
70
        """
71
        repo = branch.repository
0.80.1 by Ian Clatworthy
basic units tests for filemodify
72
        revtree1 = repo.revision_tree(branch.get_rev_id(revno - 1))
73
        revtree2 = repo.revision_tree(branch.get_rev_id(revno))
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
74
        changes = revtree2.changes_from(revtree1)
0.80.3 by Ian Clatworthy
file <-> symlink change tests
75
        self._check_changes(changes, expected_added, expected_removed,
76
            expected_modified, expected_renamed, expected_kind_changed)
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
77
        return revtree1, revtree2
78
0.80.3 by Ian Clatworthy
file <-> symlink change tests
79
    def _check_changes(self, changes, expected_added=[],
0.65.4 by James Westby
Make the rename handling more robust.
80
            expected_removed=[], expected_modified=[],
0.80.3 by Ian Clatworthy
file <-> symlink change tests
81
            expected_renamed=[], expected_kind_changed=[]):
0.65.4 by James Westby
Make the rename handling more robust.
82
        """Check the changes in a TreeDelta
83
84
        This method checks that the TreeDelta contains the expected
85
        modifications between the two trees that were used to generate
86
        it. The required changes are passed in as a list, where
87
        each entry contains the needed information about the change.
88
89
        If you do not wish to assert anything about a particular
90
        category then pass None instead.
91
92
        changes: The TreeDelta to check.
93
        expected_added: a list of (filename,) tuples that must have
94
            been added in the delta.
95
        expected_removed: a list of (filename,) tuples that must have
96
            been removed in the delta.
97
        expected_modified: a list of (filename,) tuples that must have
98
            been modified in the delta.
99
        expected_renamed: a list of (old_path, new_path) tuples that
100
            must have been renamed in the delta.
0.80.3 by Ian Clatworthy
file <-> symlink change tests
101
        expected_kind_changed: a list of (path, old_kind, new_kind) tuples
102
            that must have been changed in the delta.
0.65.4 by James Westby
Make the rename handling more robust.
103
        """
104
        renamed = changes.renamed
105
        added = changes.added
106
        removed = changes.removed
107
        modified = changes.modified
0.80.3 by Ian Clatworthy
file <-> symlink change tests
108
        kind_changed = changes.kind_changed
0.65.4 by James Westby
Make the rename handling more robust.
109
        if expected_renamed is not None:
110
            self.assertEquals(len(renamed), len(expected_renamed),
0.74.1 by John Arbash Meinel
Change the rename code to create a new text entry.
111
                "%s is renamed, expected %s" % (renamed, expected_renamed))
0.65.4 by James Westby
Make the rename handling more robust.
112
            renamed_files = [(item[0], item[1]) for item in renamed]
113
            for expected_renamed_entry in expected_renamed:
114
                self.assertTrue(expected_renamed_entry in renamed_files,
115
                    "%s is not renamed, %s are" % (str(expected_renamed_entry),
116
                        renamed_files))
117
        if expected_added is not None:
118
            self.assertEquals(len(added), len(expected_added),
119
                "%s is added" % str(added))
120
            added_files = [(item[0],) for item in added]
121
            for expected_added_entry in expected_added:
122
                self.assertTrue(expected_added_entry in added_files,
123
                    "%s is not added, %s are" % (str(expected_added_entry),
124
                        added_files))
125
        if expected_removed is not None:
126
            self.assertEquals(len(removed), len(expected_removed),
127
                "%s is removed" % str(removed))
128
            removed_files = [(item[0],) for item in removed]
129
            for expected_removed_entry in expected_removed:
130
                self.assertTrue(expected_removed_entry in removed_files,
131
                    "%s is not removed, %s are" % (str(expected_removed_entry),
132
                        removed_files))
133
        if expected_modified is not None:
134
            self.assertEquals(len(modified), len(expected_modified),
135
                "%s is modified" % str(modified))
136
            modified_files = [(item[0],) for item in modified]
137
            for expected_modified_entry in expected_modified:
138
                self.assertTrue(expected_modified_entry in modified_files,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
139
                    "%s is not modified, %s are" % (
140
                    str(expected_modified_entry), modified_files))
141
        if expected_kind_changed is not None:
142
            self.assertEquals(len(kind_changed), len(expected_kind_changed),
143
                "%s is kind-changed, expected %s" % (kind_changed,
144
                    expected_kind_changed))
145
            kind_changed_files = [(item[0], item[2], item[3])
146
                for item in kind_changed]
147
            for expected_kind_changed_entry in expected_kind_changed:
148
                self.assertTrue(expected_kind_changed_entry in
149
                    kind_changed_files, "%s is not kind-changed, %s are" % (
150
                    str(expected_kind_changed_entry), kind_changed_files))
0.65.4 by James Westby
Make the rename handling more robust.
151
0.80.1 by Ian Clatworthy
basic units tests for filemodify
152
    def assertContent(self, branch, tree, path, content):
153
        file_id = tree.inventory.path2id(path)
154
        branch.lock_read()
155
        self.addCleanup(branch.unlock)
156
        self.assertEqual(tree.get_file_text(file_id), content)
157
158
    def assertSymlinkTarget(self, branch, tree, path, target):
159
        file_id = tree.inventory.path2id(path)
160
        branch.lock_read()
161
        self.addCleanup(branch.unlock)
162
        self.assertEqual(tree.get_symlink_target(file_id), target)
163
0.80.4 by Ian Clatworthy
file executable off <-> on tests
164
    def assertExecutable(self, branch, tree, path, executable):
165
        file_id = tree.inventory.path2id(path)
166
        branch.lock_read()
167
        self.addCleanup(branch.unlock)
168
        self.assertEqual(tree.is_executable(file_id), executable)
169
0.80.1 by Ian Clatworthy
basic units tests for filemodify
170
    def assertRevisionRoot(self, revtree, path):
171
        self.assertEqual(revtree.get_revision_id(),
172
                         revtree.inventory.root.children[path].revision)
173
174
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
175
class TestImportToPackModify(TestCaseForGenericProcessor):
0.80.1 by Ian Clatworthy
basic units tests for filemodify
176
0.80.3 by Ian Clatworthy
file <-> symlink change tests
177
    def file_command_iter(self, path, kind='file', content='aaa',
0.80.4 by Ian Clatworthy
file executable off <-> on tests
178
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
179
        # Revno 1: create a file or symlink
180
        # Revno 2: modify it
0.80.3 by Ian Clatworthy
file <-> symlink change tests
181
        if to_kind is None:
182
            to_kind = kind
0.80.4 by Ian Clatworthy
file executable off <-> on tests
183
        if to_executable is None:
184
            to_executable = executable
0.80.1 by Ian Clatworthy
basic units tests for filemodify
185
        def command_list():
186
            author = ['', 'bugs@a.com', time.time(), time.timezone]
187
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
188
            def files_one():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
189
                yield commands.FileModifyCommand(path, kind, executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
190
                        None, content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
191
            yield commands.CommitCommand('head', '1', author,
192
                committer, "commit 1", None, [], files_one)
193
            def files_two():
0.80.4 by Ian Clatworthy
file executable off <-> on tests
194
                yield commands.FileModifyCommand(path, to_kind, to_executable,
0.80.3 by Ian Clatworthy
file <-> symlink change tests
195
                        None, to_content)
0.80.1 by Ian Clatworthy
basic units tests for filemodify
196
            yield commands.CommitCommand('head', '2', author,
197
                committer, "commit 2", ":1", [], files_two)
198
        return command_list
199
200
    def test_modify_file_in_root(self):
201
        handler, branch = self.get_handler()
202
        path = 'a'
203
        handler.process(self.file_command_iter(path))
204
        revtree0, revtree1 = self.assertChanges(branch, 1,
205
            expected_added=[(path,)])
206
        revtree1, revtree2 = self.assertChanges(branch, 2,
207
            expected_modified=[(path,)])
208
        self.assertContent(branch, revtree1, path, "aaa")
209
        self.assertContent(branch, revtree2, path, "bbb")
210
        self.assertRevisionRoot(revtree1, path)
211
        self.assertRevisionRoot(revtree2, path)
212
213
    def test_modify_file_in_subdir(self):
214
        handler, branch = self.get_handler()
215
        path = 'a/a'
216
        handler.process(self.file_command_iter(path))
217
        revtree0, revtree1 = self.assertChanges(branch, 1,
218
            expected_added=[('a',), (path,)])
219
        revtree1, revtree2 = self.assertChanges(branch, 2,
220
            expected_modified=[(path,)])
221
        self.assertContent(branch, revtree1, path, "aaa")
222
        self.assertContent(branch, revtree2, path, "bbb")
223
224
    def test_modify_symlink_in_root(self):
225
        handler, branch = self.get_handler()
226
        path = 'a'
227
        handler.process(self.file_command_iter(path, kind='symlink'))
228
        revtree1, revtree2 = self.assertChanges(branch, 2,
229
            expected_modified=[(path,)])
230
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
231
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
232
        self.assertRevisionRoot(revtree1, path)
233
        self.assertRevisionRoot(revtree2, path)
234
235
    def test_modify_symlink_in_subdir(self):
236
        handler, branch = self.get_handler()
237
        path = 'a/a'
238
        handler.process(self.file_command_iter(path, kind='symlink'))
239
        revtree0, revtree1 = self.assertChanges(branch, 1,
240
            expected_added=[('a',), (path,)])
241
        revtree1, revtree2 = self.assertChanges(branch, 2,
242
            expected_modified=[(path,)])
243
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
244
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
245
0.80.3 by Ian Clatworthy
file <-> symlink change tests
246
    def test_modify_file_becomes_symlink(self):
247
        handler, branch = self.get_handler()
248
        path = 'a/a'
249
        handler.process(self.file_command_iter(path,
250
            kind='file', to_kind='symlink'))
251
        revtree0, revtree1 = self.assertChanges(branch, 1,
252
            expected_added=[('a',), (path,)])
253
        revtree1, revtree2 = self.assertChanges(branch, 2,
254
            expected_kind_changed=[(path, 'file', 'symlink')])
255
        self.assertContent(branch, revtree1, path, "aaa")
256
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
257
258
    def test_modify_symlink_becomes_file(self):
259
        handler, branch = self.get_handler()
260
        path = 'a/a'
261
        handler.process(self.file_command_iter(path,
262
            kind='symlink', to_kind='file'))
263
        revtree0, revtree1 = self.assertChanges(branch, 1,
264
            expected_added=[('a',), (path,)])
265
        revtree1, revtree2 = self.assertChanges(branch, 2,
266
            expected_kind_changed=[(path, 'symlink', 'file')])
267
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
268
        self.assertContent(branch, revtree2, path, "bbb")
269
0.80.4 by Ian Clatworthy
file executable off <-> on tests
270
    def test_modify_file_now_executable(self):
271
        handler, branch = self.get_handler()
272
        path = 'a/a'
273
        handler.process(self.file_command_iter(path,
274
            executable=False, to_executable=True, to_content='aaa'))
275
        revtree0, revtree1 = self.assertChanges(branch, 1,
276
            expected_added=[('a',), (path,)])
277
        revtree1, revtree2 = self.assertChanges(branch, 2,
278
            expected_modified=[(path,)])
279
        self.assertExecutable(branch, revtree1, path, False)
280
        self.assertExecutable(branch, revtree2, path, True)
281
282
    def test_modify_file_no_longer_executable(self):
283
        handler, branch = self.get_handler()
284
        path = 'a/a'
285
        handler.process(self.file_command_iter(path,
286
            executable=True, to_executable=False, to_content='aaa'))
287
        revtree0, revtree1 = self.assertChanges(branch, 1,
288
            expected_added=[('a',), (path,)])
289
        revtree1, revtree2 = self.assertChanges(branch, 2,
290
            expected_modified=[(path,)])
291
        self.assertExecutable(branch, revtree1, path, True)
292
        self.assertExecutable(branch, revtree2, path, False)
293
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
294
0.99.5 by Ian Clatworthy
handle adding the same file twice in the one commit
295
class TestImportToPackModifyTwice(TestCaseForGenericProcessor):
296
    """This tests when the same file is modified twice in the one commit.
297
    
298
    Note: hg-fast-export produces data like this on occasions.
299
    """
300
301
    def file_command_iter(self, path, kind='file', content='aaa',
302
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
303
        # Revno 1: create a file twice
304
        if to_kind is None:
305
            to_kind = kind
306
        if to_executable is None:
307
            to_executable = executable
308
        def command_list():
309
            author = ['', 'bugs@a.com', time.time(), time.timezone]
310
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
311
            def files_one():
312
                yield commands.FileModifyCommand(path, kind, executable,
313
                        None, content)
314
                yield commands.FileModifyCommand(path, to_kind, to_executable,
315
                        None, to_content)
316
            yield commands.CommitCommand('head', '1', author,
317
                committer, "commit 1", None, [], files_one)
318
        return command_list
319
320
    def test_modify_file_twice_in_root(self):
321
        handler, branch = self.get_handler()
322
        path = 'a'
323
        handler.process(self.file_command_iter(path))
324
        revtree0, revtree1 = self.assertChanges(branch, 1,
325
            expected_added=[(path,)])
326
        self.assertContent(branch, revtree1, path, "aaa")
327
        self.assertRevisionRoot(revtree1, path)
328
329
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
330
class TestImportToPackModifyTricky(TestCaseForGenericProcessor):
0.80.5 by Ian Clatworthy
file/symlink <-> directory change tests & fix
331
332
    def file_command_iter(self, path1, path2, kind='file'):
333
        # Revno 1: create a file or symlink in a directory
334
        # Revno 2: create a second file that implicitly deletes the
335
        # first one because either:
336
        # * the new file is a in directory with the old file name
337
        # * the new file has the same name as the directory of the first
338
        def command_list():
339
            author = ['', 'bugs@a.com', time.time(), time.timezone]
340
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
341
            def files_one():
342
                yield commands.FileModifyCommand(path1, kind, False,
343
                        None, "aaa")
344
            yield commands.CommitCommand('head', '1', author,
345
                committer, "commit 1", None, [], files_one)
346
            def files_two():
347
                yield commands.FileModifyCommand(path2, kind, False,
348
                        None, "bbb")
349
            yield commands.CommitCommand('head', '2', author,
350
                committer, "commit 2", ":1", [], files_two)
351
        return command_list
352
353
354
    def test_modify_file_becomes_directory(self):
355
        handler, branch = self.get_handler()
356
        path1 = 'a/b'
357
        path2 = 'a/b/c'
358
        handler.process(self.file_command_iter(path1, path2))
359
        revtree0, revtree1 = self.assertChanges(branch, 1,
360
            expected_added=[('a',), (path1,)])
361
        revtree1, revtree2 = self.assertChanges(branch, 2,
362
            expected_added=[(path2,)],
363
            expected_kind_changed=[(path1, 'file', 'directory')])
364
        self.assertContent(branch, revtree1, path1, "aaa")
365
        self.assertContent(branch, revtree2, path2, "bbb")
366
367
    def test_modify_directory_becomes_file(self):
368
        handler, branch = self.get_handler()
369
        path1 = 'a/b/c'
370
        path2 = 'a/b'
371
        handler.process(self.file_command_iter(path1, path2))
372
        revtree0, revtree1 = self.assertChanges(branch, 1,
373
            expected_added=[('a',), ('a/b',), (path1,)])
374
        revtree1, revtree2 = self.assertChanges(branch, 2,
375
            expected_removed=[(path1,),],
376
            expected_kind_changed=[(path2, 'directory', 'file')])
377
        self.assertContent(branch, revtree1, path1, "aaa")
378
        self.assertContent(branch, revtree2, path2, "bbb")
379
380
    def test_modify_symlink_becomes_directory(self):
381
        handler, branch = self.get_handler()
382
        path1 = 'a/b'
383
        path2 = 'a/b/c'
384
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
385
        revtree0, revtree1 = self.assertChanges(branch, 1,
386
            expected_added=[('a',), (path1,)])
387
        revtree1, revtree2 = self.assertChanges(branch, 2,
388
            expected_added=[(path2,)],
389
            expected_kind_changed=[(path1, 'symlink', 'directory')])
390
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
391
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
392
393
    def test_modify_directory_becomes_symlink(self):
394
        handler, branch = self.get_handler()
395
        path1 = 'a/b/c'
396
        path2 = 'a/b'
397
        handler.process(self.file_command_iter(path1, path2, 'symlink'))
398
        revtree0, revtree1 = self.assertChanges(branch, 1,
399
            expected_added=[('a',), ('a/b',), (path1,)])
400
        revtree1, revtree2 = self.assertChanges(branch, 2,
401
            expected_removed=[(path1,),],
402
            expected_kind_changed=[(path2, 'directory', 'symlink')])
403
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
404
        self.assertSymlinkTarget(branch, revtree2, path2, "bbb")
405
406
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
407
class TestImportToPackDelete(TestCaseForGenericProcessor):
0.80.2 by Ian Clatworthy
basic delete tests
408
409
    def file_command_iter(self, path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
410
        # Revno 1: create a file or symlink
411
        # Revno 2: delete it
0.80.2 by Ian Clatworthy
basic delete tests
412
        def command_list():
413
            author = ['', 'bugs@a.com', time.time(), time.timezone]
414
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
415
            def files_one():
416
                yield commands.FileModifyCommand(path, kind, False,
417
                        None, "aaa")
418
            yield commands.CommitCommand('head', '1', author,
419
                committer, "commit 1", None, [], files_one)
420
            def files_two():
421
                yield commands.FileDeleteCommand(path)
422
            yield commands.CommitCommand('head', '2', author,
423
                committer, "commit 2", ":1", [], files_two)
424
        return command_list
425
426
    def test_delete_file_in_root(self):
427
        handler, branch = self.get_handler()
428
        path = 'a'
429
        handler.process(self.file_command_iter(path))
430
        revtree0, revtree1 = self.assertChanges(branch, 1,
431
            expected_added=[(path,)])
432
        revtree1, revtree2 = self.assertChanges(branch, 2,
433
            expected_removed=[(path,)])
434
        self.assertContent(branch, revtree1, path, "aaa")
435
        self.assertRevisionRoot(revtree1, path)
436
437
    def test_delete_file_in_subdir(self):
438
        handler, branch = self.get_handler()
439
        path = 'a/a'
440
        handler.process(self.file_command_iter(path))
441
        revtree0, revtree1 = self.assertChanges(branch, 1,
442
            expected_added=[('a',), (path,)])
443
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
444
            expected_removed=[('a',), (path,)])
0.80.2 by Ian Clatworthy
basic delete tests
445
        self.assertContent(branch, revtree1, path, "aaa")
446
447
    def test_delete_symlink_in_root(self):
448
        handler, branch = self.get_handler()
449
        path = 'a'
450
        handler.process(self.file_command_iter(path, kind='symlink'))
451
        revtree1, revtree2 = self.assertChanges(branch, 2,
452
            expected_removed=[(path,)])
453
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
454
        self.assertRevisionRoot(revtree1, path)
455
456
    def test_delete_symlink_in_subdir(self):
457
        handler, branch = self.get_handler()
458
        path = 'a/a'
459
        handler.process(self.file_command_iter(path, kind='symlink'))
460
        revtree0, revtree1 = self.assertChanges(branch, 1,
461
            expected_added=[('a',), (path,)])
462
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
463
            expected_removed=[('a',), (path,)])
0.80.2 by Ian Clatworthy
basic delete tests
464
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
465
0.96.2 by Ian Clatworthy
test and fix for implicit directory delete recursing up
466
    def test_delete_file_in_deep_subdir(self):
467
        handler, branch = self.get_handler()
468
        path = 'a/b/c/d'
469
        handler.process(self.file_command_iter(path))
470
        revtree0, revtree1 = self.assertChanges(branch, 1,
471
            expected_added=[('a',), ('a/b',), ('a/b/c',), (path,)])
472
        revtree1, revtree2 = self.assertChanges(branch, 2,
473
            expected_removed=[('a',), ('a/b',), ('a/b/c',), (path,)])
474
        self.assertContent(branch, revtree1, path, "aaa")
475
0.80.2 by Ian Clatworthy
basic delete tests
476
0.99.7 by Ian Clatworthy
handle a delete of a newly added file
477
class TestImportToPackDeleteNew(TestCaseForGenericProcessor):
478
    """Test deletion of a newly added file."""
479
480
    def file_command_iter(self, path, kind='file'):
481
        # Revno 1: create a file or symlink then delete it
482
        def command_list():
483
            author = ['', 'bugs@a.com', time.time(), time.timezone]
484
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
485
            def files_one():
486
                yield commands.FileModifyCommand(path, kind, False,
487
                        None, "aaa")
488
                yield commands.FileDeleteCommand(path)
489
            yield commands.CommitCommand('head', '1', author,
490
                committer, "commit 1", None, [], files_one)
491
        return command_list
492
493
    def test_delete_new_file_in_root(self):
494
        handler, branch = self.get_handler()
495
        path = 'a'
496
        handler.process(self.file_command_iter(path))
497
        revtree0, revtree1 = self.assertChanges(branch, 1,)
498
499
    def test_delete_new_file_in_subdir(self):
500
        handler, branch = self.get_handler()
501
        path = 'a/a'
502
        handler.process(self.file_command_iter(path))
503
        revtree0, revtree1 = self.assertChanges(branch, 1,)
504
505
    def test_delete_new_symlink_in_root(self):
506
        handler, branch = self.get_handler()
507
        path = 'a'
508
        handler.process(self.file_command_iter(path, kind='symlink'))
509
        revtree0, revtree1 = self.assertChanges(branch, 1,)
510
511
    def test_delete_new_symlink_in_subdir(self):
512
        handler, branch = self.get_handler()
513
        path = 'a/a'
514
        handler.process(self.file_command_iter(path, kind='symlink'))
515
        revtree0, revtree1 = self.assertChanges(branch, 1,)
516
517
    def test_delete_new_file_in_deep_subdir(self):
518
        handler, branch = self.get_handler()
519
        path = 'a/b/c/d'
520
        handler.process(self.file_command_iter(path))
521
        revtree0, revtree1 = self.assertChanges(branch, 1,)
522
523
0.101.1 by Tom Widmer
Add test cases to check deletions from multiple levels in a tree still cause pruning of empty dirs to happen correctly.
524
class TestImportToPackDeleteMultiLevel(TestCaseForGenericProcessor):
525
526
    def file_command_iter(self, paths, paths_to_delete):
527
        # Revno 1: create multiple files
528
        # Revno 2: delete multiple files
529
        def command_list():
530
            author = ['', 'bugs@a.com', time.time(), time.timezone]
531
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
532
            def files_one():
533
                for i, path in enumerate(paths):
534
                    yield commands.FileModifyCommand(path, 'file', False,
535
                            None, "aaa%d" % i)
536
            yield commands.CommitCommand('head', '1', author,
537
                committer, "commit 1", None, [], files_one)
538
            def files_two():
539
                for path in paths_to_delete:
540
                    yield commands.FileDeleteCommand(path)
541
            yield commands.CommitCommand('head', '2', author,
542
                committer, "commit 2", ":1", [], files_two)
543
        return command_list
544
545
    def test_delete_files_in_multiple_levels(self):
546
        handler, branch = self.get_handler()
547
        paths = ['a/b/c', 'a/b/d/e']
548
        paths_to_delete = ['a/b/c', 'a/b/d/e']
549
        handler.process(self.file_command_iter(paths, paths_to_delete))
550
        revtree0, revtree1 = self.assertChanges(branch, 1,
551
            expected_added=[
552
                ('a',), ('a/b',), ('a/b/c',),
553
                ('a/b/d',), ('a/b/d/e',),
554
                ])
555
        revtree1, revtree2 = self.assertChanges(branch, 2,
556
            expected_removed=[
557
                ('a',), ('a/b',), ('a/b/c',),
558
                ('a/b/d',), ('a/b/d/e',),
559
                ])
560
561
    def test_delete_file_single_level(self):
562
        handler, branch = self.get_handler()
563
        paths = ['a/b/c', 'a/b/d/e']
564
        paths_to_delete = ['a/b/d/e']
565
        handler.process(self.file_command_iter(paths, paths_to_delete))
566
        revtree0, revtree1 = self.assertChanges(branch, 1,
567
            expected_added=[
568
                ('a',), ('a/b',), ('a/b/c',),
569
                ('a/b/d',), ('a/b/d/e',),
570
                ])
571
        revtree1, revtree2 = self.assertChanges(branch, 2,
572
            expected_removed=[
573
                ('a/b/d',), ('a/b/d/e',),
574
                ])
575
576
    def test_delete_file_complex_level(self):
577
        handler, branch = self.get_handler()
578
        paths = ['a/b/c', 'a/b/d/e', 'a/f/g', 'a/h', 'a/b/d/i/j']
579
        paths_to_delete = ['a/b/c', 'a/b/d/e', 'a/f/g', 'a/b/d/i/j']
580
        handler.process(self.file_command_iter(paths, paths_to_delete))
581
        revtree0, revtree1 = self.assertChanges(branch, 1,
582
            expected_added=[
583
                ('a',), ('a/b',), ('a/b/c',),
584
                ('a/b/d',), ('a/b/d/e',),
585
                ('a/f',), ('a/f/g',),
586
                ('a/h',),
587
                ('a/b/d/i',), ('a/b/d/i/j',),
588
                ])
589
        revtree1, revtree2 = self.assertChanges(branch, 2,
590
            expected_removed=[
591
                ('a/b',), ('a/b/c',),
592
                ('a/b/d',), ('a/b/d/e',),
593
                ('a/f',), ('a/f/g',),
594
                ('a/b/d/i',), ('a/b/d/i/j',),
595
                ])
596
0.99.13 by Ian Clatworthy
Handle delete then add of a file/symlink in the one commit
597
class TestImportToPackDeleteThenAdd(TestCaseForGenericProcessor):
598
    """Test delete followed by an add. Merges can cause this."""
599
600
    def file_command_iter(self, path, kind='file', content='aaa',
601
        executable=False, to_kind=None, to_content='bbb', to_executable=None):
602
        # Revno 1: create a file or symlink
603
        # Revno 2: delete it and add it
604
        if to_kind is None:
605
            to_kind = kind
606
        if to_executable is None:
607
            to_executable = executable
608
        def command_list():
609
            author = ['', 'bugs@a.com', time.time(), time.timezone]
610
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
611
            def files_one():
612
                yield commands.FileModifyCommand(path, kind, executable,
613
                        None, content)
614
            yield commands.CommitCommand('head', '1', author,
615
                committer, "commit 1", None, [], files_one)
616
            def files_two():
617
                yield commands.FileDeleteCommand(path)
618
                yield commands.FileModifyCommand(path, to_kind, to_executable,
619
                        None, to_content)
620
            yield commands.CommitCommand('head', '2', author,
621
                committer, "commit 2", ":1", [], files_two)
622
        return command_list
623
624
    def test_delete_then_add_file_in_root(self):
625
        handler, branch = self.get_handler()
626
        path = 'a'
627
        handler.process(self.file_command_iter(path))
628
        revtree0, revtree1 = self.assertChanges(branch, 1,
629
            expected_added=[(path,)])
630
        revtree1, revtree2 = self.assertChanges(branch, 2,
631
            expected_removed=[(path,)],
632
            expected_added=[(path,)])
633
        self.assertContent(branch, revtree1, path, "aaa")
634
        self.assertContent(branch, revtree2, path, "bbb")
635
        self.assertRevisionRoot(revtree1, path)
636
        self.assertRevisionRoot(revtree2, path)
637
638
    def test_delete_then_add_file_in_subdir(self):
639
        handler, branch = self.get_handler()
640
        path = 'a/a'
641
        handler.process(self.file_command_iter(path))
642
        revtree0, revtree1 = self.assertChanges(branch, 1,
643
            expected_added=[('a',), (path,)])
644
        revtree1, revtree2 = self.assertChanges(branch, 2,
645
            expected_removed=[(path,)],
646
            expected_added=[(path,)])
647
        self.assertContent(branch, revtree1, path, "aaa")
648
        self.assertContent(branch, revtree2, path, "bbb")
649
650
    def test_delete_then_add_symlink_in_root(self):
651
        handler, branch = self.get_handler()
652
        path = 'a'
653
        handler.process(self.file_command_iter(path, kind='symlink'))
654
        revtree1, revtree2 = self.assertChanges(branch, 2,
655
            expected_removed=[(path,)],
656
            expected_added=[(path,)])
657
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
658
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
659
        self.assertRevisionRoot(revtree1, path)
660
        self.assertRevisionRoot(revtree2, path)
661
662
    def test_delete_then_add_symlink_in_subdir(self):
663
        handler, branch = self.get_handler()
664
        path = 'a/a'
665
        handler.process(self.file_command_iter(path, kind='symlink'))
666
        revtree0, revtree1 = self.assertChanges(branch, 1,
667
            expected_added=[('a',), (path,)])
668
        revtree1, revtree2 = self.assertChanges(branch, 2,
669
            expected_removed=[(path,)],
670
            expected_added=[(path,)])
671
        self.assertSymlinkTarget(branch, revtree1, path, "aaa")
672
        self.assertSymlinkTarget(branch, revtree2, path, "bbb")
673
674
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
675
class TestImportToPackDeleteDirectory(TestCaseForGenericProcessor):
0.80.7 by Ian Clatworthy
add directory delete test
676
677
    def file_command_iter(self, paths, dir):
678
        # Revno 1: create multiple files
679
        # Revno 2: delete a directory holding those files
680
        def command_list():
681
            author = ['', 'bugs@a.com', time.time(), time.timezone]
682
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
683
            def files_one():
684
                for i, path in enumerate(paths):
685
                    yield commands.FileModifyCommand(path, 'file', False,
686
                            None, "aaa%d" % i)
687
            yield commands.CommitCommand('head', '1', author,
688
                committer, "commit 1", None, [], files_one)
689
            def files_two():
690
                yield commands.FileDeleteCommand(dir)
691
            yield commands.CommitCommand('head', '2', author,
692
                committer, "commit 2", ":1", [], files_two)
693
        return command_list
694
695
    def test_delete_dir(self):
696
        handler, branch = self.get_handler()
697
        paths = ['a/b/c', 'a/b/d', 'a/b/e/f', 'a/g']
698
        dir = 'a/b'
699
        handler.process(self.file_command_iter(paths, dir))
700
        revtree0, revtree1 = self.assertChanges(branch, 1,
701
            expected_added=[
702
                ('a',), ('a/b',), ('a/b/c',),
703
                ('a/b/d',),
704
                ('a/b/e',), ('a/b/e/f',),
705
                ('a/g',),
706
                ])
707
        revtree1, revtree2 = self.assertChanges(branch, 2,
708
            expected_removed=[
709
                ('a/b',), ('a/b/c',),
710
                ('a/b/d',),
711
                ('a/b/e',), ('a/b/e/f',),
712
                ])
713
714
0.99.21 by Ian Clatworthy
Handle deleting a directory then adding a file within it in the same commit
715
class TestImportToPackDeleteDirectoryThenAddFile(TestCaseForGenericProcessor):
716
    """Test deleting a directory then adding a file in the same commit."""
717
718
    def file_command_iter(self, paths, dir, new_path, kind='file'):
719
        # Revno 1: create files in a directory
720
        # Revno 2: delete the directory then add a file into it
721
        def command_list():
722
            author = ['', 'bugs@a.com', time.time(), time.timezone]
723
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
724
            def files_one():
725
                for i, path in enumerate(paths):
726
                    yield commands.FileModifyCommand(path, kind, False,
727
                            None, "aaa%d" % i)
728
            yield commands.CommitCommand('head', '1', author,
729
                committer, "commit 1", None, [], files_one)
730
            def files_two():
731
                yield commands.FileDeleteCommand(dir)
732
                yield commands.FileModifyCommand(new_path, kind, False,
733
                        None, "bbb")
734
            yield commands.CommitCommand('head', '2', author,
735
                committer, "commit 2", ":1", [], files_two)
736
        return command_list
737
738
    def test_delete_dir_then_add_file(self):
739
        handler, branch = self.get_handler()
740
        paths = ['a/b/c', 'a/b/d']
741
        dir = 'a/b'
742
        new_path = 'a/b/z'
743
        handler.process(self.file_command_iter(paths, dir, new_path))
744
        revtree0, revtree1 = self.assertChanges(branch, 1,
745
            expected_added=[('a',), ('a/b',), ('a/b/c',), ('a/b/d',),])
746
        revtree1, revtree2 = self.assertChanges(branch, 2,
747
            expected_removed=[('a/b',), ('a/b/c',), ('a/b/d',)],
748
            expected_added=[('a/b',), ('a/b/z',)])
749
        self.assertContent(branch, revtree2, new_path, "bbb")
750
751
    def test_delete_dir_then_add_symlink(self):
752
        handler, branch = self.get_handler()
753
        paths = ['a/b/c', 'a/b/d']
754
        dir = 'a/b'
755
        new_path = 'a/b/z'
756
        handler.process(self.file_command_iter(paths, dir, new_path, 'symlink'))
757
        revtree0, revtree1 = self.assertChanges(branch, 1,
758
            expected_added=[('a',), ('a/b',), ('a/b/c',), ('a/b/d',),])
759
        revtree1, revtree2 = self.assertChanges(branch, 2,
760
            expected_removed=[('a/b',), ('a/b/c',), ('a/b/d',)],
761
            expected_added=[('a/b',), ('a/b/z',)])
762
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
763
764
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
765
class TestImportToPackRename(TestCaseForGenericProcessor):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
766
0.99.16 by Ian Clatworthy
add tests for symlink renaming
767
    def get_command_iter(self, old_path, new_path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
768
        # Revno 1: create a file or symlink
769
        # Revno 2: rename it
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
770
        def command_list():
771
            author = ['', 'bugs@a.com', time.time(), time.timezone]
772
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
773
            def files_one():
0.99.16 by Ian Clatworthy
add tests for symlink renaming
774
                yield commands.FileModifyCommand(old_path, kind, False,
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
775
                        None, "aaa")
776
            yield commands.CommitCommand('head', '1', author,
777
                committer, "commit 1", None, [], files_one)
778
            def files_two():
779
                yield commands.FileRenameCommand(old_path, new_path)
780
            yield commands.CommitCommand('head', '2', author,
781
                committer, "commit 2", ":1", [], files_two)
782
        return command_list
783
0.99.16 by Ian Clatworthy
add tests for symlink renaming
784
    def test_rename_file_in_root(self):
785
        handler, branch = self.get_handler()
786
        old_path = 'a'
787
        new_path = 'b'
788
        handler.process(self.get_command_iter(old_path, new_path))
789
        revtree1, revtree2 = self.assertChanges(branch, 2,
790
            expected_renamed=[(old_path, new_path)])
791
        self.assertRevisionRoot(revtree1, old_path)
792
        self.assertRevisionRoot(revtree2, new_path)
793
794
    def test_rename_symlink_in_root(self):
795
        handler, branch = self.get_handler()
796
        old_path = 'a'
797
        new_path = 'b'
798
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
799
        revtree1, revtree2 = self.assertChanges(branch, 2,
800
            expected_renamed=[(old_path, new_path)])
801
        self.assertRevisionRoot(revtree1, old_path)
802
        self.assertRevisionRoot(revtree2, new_path)
803
804
    def test_rename_file_in_subdir(self):
805
        handler, branch = self.get_handler()
806
        old_path = 'a/a'
807
        new_path = 'a/b'
808
        handler.process(self.get_command_iter(old_path, new_path))
809
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
810
811
    def test_rename_symlink_in_subdir(self):
812
        handler, branch = self.get_handler()
813
        old_path = 'a/a'
814
        new_path = 'a/b'
815
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
816
        self.assertChanges(branch, 2, expected_renamed=[(old_path, new_path)])
817
818
    def test_rename_file_to_new_dir(self):
819
        handler, branch = self.get_handler()
820
        old_path = 'a/a'
821
        new_path = 'b/a'
822
        handler.process(self.get_command_iter(old_path, new_path))
823
        self.assertChanges(branch, 2,
824
            expected_renamed=[(old_path, new_path)],
825
            expected_added=[('b',)],
826
            expected_removed=[('a',)])
827
828
    def test_rename_symlink_to_new_dir(self):
829
        handler, branch = self.get_handler()
830
        old_path = 'a/a'
831
        new_path = 'b/a'
832
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
0.96.1 by Ian Clatworthy
update existing tests to reflect implicit directory pruning bahaviour
833
        self.assertChanges(branch, 2,
834
            expected_renamed=[(old_path, new_path)],
835
            expected_added=[('b',)],
836
            expected_removed=[('a',)])
0.64.74 by Ian Clatworthy
fix symlink importing
837
838
0.99.6 by Ian Clatworthy
Handle rename of a just added file
839
class TestImportToPackRenameNew(TestCaseForGenericProcessor):
0.99.8 by Ian Clatworthy
handle copy of a newly added file
840
    """Test rename of a newly added file."""
0.99.6 by Ian Clatworthy
Handle rename of a just added file
841
0.99.16 by Ian Clatworthy
add tests for symlink renaming
842
    def get_command_iter(self, old_path, new_path, kind='file'):
0.99.6 by Ian Clatworthy
Handle rename of a just added file
843
        # Revno 1: create a file and rename it
844
        def command_list():
845
            author = ['', 'bugs@a.com', time.time(), time.timezone]
846
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
847
            def files_one():
0.99.16 by Ian Clatworthy
add tests for symlink renaming
848
                yield commands.FileModifyCommand(old_path, kind, False,
0.99.6 by Ian Clatworthy
Handle rename of a just added file
849
                        None, "aaa")
850
                yield commands.FileRenameCommand(old_path, new_path)
851
            yield commands.CommitCommand('head', '1', author,
852
                committer, "commit 1", None, [], files_one)
853
        return command_list
854
0.99.16 by Ian Clatworthy
add tests for symlink renaming
855
    def test_rename_new_file_in_root(self):
856
        handler, branch = self.get_handler()
857
        old_path = 'a'
858
        new_path = 'b'
859
        handler.process(self.get_command_iter(old_path, new_path))
860
        revtree0, revtree1 = self.assertChanges(branch, 1,
861
            expected_added=[(new_path,)])
862
        self.assertRevisionRoot(revtree1, new_path)
863
864
    def test_rename_new_symlink_in_root(self):
865
        handler, branch = self.get_handler()
866
        old_path = 'a'
867
        new_path = 'b'
868
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
869
        revtree0, revtree1 = self.assertChanges(branch, 1,
870
            expected_added=[(new_path,)])
871
        self.assertRevisionRoot(revtree1, new_path)
872
873
    def test_rename_new_file_in_subdir(self):
874
        handler, branch = self.get_handler()
875
        old_path = 'a/a'
876
        new_path = 'a/b'
877
        handler.process(self.get_command_iter(old_path, new_path))
878
        revtree0, revtree1 = self.assertChanges(branch, 1,
879
            expected_added=[('a',), (new_path,)])
880
881
    def test_rename_new_symlink_in_subdir(self):
882
        handler, branch = self.get_handler()
883
        old_path = 'a/a'
884
        new_path = 'a/b'
885
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
0.99.6 by Ian Clatworthy
Handle rename of a just added file
886
        revtree0, revtree1 = self.assertChanges(branch, 1,
887
            expected_added=[('a',), (new_path,)])
888
889
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
890
class TestImportToPackRenameToDeleted(TestCaseForGenericProcessor):
891
    """Test rename to a destination path deleted in this commit."""
892
0.99.16 by Ian Clatworthy
add tests for symlink renaming
893
    def get_command_iter(self, old_path, new_path, kind='file'):
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
894
        # Revno 1: create two files
895
        # Revno 2: delete one, rename the other one to that path
896
        def command_list():
897
            author = ['', 'bugs@a.com', time.time(), time.timezone]
898
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
899
            def files_one():
0.99.16 by Ian Clatworthy
add tests for symlink renaming
900
                yield commands.FileModifyCommand(old_path, kind, False,
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
901
                        None, "aaa")
0.99.16 by Ian Clatworthy
add tests for symlink renaming
902
                yield commands.FileModifyCommand(new_path, kind, False,
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
903
                        None, "bbb")
904
            yield commands.CommitCommand('head', '1', author,
905
                committer, "commit 1", None, [], files_one)
906
            def files_two():
907
                yield commands.FileDeleteCommand(new_path)
908
                yield commands.FileRenameCommand(old_path, new_path)
909
            yield commands.CommitCommand('head', '2', author,
910
                committer, "commit 2", ":1", [], files_two)
911
        return command_list
912
0.99.16 by Ian Clatworthy
add tests for symlink renaming
913
    def test_rename_to_deleted_file_in_root(self):
914
        handler, branch = self.get_handler()
915
        old_path = 'a'
916
        new_path = 'b'
917
        handler.process(self.get_command_iter(old_path, new_path))
918
        revtree0, revtree1 = self.assertChanges(branch, 1,
919
            expected_added=[(old_path,), (new_path,)])
920
        revtree1, revtree2 = self.assertChanges(branch, 2,
921
            expected_removed=[(new_path,)],
922
            expected_renamed=[(old_path, new_path)])
923
        self.assertContent(branch, revtree1, old_path, "aaa")
924
        self.assertContent(branch, revtree1, new_path, "bbb")
925
        self.assertContent(branch, revtree2, new_path, "aaa")
926
        self.assertRevisionRoot(revtree1, old_path)
927
        self.assertRevisionRoot(revtree1, new_path)
928
929
    def test_rename_to_deleted_symlink_in_root(self):
930
        handler, branch = self.get_handler()
931
        old_path = 'a'
932
        new_path = 'b'
933
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
934
        revtree0, revtree1 = self.assertChanges(branch, 1,
935
            expected_added=[(old_path,), (new_path,)])
936
        revtree1, revtree2 = self.assertChanges(branch, 2,
937
            expected_removed=[(new_path,)],
938
            expected_renamed=[(old_path, new_path)])
939
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
940
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
941
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
942
        self.assertRevisionRoot(revtree1, old_path)
943
        self.assertRevisionRoot(revtree1, new_path)
944
945
    def test_rename_to_deleted_file_in_subdir(self):
946
        handler, branch = self.get_handler()
947
        old_path = 'd/a'
948
        new_path = 'd/b'
949
        handler.process(self.get_command_iter(old_path, new_path))
950
        revtree0, revtree1 = self.assertChanges(branch, 1,
951
            expected_added=[('d',), (old_path,), (new_path,)])
952
        revtree1, revtree2 = self.assertChanges(branch, 2,
953
            expected_removed=[(new_path,)],
954
            expected_renamed=[(old_path, new_path)])
955
        self.assertContent(branch, revtree1, old_path, "aaa")
956
        self.assertContent(branch, revtree1, new_path, "bbb")
957
        self.assertContent(branch, revtree2, new_path, "aaa")
958
959
    def test_rename_to_deleted_symlink_in_subdir(self):
960
        handler, branch = self.get_handler()
961
        old_path = 'd/a'
962
        new_path = 'd/b'
963
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
964
        revtree0, revtree1 = self.assertChanges(branch, 1,
965
            expected_added=[('d',), (old_path,), (new_path,)])
966
        revtree1, revtree2 = self.assertChanges(branch, 2,
967
            expected_removed=[(new_path,)],
968
            expected_renamed=[(old_path, new_path)])
969
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
970
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
971
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
972
973
    def test_rename_to_deleted_file_in_new_dir(self):
974
        handler, branch = self.get_handler()
975
        old_path = 'd1/a'
976
        new_path = 'd2/b'
977
        handler.process(self.get_command_iter(old_path, new_path))
978
        revtree0, revtree1 = self.assertChanges(branch, 1,
979
            expected_added=[('d1',), (old_path,), ('d2',), (new_path,)])
980
        revtree1, revtree2 = self.assertChanges(branch, 2,
981
            expected_removed=[('d1',), (new_path,)],
982
            expected_renamed=[(old_path, new_path)])
983
        self.assertContent(branch, revtree1, old_path, "aaa")
984
        self.assertContent(branch, revtree1, new_path, "bbb")
985
        self.assertContent(branch, revtree2, new_path, "aaa")
986
987
    def test_rename_to_deleted_symlink_in_new_dir(self):
988
        handler, branch = self.get_handler()
989
        old_path = 'd1/a'
990
        new_path = 'd2/b'
991
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
992
        revtree0, revtree1 = self.assertChanges(branch, 1,
993
            expected_added=[('d1',), (old_path,), ('d2',), (new_path,)])
994
        revtree1, revtree2 = self.assertChanges(branch, 2,
995
            expected_removed=[('d1',), (new_path,)],
996
            expected_renamed=[(old_path, new_path)])
997
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
998
        self.assertSymlinkTarget(branch, revtree1, new_path, "bbb")
999
        self.assertSymlinkTarget(branch, revtree2, new_path, "aaa")
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
1000
1001
0.99.17 by Ian Clatworthy
Handle rename of a file/symlink modified already in this commit
1002
class TestImportToPackRenameModified(TestCaseForGenericProcessor):
1003
    """Test rename of a path previously modified in this commit."""
1004
1005
    def get_command_iter(self, old_path, new_path, kind='file'):
1006
        # Revno 1: create a file or symlink
1007
        # Revno 2: modify then rename it
1008
        def command_list():
1009
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1010
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1011
            def files_one():
1012
                yield commands.FileModifyCommand(old_path, kind, False,
1013
                        None, "aaa")
1014
            yield commands.CommitCommand('head', '1', author,
1015
                committer, "commit 1", None, [], files_one)
1016
            def files_two():
1017
                yield commands.FileModifyCommand(old_path, kind, False,
1018
                        None, "bbb")
1019
                yield commands.FileRenameCommand(old_path, new_path)
1020
            yield commands.CommitCommand('head', '2', author,
1021
                committer, "commit 2", ":1", [], files_two)
1022
        return command_list
1023
1024
    def test_rename_of_modified_file_in_root(self):
1025
        handler, branch = self.get_handler()
1026
        old_path = 'a'
1027
        new_path = 'b'
1028
        handler.process(self.get_command_iter(old_path, new_path))
1029
        revtree0, revtree1 = self.assertChanges(branch, 1,
1030
            expected_added=[(old_path,)])
1031
        # Note: the delta doesn't show the modification?
1032
        # The actual new content is validated in the assertions following.
1033
        revtree1, revtree2 = self.assertChanges(branch, 2,
1034
            expected_renamed=[(old_path, new_path)])
1035
        self.assertContent(branch, revtree1, old_path, "aaa")
1036
        self.assertContent(branch, revtree2, new_path, "bbb")
1037
        self.assertRevisionRoot(revtree1, old_path)
1038
        self.assertRevisionRoot(revtree2, new_path)
1039
1040
    def test_rename_of_modified_symlink_in_root(self):
1041
        handler, branch = self.get_handler()
1042
        old_path = 'a'
1043
        new_path = 'b'
1044
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1045
        revtree0, revtree1 = self.assertChanges(branch, 1,
1046
            expected_added=[(old_path,)])
1047
        # Note: the delta doesn't show the modification?
1048
        # The actual new content is validated in the assertions following.
1049
        revtree1, revtree2 = self.assertChanges(branch, 2,
1050
            expected_renamed=[(old_path, new_path)])
1051
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1052
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1053
        self.assertRevisionRoot(revtree1, old_path)
1054
        self.assertRevisionRoot(revtree2, new_path)
1055
1056
    def test_rename_of_modified_file_in_subdir(self):
1057
        handler, branch = self.get_handler()
1058
        old_path = 'd/a'
1059
        new_path = 'd/b'
1060
        handler.process(self.get_command_iter(old_path, new_path))
1061
        revtree0, revtree1 = self.assertChanges(branch, 1,
1062
            expected_added=[('d',), (old_path,)])
1063
        # Note: the delta doesn't show the modification?
1064
        # The actual new content is validated in the assertions following.
1065
        revtree1, revtree2 = self.assertChanges(branch, 2,
1066
            expected_renamed=[(old_path, new_path)])
1067
        self.assertContent(branch, revtree1, old_path, "aaa")
1068
        self.assertContent(branch, revtree2, new_path, "bbb")
1069
1070
    def test_rename_of_modified_symlink_in_subdir(self):
1071
        handler, branch = self.get_handler()
1072
        old_path = 'd/a'
1073
        new_path = 'd/b'
1074
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1075
        revtree0, revtree1 = self.assertChanges(branch, 1,
1076
            expected_added=[('d',), (old_path,)])
1077
        # Note: the delta doesn't show the modification?
1078
        # The actual new content is validated in the assertions following.
1079
        revtree1, revtree2 = self.assertChanges(branch, 2,
1080
            expected_renamed=[(old_path, new_path)])
1081
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1082
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1083
1084
    def test_rename_of_modified_file_to_new_dir(self):
1085
        handler, branch = self.get_handler()
1086
        old_path = 'd1/a'
1087
        new_path = 'd2/b'
1088
        handler.process(self.get_command_iter(old_path, new_path))
1089
        revtree0, revtree1 = self.assertChanges(branch, 1,
1090
            expected_added=[('d1',), (old_path,)])
1091
        # Note: the delta doesn't show the modification?
1092
        # The actual new content is validated in the assertions following.
1093
        revtree1, revtree2 = self.assertChanges(branch, 2,
1094
            expected_renamed=[(old_path, new_path)],
1095
            expected_added=[('d2',)],
1096
            expected_removed=[('d1',)])
1097
        self.assertContent(branch, revtree1, old_path, "aaa")
1098
        self.assertContent(branch, revtree2, new_path, "bbb")
1099
1100
    def test_rename_of_modified_symlink_to_new_dir(self):
1101
        handler, branch = self.get_handler()
1102
        old_path = 'd1/a'
1103
        new_path = 'd2/b'
1104
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1105
        revtree0, revtree1 = self.assertChanges(branch, 1,
1106
            expected_added=[('d1',), (old_path,)])
1107
        # Note: the delta doesn't show the modification?
1108
        # The actual new content is validated in the assertions following.
1109
        revtree1, revtree2 = self.assertChanges(branch, 2,
1110
            expected_renamed=[(old_path, new_path)],
1111
            expected_added=[('d2',)],
1112
            expected_removed=[('d1',)])
1113
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1114
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1115
1116
0.99.19 by Ian Clatworthy
Handle rename then modification of the new path
1117
class TestImportToPackRenameThenModify(TestCaseForGenericProcessor):
1118
    """Test rename of a path then modfy the new-path in the same commit."""
1119
1120
    def get_command_iter(self, old_path, new_path, kind='file'):
1121
        # Revno 1: create a file or symlink
1122
        # Revno 2: rename it then modify the newly created path
1123
        def command_list():
1124
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1125
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1126
            def files_one():
1127
                yield commands.FileModifyCommand(old_path, kind, False,
1128
                        None, "aaa")
1129
            yield commands.CommitCommand('head', '1', author,
1130
                committer, "commit 1", None, [], files_one)
1131
            def files_two():
1132
                yield commands.FileRenameCommand(old_path, new_path)
1133
                yield commands.FileModifyCommand(new_path, kind, False,
1134
                        None, "bbb")
1135
            yield commands.CommitCommand('head', '2', author,
1136
                committer, "commit 2", ":1", [], files_two)
1137
        return command_list
1138
1139
    def test_rename_then_modify_file_in_root(self):
1140
        handler, branch = self.get_handler()
1141
        old_path = 'a'
1142
        new_path = 'b'
1143
        handler.process(self.get_command_iter(old_path, new_path))
1144
        revtree0, revtree1 = self.assertChanges(branch, 1,
1145
            expected_added=[(old_path,)])
1146
        # Note: the delta doesn't show the modification?
1147
        # The actual new content is validated in the assertions following.
1148
        revtree1, revtree2 = self.assertChanges(branch, 2,
1149
            expected_renamed=[(old_path, new_path)])
1150
        self.assertContent(branch, revtree1, old_path, "aaa")
1151
        self.assertContent(branch, revtree2, new_path, "bbb")
1152
        self.assertRevisionRoot(revtree1, old_path)
1153
        self.assertRevisionRoot(revtree2, new_path)
1154
1155
    def test_rename_then_modify_file_in_subdir(self):
1156
        handler, branch = self.get_handler()
1157
        old_path = 'd/a'
1158
        new_path = 'd/b'
1159
        handler.process(self.get_command_iter(old_path, new_path))
1160
        revtree0, revtree1 = self.assertChanges(branch, 1,
1161
            expected_added=[('d',), (old_path,)])
1162
        # Note: the delta doesn't show the modification?
1163
        # The actual new content is validated in the assertions following.
1164
        revtree1, revtree2 = self.assertChanges(branch, 2,
1165
            expected_renamed=[(old_path, new_path)])
1166
        self.assertContent(branch, revtree1, old_path, "aaa")
1167
        self.assertContent(branch, revtree2, new_path, "bbb")
1168
1169
    def test_rename_then_modify_file_in_new_dir(self):
1170
        handler, branch = self.get_handler()
1171
        old_path = 'd1/a'
1172
        new_path = 'd2/b'
1173
        handler.process(self.get_command_iter(old_path, new_path))
1174
        revtree0, revtree1 = self.assertChanges(branch, 1,
1175
            expected_added=[('d1',), (old_path,)])
1176
        # Note: the delta doesn't show the modification?
1177
        # The actual new content is validated in the assertions following.
1178
        revtree1, revtree2 = self.assertChanges(branch, 2,
1179
            expected_renamed=[(old_path, new_path)],
1180
            expected_added=[('d2',)],
1181
            expected_removed=[('d1',)])
1182
        self.assertContent(branch, revtree1, old_path, "aaa")
1183
        self.assertContent(branch, revtree2, new_path, "bbb")
1184
1185
    def test_rename_then_modify_symlink_in_root(self):
1186
        handler, branch = self.get_handler()
1187
        old_path = 'a'
1188
        new_path = 'b'
1189
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1190
        revtree0, revtree1 = self.assertChanges(branch, 1,
1191
            expected_added=[(old_path,)])
1192
        # Note: the delta doesn't show the modification?
1193
        # The actual new content is validated in the assertions following.
1194
        revtree1, revtree2 = self.assertChanges(branch, 2,
1195
            expected_renamed=[(old_path, new_path)])
1196
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1197
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1198
        self.assertRevisionRoot(revtree1, old_path)
1199
        self.assertRevisionRoot(revtree2, new_path)
1200
1201
    def test_rename_then_modify_symlink_in_subdir(self):
1202
        handler, branch = self.get_handler()
1203
        old_path = 'd/a'
1204
        new_path = 'd/b'
1205
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1206
        revtree0, revtree1 = self.assertChanges(branch, 1,
1207
            expected_added=[('d',), (old_path,)])
1208
        # Note: the delta doesn't show the modification?
1209
        # The actual new content is validated in the assertions following.
1210
        revtree1, revtree2 = self.assertChanges(branch, 2,
1211
            expected_renamed=[(old_path, new_path)])
1212
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1213
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1214
1215
    def test_rename_then_modify_symlink_in_new_dir(self):
1216
        handler, branch = self.get_handler()
1217
        old_path = 'd1/a'
1218
        new_path = 'd2/b'
1219
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1220
        revtree0, revtree1 = self.assertChanges(branch, 1,
1221
            expected_added=[('d1',), (old_path,)])
1222
        # Note: the delta doesn't show the modification?
1223
        # The actual new content is validated in the assertions following.
1224
        revtree1, revtree2 = self.assertChanges(branch, 2,
1225
            expected_renamed=[(old_path, new_path)],
1226
            expected_added=[('d2',)],
1227
            expected_removed=[('d1',)])
1228
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1229
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1230
1231
0.64.233 by Ian Clatworthy
Handle delete, rename then modify all in the one commit
1232
class TestImportToPackDeleteRenameThenModify(TestCaseForGenericProcessor):
1233
    """Test rename of to a deleted path then modfy the new-path in the same commit."""
1234
1235
    def get_command_iter(self, old_path, new_path, kind='file'):
1236
        # Revno 1: create two files or symlinks
1237
        # Revno 2: delete one, rename the other to it then modify the newly created path
1238
        def command_list():
1239
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1240
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1241
            def files_one():
1242
                yield commands.FileModifyCommand(old_path, kind, False,
1243
                        None, "aaa")
1244
                yield commands.FileModifyCommand(new_path, kind, False,
1245
                        None, "zzz")
1246
            yield commands.CommitCommand('head', '1', author,
1247
                committer, "commit 1", None, [], files_one)
1248
            def files_two():
1249
                yield commands.FileDeleteCommand(new_path)
1250
                yield commands.FileRenameCommand(old_path, new_path)
1251
                yield commands.FileModifyCommand(new_path, kind, False,
1252
                        None, "bbb")
1253
            yield commands.CommitCommand('head', '2', author,
1254
                committer, "commit 2", ":1", [], files_two)
1255
        return command_list
1256
1257
    def test_delete_rename_then_modify_file_in_root(self):
1258
        handler, branch = self.get_handler()
1259
        old_path = 'a'
1260
        new_path = 'b'
1261
        handler.process(self.get_command_iter(old_path, new_path))
1262
        revtree0, revtree1 = self.assertChanges(branch, 1,
1263
            expected_added=[(old_path,), (new_path,)])
1264
        # Note: the delta doesn't show the modification?
1265
        # The actual new content is validated in the assertions following.
1266
        revtree1, revtree2 = self.assertChanges(branch, 2,
1267
            expected_removed=[(new_path,)],
1268
            expected_renamed=[(old_path, new_path)])
1269
        self.assertContent(branch, revtree1, old_path, "aaa")
1270
        self.assertContent(branch, revtree1, new_path, "zzz")
1271
        self.assertContent(branch, revtree2, new_path, "bbb")
1272
        self.assertRevisionRoot(revtree1, old_path)
1273
        self.assertRevisionRoot(revtree1, new_path)
1274
        self.assertRevisionRoot(revtree2, new_path)
1275
1276
    def test_delete_rename_then_modify_file_in_subdir(self):
1277
        handler, branch = self.get_handler()
1278
        old_path = 'd/a'
1279
        new_path = 'd/b'
1280
        handler.process(self.get_command_iter(old_path, new_path))
1281
        revtree0, revtree1 = self.assertChanges(branch, 1,
1282
            expected_added=[('d',), (old_path,), (new_path,)])
1283
        # Note: the delta doesn't show the modification?
1284
        # The actual new content is validated in the assertions following.
1285
        revtree1, revtree2 = self.assertChanges(branch, 2,
1286
            expected_removed=[(new_path,)],
1287
            expected_renamed=[(old_path, new_path)])
1288
        self.assertContent(branch, revtree1, old_path, "aaa")
1289
        self.assertContent(branch, revtree1, new_path, "zzz")
1290
        self.assertContent(branch, revtree2, new_path, "bbb")
1291
1292
    def test_delete_rename_then_modify_file_in_new_dir(self):
1293
        handler, branch = self.get_handler()
1294
        old_path = 'd1/a'
1295
        new_path = 'd2/b'
1296
        handler.process(self.get_command_iter(old_path, new_path))
1297
        revtree0, revtree1 = self.assertChanges(branch, 1,
1298
            expected_added=[('d1',), ('d2',), (old_path,), (new_path,)])
1299
        # Note: the delta doesn't show the modification?
1300
        # The actual new content is validated in the assertions following.
1301
        revtree1, revtree2 = self.assertChanges(branch, 2,
1302
            expected_removed=[('d1',), (new_path,)],
1303
            expected_renamed=[(old_path, new_path)])
1304
        self.assertContent(branch, revtree1, old_path, "aaa")
1305
        self.assertContent(branch, revtree1, new_path, "zzz")
1306
        self.assertContent(branch, revtree2, new_path, "bbb")
1307
1308
    def test_delete_rename_then_modify_symlink_in_root(self):
1309
        handler, branch = self.get_handler()
1310
        old_path = 'a'
1311
        new_path = 'b'
1312
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1313
        revtree0, revtree1 = self.assertChanges(branch, 1,
1314
            expected_added=[(old_path,), (new_path,)])
1315
        # Note: the delta doesn't show the modification?
1316
        # The actual new content is validated in the assertions following.
1317
        revtree1, revtree2 = self.assertChanges(branch, 2,
1318
            expected_removed=[(new_path,)],
1319
            expected_renamed=[(old_path, new_path)])
1320
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1321
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1322
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1323
        self.assertRevisionRoot(revtree1, old_path)
1324
        self.assertRevisionRoot(revtree1, new_path)
1325
        self.assertRevisionRoot(revtree2, new_path)
1326
1327
    def test_delete_rename_then_modify_symlink_in_subdir(self):
1328
        handler, branch = self.get_handler()
1329
        old_path = 'd/a'
1330
        new_path = 'd/b'
1331
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1332
        revtree0, revtree1 = self.assertChanges(branch, 1,
1333
            expected_added=[('d',), (old_path,), (new_path,)])
1334
        # Note: the delta doesn't show the modification?
1335
        # The actual new content is validated in the assertions following.
1336
        revtree1, revtree2 = self.assertChanges(branch, 2,
1337
            expected_removed=[(new_path,)],
1338
            expected_renamed=[(old_path, new_path)])
1339
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1340
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1341
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1342
1343
    def test_delete_rename_then_modify_symlink_in_new_dir(self):
1344
        handler, branch = self.get_handler()
1345
        old_path = 'd1/a'
1346
        new_path = 'd2/b'
1347
        handler.process(self.get_command_iter(old_path, new_path, 'symlink'))
1348
        revtree0, revtree1 = self.assertChanges(branch, 1,
1349
            expected_added=[('d1',), ('d2',), (old_path,), (new_path,)])
1350
        # Note: the delta doesn't show the modification?
1351
        # The actual new content is validated in the assertions following.
1352
        revtree1, revtree2 = self.assertChanges(branch, 2,
1353
            expected_removed=[('d1',), (new_path,)],
1354
            expected_renamed=[(old_path, new_path)])
1355
        self.assertSymlinkTarget(branch, revtree1, old_path, "aaa")
1356
        self.assertSymlinkTarget(branch, revtree1, new_path, "zzz")
1357
        self.assertSymlinkTarget(branch, revtree2, new_path, "bbb")
1358
1359
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1360
class TestImportToPackRenameTricky(TestCaseForGenericProcessor):
0.80.6 by Ian Clatworthy
file/symlink <-> directory rename tests
1361
1362
    def file_command_iter(self, path1, old_path2, new_path2, kind='file'):
1363
        # Revno 1: create two files or symlinks in a directory
1364
        # Revno 2: rename the second file so that it implicitly deletes the
1365
        # first one because either:
1366
        # * the new file is a in directory with the old file name
1367
        # * the new file has the same name as the directory of the first
1368
        def command_list():
1369
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1370
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1371
            def files_one():
1372
                yield commands.FileModifyCommand(path1, kind, False,
1373
                        None, "aaa")
1374
                yield commands.FileModifyCommand(old_path2, kind, False,
1375
                        None, "bbb")
1376
            yield commands.CommitCommand('head', '1', author,
1377
                committer, "commit 1", None, [], files_one)
1378
            def files_two():
1379
                yield commands.FileRenameCommand(old_path2, new_path2)
1380
            yield commands.CommitCommand('head', '2', author,
1381
                committer, "commit 2", ":1", [], files_two)
1382
        return command_list
1383
1384
    def test_rename_file_becomes_directory(self):
1385
        handler, branch = self.get_handler()
1386
        old_path2 = 'foo'
1387
        path1     = 'a/b'
1388
        new_path2 = 'a/b/c'
1389
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
1390
        revtree0, revtree1 = self.assertChanges(branch, 1,
1391
            expected_added=[('a',), (path1,), (old_path2,)])
1392
        revtree1, revtree2 = self.assertChanges(branch, 2,
1393
            expected_renamed=[(old_path2, new_path2)],
1394
            expected_kind_changed=[(path1, 'file', 'directory')])
1395
        self.assertContent(branch, revtree1, path1, "aaa")
1396
        self.assertContent(branch, revtree2, new_path2, "bbb")
1397
1398
    def test_rename_directory_becomes_file(self):
1399
        handler, branch = self.get_handler()
1400
        old_path2 = 'foo'
1401
        path1     = 'a/b/c'
1402
        new_path2 = 'a/b'
1403
        handler.process(self.file_command_iter(path1, old_path2, new_path2))
1404
        revtree0, revtree1 = self.assertChanges(branch, 1,
1405
            expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
1406
        revtree1, revtree2 = self.assertChanges(branch, 2,
1407
            expected_renamed=[(old_path2, new_path2)],
1408
            expected_removed=[(path1,), (new_path2,)])
1409
        self.assertContent(branch, revtree1, path1, "aaa")
1410
        self.assertContent(branch, revtree2, new_path2, "bbb")
1411
1412
    def test_rename_symlink_becomes_directory(self):
1413
        handler, branch = self.get_handler()
1414
        old_path2 = 'foo'
1415
        path1     = 'a/b'
1416
        new_path2 = 'a/b/c'
1417
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
1418
            'symlink'))
1419
        revtree0, revtree1 = self.assertChanges(branch, 1,
1420
            expected_added=[('a',), (path1,), (old_path2,)])
1421
        revtree1, revtree2 = self.assertChanges(branch, 2,
1422
            expected_renamed=[(old_path2, new_path2)],
1423
            expected_kind_changed=[(path1, 'symlink', 'directory')])
1424
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
1425
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
1426
1427
    def test_rename_directory_becomes_symlink(self):
1428
        handler, branch = self.get_handler()
1429
        old_path2 = 'foo'
1430
        path1     = 'a/b/c'
1431
        new_path2 = 'a/b'
1432
        handler.process(self.file_command_iter(path1, old_path2, new_path2,
1433
            'symlink'))
1434
        revtree0, revtree1 = self.assertChanges(branch, 1,
1435
            expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
1436
        revtree1, revtree2 = self.assertChanges(branch, 2,
1437
            expected_renamed=[(old_path2, new_path2)],
1438
            expected_removed=[(path1,), (new_path2,)])
1439
        self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
1440
        self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
1441
1442
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1443
class TestImportToPackCopy(TestCaseForGenericProcessor):
0.76.2 by Ian Clatworthy
code & tests for file copying
1444
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1445
    def file_command_iter(self, src_path, dest_path, kind='file'):
0.80.4 by Ian Clatworthy
file executable off <-> on tests
1446
        # Revno 1: create a file or symlink
1447
        # Revno 2: copy it
0.76.2 by Ian Clatworthy
code & tests for file copying
1448
        def command_list():
1449
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1450
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1451
            def files_one():
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1452
                yield commands.FileModifyCommand(src_path, kind, False,
0.76.2 by Ian Clatworthy
code & tests for file copying
1453
                        None, "aaa")
1454
            yield commands.CommitCommand('head', '1', author,
1455
                committer, "commit 1", None, [], files_one)
1456
            def files_two():
1457
                yield commands.FileCopyCommand(src_path, dest_path)
1458
            yield commands.CommitCommand('head', '2', author,
1459
                committer, "commit 2", ":1", [], files_two)
1460
        return command_list
1461
1462
    def test_copy_file_in_root(self):
1463
        handler, branch = self.get_handler()
1464
        src_path = 'a'
1465
        dest_path = 'b'
1466
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1467
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
1468
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1469
        self.assertContent(branch, revtree1, src_path, "aaa")
1470
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
1471
        self.assertContent(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1472
        self.assertRevisionRoot(revtree1, src_path)
1473
        self.assertRevisionRoot(revtree2, dest_path)
0.76.2 by Ian Clatworthy
code & tests for file copying
1474
1475
    def test_copy_file_in_subdir(self):
1476
        handler, branch = self.get_handler()
1477
        src_path = 'a/a'
1478
        dest_path = 'a/b'
1479
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1480
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
1481
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1482
        self.assertContent(branch, revtree1, src_path, "aaa")
1483
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
1484
        self.assertContent(branch, revtree2, dest_path, "aaa")
1485
1486
    def test_copy_file_to_new_dir(self):
1487
        handler, branch = self.get_handler()
1488
        src_path = 'a/a'
1489
        dest_path = 'b/a'
1490
        handler.process(self.file_command_iter(src_path, dest_path))
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1491
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.2 by Ian Clatworthy
code & tests for file copying
1492
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1493
        self.assertContent(branch, revtree1, src_path, "aaa")
1494
        self.assertContent(branch, revtree2, src_path, "aaa")
0.76.2 by Ian Clatworthy
code & tests for file copying
1495
        self.assertContent(branch, revtree2, dest_path, "aaa")
1496
0.76.3 by Ian Clatworthy
symlink copying tests
1497
    def test_copy_symlink_in_root(self):
1498
        handler, branch = self.get_handler()
1499
        src_path = 'a'
1500
        dest_path = 'b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1501
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1502
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
1503
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1504
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1505
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
1506
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1507
        self.assertRevisionRoot(revtree1, src_path)
1508
        self.assertRevisionRoot(revtree2, dest_path)
0.76.3 by Ian Clatworthy
symlink copying tests
1509
1510
    def test_copy_symlink_in_subdir(self):
1511
        handler, branch = self.get_handler()
1512
        src_path = 'a/a'
1513
        dest_path = 'a/b'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1514
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1515
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
1516
            expected_added=[(dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1517
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1518
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
1519
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1520
1521
    def test_copy_symlink_to_new_dir(self):
1522
        handler, branch = self.get_handler()
1523
        src_path = 'a/a'
1524
        dest_path = 'b/a'
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1525
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1526
        revtree1, revtree2 = self.assertChanges(branch, 2,
0.76.3 by Ian Clatworthy
symlink copying tests
1527
            expected_added=[('b',), (dest_path,)])
0.80.1 by Ian Clatworthy
basic units tests for filemodify
1528
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1529
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
0.76.3 by Ian Clatworthy
symlink copying tests
1530
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1531
0.76.2 by Ian Clatworthy
code & tests for file copying
1532
0.99.8 by Ian Clatworthy
handle copy of a newly added file
1533
class TestImportToPackCopyNew(TestCaseForGenericProcessor):
1534
    """Test copy of a newly added file."""
1535
1536
    def file_command_iter(self, src_path, dest_path, kind='file'):
1537
        # Revno 1: create a file or symlink and copy it
1538
        def command_list():
1539
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1540
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1541
            def files_one():
1542
                yield commands.FileModifyCommand(src_path, kind, False,
1543
                        None, "aaa")
1544
                yield commands.FileCopyCommand(src_path, dest_path)
1545
            yield commands.CommitCommand('head', '1', author,
1546
                committer, "commit 1", None, [], files_one)
1547
        return command_list
1548
1549
    def test_copy_new_file_in_root(self):
1550
        handler, branch = self.get_handler()
1551
        src_path = 'a'
1552
        dest_path = 'b'
1553
        handler.process(self.file_command_iter(src_path, dest_path))
1554
        revtree0, revtree1 = self.assertChanges(branch, 1,
1555
            expected_added=[(src_path,), (dest_path,)])
1556
        self.assertContent(branch, revtree1, src_path, "aaa")
1557
        self.assertContent(branch, revtree1, dest_path, "aaa")
1558
        self.assertRevisionRoot(revtree1, src_path)
1559
        self.assertRevisionRoot(revtree1, dest_path)
1560
1561
    def test_copy_new_file_in_subdir(self):
1562
        handler, branch = self.get_handler()
1563
        src_path = 'a/a'
1564
        dest_path = 'a/b'
1565
        handler.process(self.file_command_iter(src_path, dest_path))
1566
        revtree0, revtree1 = self.assertChanges(branch, 1,
1567
            expected_added=[('a',), (src_path,), (dest_path,)])
1568
        self.assertContent(branch, revtree1, src_path, "aaa")
1569
        self.assertContent(branch, revtree1, dest_path, "aaa")
1570
1571
    def test_copy_new_file_to_new_dir(self):
1572
        handler, branch = self.get_handler()
1573
        src_path = 'a/a'
1574
        dest_path = 'b/a'
1575
        handler.process(self.file_command_iter(src_path, dest_path))
1576
        revtree0, revtree1 = self.assertChanges(branch, 1,
1577
            expected_added=[('a',), (src_path,), ('b',), (dest_path,)])
1578
        self.assertContent(branch, revtree1, src_path, "aaa")
1579
        self.assertContent(branch, revtree1, dest_path, "aaa")
1580
1581
    def test_copy_new_symlink_in_root(self):
1582
        handler, branch = self.get_handler()
1583
        src_path = 'a'
1584
        dest_path = 'b'
1585
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1586
        revtree0, revtree1 = self.assertChanges(branch, 1,
1587
            expected_added=[(src_path,), (dest_path,)])
1588
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1589
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1590
        self.assertRevisionRoot(revtree1, src_path)
1591
        self.assertRevisionRoot(revtree1, dest_path)
1592
1593
    def test_copy_new_symlink_in_subdir(self):
1594
        handler, branch = self.get_handler()
1595
        src_path = 'a/a'
1596
        dest_path = 'a/b'
1597
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1598
        revtree0, revtree1 = self.assertChanges(branch, 1,
1599
            expected_added=[('a',), (src_path,), (dest_path,)])
1600
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1601
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1602
1603
    def test_copy_new_symlink_to_new_dir(self):
1604
        handler, branch = self.get_handler()
1605
        src_path = 'a/a'
1606
        dest_path = 'b/a'
1607
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1608
        revtree0, revtree1 = self.assertChanges(branch, 1,
1609
            expected_added=[('a',), (src_path,), ('b',), (dest_path,)])
1610
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1611
        self.assertSymlinkTarget(branch, revtree1, dest_path, "aaa")
1612
1613
0.99.15 by Ian Clatworthy
Add tests for copying to a path deleted in the same commit
1614
class TestImportToPackCopyToDeleted(TestCaseForGenericProcessor):
1615
1616
    def file_command_iter(self, src_path, dest_path, kind='file'):
1617
        # Revno 1: create two files or symlinks
1618
        # Revno 2: delete one and copy the other one to its path
1619
        def command_list():
1620
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1621
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1622
            def files_one():
1623
                yield commands.FileModifyCommand(src_path, kind, False,
1624
                        None, "aaa")
1625
                yield commands.FileModifyCommand(dest_path, kind, False,
1626
                        None, "bbb")
1627
            yield commands.CommitCommand('head', '1', author,
1628
                committer, "commit 1", None, [], files_one)
1629
            def files_two():
1630
                yield commands.FileDeleteCommand(dest_path)
1631
                yield commands.FileCopyCommand(src_path, dest_path)
1632
            yield commands.CommitCommand('head', '2', author,
1633
                committer, "commit 2", ":1", [], files_two)
1634
        return command_list
1635
1636
    def test_copy_to_deleted_file_in_root(self):
1637
        handler, branch = self.get_handler()
1638
        src_path = 'a'
1639
        dest_path = 'b'
1640
        handler.process(self.file_command_iter(src_path, dest_path))
1641
        revtree0, revtree1 = self.assertChanges(branch, 1,
1642
            expected_added=[(src_path,), (dest_path,)])
1643
        revtree1, revtree2 = self.assertChanges(branch, 2,
1644
            expected_removed=[(dest_path,)],
1645
            expected_added=[(dest_path,)])
1646
        self.assertContent(branch, revtree1, src_path, "aaa")
1647
        self.assertContent(branch, revtree1, dest_path, "bbb")
1648
        self.assertContent(branch, revtree2, src_path, "aaa")
1649
        self.assertContent(branch, revtree2, dest_path, "aaa")
1650
        self.assertRevisionRoot(revtree1, src_path)
1651
        self.assertRevisionRoot(revtree1, dest_path)
1652
1653
    def test_copy_to_deleted_symlink_in_root(self):
1654
        handler, branch = self.get_handler()
1655
        src_path = 'a'
1656
        dest_path = 'b'
1657
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1658
        revtree0, revtree1 = self.assertChanges(branch, 1,
1659
            expected_added=[(src_path,), (dest_path,)])
1660
        revtree1, revtree2 = self.assertChanges(branch, 2,
1661
            expected_removed=[(dest_path,)],
1662
            expected_added=[(dest_path,)])
1663
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1664
        self.assertSymlinkTarget(branch, revtree1, dest_path, "bbb")
1665
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1666
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1667
        self.assertRevisionRoot(revtree1, src_path)
1668
        self.assertRevisionRoot(revtree1, dest_path)
1669
1670
    def test_copy_to_deleted_file_in_subdir(self):
1671
        handler, branch = self.get_handler()
1672
        src_path = 'd/a'
1673
        dest_path = 'd/b'
1674
        handler.process(self.file_command_iter(src_path, dest_path))
1675
        revtree0, revtree1 = self.assertChanges(branch, 1,
1676
            expected_added=[('d',), (src_path,), (dest_path,)])
1677
        revtree1, revtree2 = self.assertChanges(branch, 2,
1678
            expected_removed=[(dest_path,)],
1679
            expected_added=[(dest_path,)])
1680
        self.assertContent(branch, revtree1, src_path, "aaa")
1681
        self.assertContent(branch, revtree1, dest_path, "bbb")
1682
        self.assertContent(branch, revtree2, src_path, "aaa")
1683
        self.assertContent(branch, revtree2, dest_path, "aaa")
1684
1685
    def test_copy_to_deleted_symlink_in_subdir(self):
1686
        handler, branch = self.get_handler()
1687
        src_path = 'd/a'
1688
        dest_path = 'd/b'
1689
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1690
        revtree0, revtree1 = self.assertChanges(branch, 1,
1691
            expected_added=[('d',), (src_path,), (dest_path,)])
1692
        revtree1, revtree2 = self.assertChanges(branch, 2,
1693
            expected_removed=[(dest_path,)],
1694
            expected_added=[(dest_path,)])
1695
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1696
        self.assertSymlinkTarget(branch, revtree1, dest_path, "bbb")
1697
        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
1698
        self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
1699
1700
0.99.18 by Ian Clatworthy
Handle copy of a file/symlink already modified in this commit
1701
class TestImportToPackCopyModified(TestCaseForGenericProcessor):
1702
    """Test copy of file/symlink already modified in this commit."""
1703
1704
    def file_command_iter(self, src_path, dest_path, kind='file'):
1705
        # Revno 1: create a file or symlink
1706
        # Revno 2: modify and copy it
1707
        def command_list():
1708
            author = ['', 'bugs@a.com', time.time(), time.timezone]
1709
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1710
            def files_one():
1711
                yield commands.FileModifyCommand(src_path, kind, False,
1712
                        None, "aaa")
1713
            yield commands.CommitCommand('head', '1', author,
1714
                committer, "commit 1", None, [], files_one)
1715
            def files_two():
1716
                yield commands.FileModifyCommand(src_path, kind, False,
1717
                        None, "bbb")
1718
                yield commands.FileCopyCommand(src_path, dest_path)
1719
            yield commands.CommitCommand('head', '2', author,
1720
                committer, "commit 2", ":1", [], files_two)
1721
        return command_list
1722
1723
    def test_copy_of_modified_file_in_root(self):
1724
        handler, branch = self.get_handler()
1725
        src_path = 'a'
1726
        dest_path = 'b'
1727
        handler.process(self.file_command_iter(src_path, dest_path))
1728
        revtree1, revtree2 = self.assertChanges(branch, 2,
1729
            expected_modified=[(src_path,)],
1730
            expected_added=[(dest_path,)])
1731
        self.assertContent(branch, revtree1, src_path, "aaa")
1732
        self.assertContent(branch, revtree2, src_path, "bbb")
1733
        self.assertContent(branch, revtree2, dest_path, "bbb")
1734
        self.assertRevisionRoot(revtree1, src_path)
1735
        self.assertRevisionRoot(revtree2, dest_path)
1736
1737
    def test_copy_of_modified_file_in_subdir(self):
1738
        handler, branch = self.get_handler()
1739
        src_path = 'd/a'
1740
        dest_path = 'd/b'
1741
        handler.process(self.file_command_iter(src_path, dest_path))
1742
        revtree1, revtree2 = self.assertChanges(branch, 2,
1743
            expected_modified=[(src_path,)],
1744
            expected_added=[(dest_path,)])
1745
        self.assertContent(branch, revtree1, src_path, "aaa")
1746
        self.assertContent(branch, revtree2, src_path, "bbb")
1747
        self.assertContent(branch, revtree2, dest_path, "bbb")
1748
1749
    def test_copy_of_modified_file_to_new_dir(self):
1750
        handler, branch = self.get_handler()
1751
        src_path = 'd1/a'
1752
        dest_path = 'd2/a'
1753
        handler.process(self.file_command_iter(src_path, dest_path))
1754
        revtree1, revtree2 = self.assertChanges(branch, 2,
1755
            expected_modified=[(src_path,)],
1756
            expected_added=[('d2',), (dest_path,)])
1757
        self.assertContent(branch, revtree1, src_path, "aaa")
1758
        self.assertContent(branch, revtree2, src_path, "bbb")
1759
        self.assertContent(branch, revtree2, dest_path, "bbb")
1760
1761
    def test_copy_of_modified_symlink_in_root(self):
1762
        handler, branch = self.get_handler()
1763
        src_path = 'a'
1764
        dest_path = 'b'
1765
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1766
        revtree1, revtree2 = self.assertChanges(branch, 2,
1767
            expected_modified=[(src_path,)],
1768
            expected_added=[(dest_path,)])
1769
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1770
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1771
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1772
        self.assertRevisionRoot(revtree1, src_path)
1773
        self.assertRevisionRoot(revtree2, dest_path)
1774
1775
    def test_copy_of_modified_symlink_in_subdir(self):
1776
        handler, branch = self.get_handler()
1777
        src_path = 'd/a'
1778
        dest_path = 'd/b'
1779
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1780
        revtree1, revtree2 = self.assertChanges(branch, 2,
1781
            expected_modified=[(src_path,)],
1782
            expected_added=[(dest_path,)])
1783
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1784
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1785
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
1786
1787
    def test_copy_of_modified_symlink_to_new_dir(self):
1788
        handler, branch = self.get_handler()
1789
        src_path = 'd1/a'
1790
        dest_path = 'd2/a'
1791
        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
1792
        revtree1, revtree2 = self.assertChanges(branch, 2,
1793
            expected_modified=[(src_path,)],
1794
            expected_added=[('d2',), (dest_path,)])
1795
        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
1796
        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
1797
        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
0.99.10 by Ian Clatworthy
commented out draft of CopyModified tests
1798
1799
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1800
class TestImportToPackFileKinds(TestCaseForGenericProcessor):
0.64.74 by Ian Clatworthy
fix symlink importing
1801
1802
    def get_command_iter(self, path, kind, content):
1803
        def command_list():
1804
            committer = ['', 'elmer@a.com', time.time(), time.timezone]
1805
            def files_one():
1806
                yield commands.FileModifyCommand(path, kind, False,
1807
                        None, content)
1808
            yield commands.CommitCommand('head', '1', None,
1809
                committer, "commit 1", None, [], files_one)
1810
        return command_list
1811
1812
    def test_import_plainfile(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
1813
        handler, branch = self.get_handler()
1814
        handler.process(self.get_command_iter('foo', 'file', 'aaa'))
0.64.74 by Ian Clatworthy
fix symlink importing
1815
1816
    def test_import_symlink(self):
0.76.1 by Ian Clatworthy
clean-up tests for GenericProcessor
1817
        handler, branch = self.get_handler()
1818
        handler.process(self.get_command_iter('foo', 'symlink', 'bar'))
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1819
1820
1821
### TODO: Parameterise tests rather than below hack
1822
0.85.2 by Ian Clatworthy
improve per-file graph generation
1823
class TestImportToRichRootModify(TestImportToPackModify):
1824
    branch_format = "1.9-rich-root"
1825
0.99.5 by Ian Clatworthy
handle adding the same file twice in the one commit
1826
class TestImportToRichRootModifyTwice(TestImportToPackModifyTwice):
1827
    branch_format = "1.9-rich-root"
1828
0.85.2 by Ian Clatworthy
improve per-file graph generation
1829
class TestImportToRichRootModifyTricky(TestImportToPackModifyTricky):
1830
    branch_format = "1.9-rich-root"
1831
1832
class TestImportToRichRootDelete(TestImportToPackDelete):
1833
    branch_format = "1.9-rich-root"
1834
0.99.7 by Ian Clatworthy
handle a delete of a newly added file
1835
class TestImportToRichRootDeleteNew(TestImportToPackDeleteNew):
1836
    branch_format = "1.9-rich-root"
0.101.4 by Tom Widmer
Add missing test cases for multilevel deletes in 2a dn 1.9-rich-root fast imports.
1837
    
1838
class TestImportToRichRootDeleteMultiLevel(TestImportToPackDeleteMultiLevel):
1839
    branch_format = "1.9-rich-root"
0.99.7 by Ian Clatworthy
handle a delete of a newly added file
1840
0.99.13 by Ian Clatworthy
Handle delete then add of a file/symlink in the one commit
1841
class TestImportToRichRootDeleteThenAdd(TestImportToPackDeleteThenAdd):
1842
    branch_format = "1.9-rich-root"
1843
0.85.2 by Ian Clatworthy
improve per-file graph generation
1844
class TestImportToRichRootDeleteDirectory(TestImportToPackDeleteDirectory):
1845
    branch_format = "1.9-rich-root"
1846
0.99.21 by Ian Clatworthy
Handle deleting a directory then adding a file within it in the same commit
1847
class TestImportToRichRootDeleteDirectoryThenAddFile(TestImportToPackDeleteDirectoryThenAddFile):
1848
    branch_format = "1.9-rich-root"
1849
0.85.2 by Ian Clatworthy
improve per-file graph generation
1850
class TestImportToRichRootRename(TestImportToPackRename):
1851
    branch_format = "1.9-rich-root"
1852
0.99.6 by Ian Clatworthy
Handle rename of a just added file
1853
class TestImportToRichRootRenameNew(TestImportToPackRenameNew):
1854
    branch_format = "1.9-rich-root"
1855
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
1856
class TestImportToRichRootRenameToDeleted(TestImportToPackRenameToDeleted):
1857
    branch_format = "1.9-rich-root"
1858
0.99.17 by Ian Clatworthy
Handle rename of a file/symlink modified already in this commit
1859
class TestImportToRichRootRenameModified(TestImportToPackRenameModified):
1860
    branch_format = "1.9-rich-root"
1861
0.99.19 by Ian Clatworthy
Handle rename then modification of the new path
1862
class TestImportToRichRootRenameThenModify(TestImportToPackRenameThenModify):
1863
    branch_format = "1.9-rich-root"
1864
0.64.233 by Ian Clatworthy
Handle delete, rename then modify all in the one commit
1865
class TestImportToRichRootDeleteRenameThenModify(TestImportToPackDeleteRenameThenModify):
1866
    branch_format = "1.9-rich-root"
1867
0.85.2 by Ian Clatworthy
improve per-file graph generation
1868
class TestImportToRichRootRenameTricky(TestImportToPackRenameTricky):
1869
    branch_format = "1.9-rich-root"
1870
1871
class TestImportToRichRootCopy(TestImportToPackCopy):
1872
    branch_format = "1.9-rich-root"
1873
0.99.8 by Ian Clatworthy
handle copy of a newly added file
1874
class TestImportToRichRootCopyNew(TestImportToPackCopyNew):
1875
    branch_format = "1.9-rich-root"
1876
0.99.15 by Ian Clatworthy
Add tests for copying to a path deleted in the same commit
1877
class TestImportToRichRootCopyToDeleted(TestImportToPackCopyToDeleted):
1878
    branch_format = "1.9-rich-root"
1879
0.99.18 by Ian Clatworthy
Handle copy of a file/symlink already modified in this commit
1880
class TestImportToRichRootCopyModified(TestImportToPackCopyModified):
1881
    branch_format = "1.9-rich-root"
1882
0.85.2 by Ian Clatworthy
improve per-file graph generation
1883
class TestImportToRichRootFileKinds(TestImportToPackFileKinds):
1884
    branch_format = "1.9-rich-root"
1885
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1886
try:
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1887
    from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1888
1889
    class TestImportToChkModify(TestImportToPackModify):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1890
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1891
0.99.5 by Ian Clatworthy
handle adding the same file twice in the one commit
1892
    class TestImportToChkModifyTwice(TestImportToPackModifyTwice):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1893
        branch_format = "2a"
0.99.5 by Ian Clatworthy
handle adding the same file twice in the one commit
1894
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1895
    class TestImportToChkModifyTricky(TestImportToPackModifyTricky):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1896
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1897
1898
    class TestImportToChkDelete(TestImportToPackDelete):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1899
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1900
0.99.7 by Ian Clatworthy
handle a delete of a newly added file
1901
    class TestImportToChkDeleteNew(TestImportToPackDeleteNew):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1902
        branch_format = "2a"
0.99.7 by Ian Clatworthy
handle a delete of a newly added file
1903
0.101.4 by Tom Widmer
Add missing test cases for multilevel deletes in 2a dn 1.9-rich-root fast imports.
1904
    class TestImportToChkDeleteMultiLevel(TestImportToPackDeleteMultiLevel):
1905
        branch_format = "2a"
1906
0.99.13 by Ian Clatworthy
Handle delete then add of a file/symlink in the one commit
1907
    class TestImportToChkDeleteThenAdd(TestImportToPackDeleteThenAdd):
1908
        branch_format = "2a"
1909
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1910
    class TestImportToChkDeleteDirectory(TestImportToPackDeleteDirectory):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1911
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1912
0.99.21 by Ian Clatworthy
Handle deleting a directory then adding a file within it in the same commit
1913
    class TestImportToChkDeleteDirectoryThenAddFile(TestImportToPackDeleteDirectoryThenAddFile):
1914
        branch_format = "2a"
1915
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1916
    class TestImportToChkRename(TestImportToPackRename):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1917
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1918
0.99.6 by Ian Clatworthy
Handle rename of a just added file
1919
    class TestImportToChkRenameNew(TestImportToPackRenameNew):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1920
        branch_format = "2a"
0.99.6 by Ian Clatworthy
Handle rename of a just added file
1921
0.99.14 by Ian Clatworthy
Add tests for renaming to a deleted destination
1922
    class TestImportToChkRenameToDeleted(TestImportToPackRenameToDeleted):
1923
        branch_format = "2a"
1924
0.99.17 by Ian Clatworthy
Handle rename of a file/symlink modified already in this commit
1925
    class TestImportToChkRenameModified(TestImportToPackRenameModified):
1926
        branch_format = "2a"
1927
0.99.19 by Ian Clatworthy
Handle rename then modification of the new path
1928
    class TestImportToChkRenameThenModify(TestImportToPackRenameThenModify):
1929
        branch_format = "2a"
1930
0.64.233 by Ian Clatworthy
Handle delete, rename then modify all in the one commit
1931
    class TestImportToChkDeleteRenameThenModify(TestImportToPackDeleteRenameThenModify):
1932
        branch_format = "2a"
1933
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1934
    class TestImportToChkRenameTricky(TestImportToPackRenameTricky):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1935
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1936
1937
    class TestImportToChkCopy(TestImportToPackCopy):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1938
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1939
0.99.8 by Ian Clatworthy
handle copy of a newly added file
1940
    class TestImportToChkCopyNew(TestImportToPackCopyNew):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1941
        branch_format = "2a"
0.99.8 by Ian Clatworthy
handle copy of a newly added file
1942
0.99.15 by Ian Clatworthy
Add tests for copying to a path deleted in the same commit
1943
    class TestImportToChkCopyToDeleted(TestImportToPackCopyToDeleted):
1944
        branch_format = "2a"
1945
0.99.18 by Ian Clatworthy
Handle copy of a file/symlink already modified in this commit
1946
    class TestImportToChkCopyModified(TestImportToPackCopyModified):
1947
        branch_format = "2a"
1948
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1949
    class TestImportToChkFileKinds(TestImportToPackFileKinds):
0.99.11 by Ian Clatworthy
Change tests to use 2a instead of development6-rich-root
1950
        branch_format = "2a"
0.85.1 by Ian Clatworthy
extend tests to test the chk code path
1951
1952
except ImportError:
1953
    pass