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