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