/brz/remove-bazaar

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