/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.436.2 by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands.
1
# Copyright (C) 2006-2007 by Jelmer Vernooij
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
2
#
0.436.2 by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands.
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
0.436.131 by Jelmer Vernooij
Change license back to GPLv2+
5
# the Free Software Foundation; either version 2 of the License, or
0.436.2 by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands.
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0.436.178 by Jelmer Vernooij
Finish rename to 'bzr-rewrite'.
16
0.436.16 by Jelmer Vernooij
Some more work on maptree.
17
"""Tests for the rebase code."""
0.436.2 by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands.
18
7406.3.2 by Jelmer Vernooij
Update for breezy.
19
from ....conflicts import ConflictList
20
from ....errors import (
0.436.178 by Jelmer Vernooij
Finish rename to 'bzr-rewrite'.
21
    UnknownFormatError,
22
    NoSuchFile,
23
    ConflictsInTree,
24
    )
7406.3.2 by Jelmer Vernooij
Update for breezy.
25
from ....graph import (
0.436.178 by Jelmer Vernooij
Finish rename to 'bzr-rewrite'.
26
    Graph,
27
    DictParentsProvider,
28
    )
7406.3.2 by Jelmer Vernooij
Update for breezy.
29
from ....revision import NULL_REVISION
30
from ....tests import TestCase, TestCaseWithTransport
31
from ....tests.matchers import RevisionHistoryMatches
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
32
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
33
from ..rebase import (
0.436.157 by Jelmer Vernooij
use absolute imports everywhere.
34
    marshall_rebase_plan,
35
    unmarshall_rebase_plan,
0.436.204 by Jelmer Vernooij
Split up large method.
36
    CommitBuilderRevisionRewriter,
0.436.157 by Jelmer Vernooij
use absolute imports everywhere.
37
    generate_simple_plan,
38
    generate_transpose_plan,
39
    rebase_todo,
40
    REBASE_PLAN_FILENAME,
41
    REBASE_CURRENT_REVID_FILENAME,
0.436.192 by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses.
42
    RebaseState1,
0.436.157 by Jelmer Vernooij
use absolute imports everywhere.
43
    ReplaySnapshotError,
0.436.203 by Jelmer Vernooij
Use camelcasing for class names.
44
    WorkingTreeRevisionRewriter,
0.436.157 by Jelmer Vernooij
use absolute imports everywhere.
45
    )
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
46
0.436.4 by Jelmer Vernooij
Add some tests.
47
0.436.3 by Jelmer Vernooij
Fill in commands.
48
class RebasePlanReadWriterTests(TestCase):
0.436.145 by Jelmer Vernooij
Fix test.
49
0.436.4 by Jelmer Vernooij
Add some tests.
50
    def test_simple_marshall_rebase_plan(self):
7406.3.5 by Jelmer Vernooij
Fix formatting.
51
        self.assertEqualDiff(b"""\
52
# Bazaar rebase plan 1
0.436.4 by Jelmer Vernooij
Add some tests.
53
1 bla
54
oldrev newrev newparent1 newparent2
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
55
""", marshall_rebase_plan((1, b"bla"),
56
                          {b"oldrev": (b"newrev", (b"newparent1", b"newparent2"))}))
0.436.4 by Jelmer Vernooij
Add some tests.
57
58
    def test_simple_unmarshall_rebase_plan(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
59
        self.assertEquals(((1, b"bla"),
60
                          {b"oldrev": (b"newrev", (b"newparent1", b"newparent2"))}),
7406.3.5 by Jelmer Vernooij
Fix formatting.
61
                          unmarshall_rebase_plan(b"""# Bazaar rebase plan 1
0.436.4 by Jelmer Vernooij
Add some tests.
62
1 bla
63
oldrev newrev newparent1 newparent2
64
"""))
65
66
    def test_unmarshall_rebase_plan_formatunknown(self):
67
        self.assertRaises(UnknownFormatError,
7406.3.5 by Jelmer Vernooij
Fix formatting.
68
                          unmarshall_rebase_plan, b"""# Bazaar rebase plan x
0.436.4 by Jelmer Vernooij
Add some tests.
69
1 bla
70
oldrev newrev newparent1 newparent2
71
""")
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
72
73
74
class ConversionTests(TestCaseWithTransport):
0.436.145 by Jelmer Vernooij
Fix test.
75
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
76
    def test_simple(self):
77
        wt = self.make_branch_and_tree('.')
78
        b = wt.branch
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
79
        with open('hello', 'w') as f:
80
            f.write('hello world')
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
81
        wt.add('hello')
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
82
        wt.commit(message='add hello', rev_id=b"bla")
83
        with open('hello', 'w') as f:
84
            f.write('world')
85
        wt.commit(message='change hello', rev_id=b"bloe")
86
        wt.set_last_revision(b"bla")
87
        b.generate_revision_history(b"bla")
88
        with open('hello', 'w') as f:
89
            f.write('world')
90
        wt.commit(message='change hello', rev_id=b"bla2")
0.436.49 by Jelmer Vernooij
Fix locking.
91
92
        wt.branch.repository.lock_write()
7406.3.5 by Jelmer Vernooij
Fix formatting.
93
        newrev = CommitBuilderRevisionRewriter(wt.branch.repository)(
94
            b"bla2", b"bla4", (b"bloe",))
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
95
        self.assertEqual(b"bla4", newrev)
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
96
        self.assertTrue(wt.branch.repository.has_revision(newrev))
7406.3.5 by Jelmer Vernooij
Fix formatting.
97
        self.assertEqual(
98
            (b"bloe",), wt.branch.repository.get_parent_map([newrev])[newrev])
99
        self.assertEqual(
100
            "bla2", wt.branch.repository.get_revision(newrev).properties["rebase-of"])
0.436.49 by Jelmer Vernooij
Fix locking.
101
        wt.branch.repository.unlock()
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
102
103
104
class PlanCreatorTests(TestCaseWithTransport):
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
105
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
106
    def test_simple_plan_creator(self):
107
        wt = self.make_branch_and_tree('.')
108
        b = wt.branch
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
109
        with open('hello', 'w') as f:
110
            f.write('hello world')
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
111
        wt.add('hello')
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
112
        wt.commit(message='add hello', rev_id=b"bla")
113
        with open('hello', 'w') as f:
114
            f.write('world')
115
        wt.commit(message='change hello', rev_id=b"bloe")
116
        wt.set_last_revision(b"bla")
117
        b.generate_revision_history(b"bla")
118
        with open('hello', 'w') as f:
119
            f.write('world')
120
        wt.commit(message='change hello', rev_id=b"bla2")
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
121
0.436.79 by Jelmer Vernooij
Fix tests when using the latest version of bzr.
122
        b.repository.lock_read()
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
123
        graph = b.repository.get_graph()
7406.3.5 by Jelmer Vernooij
Fix formatting.
124
        self.assertEquals(
125
            {b'bla2': (b'newbla2', (b"bloe",))},
0.441.4 by Robert Collins
* Fixed O(history) access during plan creation (Robert Collins, lp:#249823).
126
            generate_simple_plan(
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
127
                graph.find_difference(b.last_revision(), b"bla")[0],
7406.3.5 by Jelmer Vernooij
Fix formatting.
128
                b"bla2", None, b"bloe", graph, lambda y, _: b"new" + y))
0.436.79 by Jelmer Vernooij
Fix tests when using the latest version of bzr.
129
        b.repository.unlock()
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
130
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
131
    def test_simple_plan_creator_extra_history(self):
132
        wt = self.make_branch_and_tree('.')
133
        b = wt.branch
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
134
        with open('hello', 'w') as f:
135
            f.write('hello world')
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
136
        wt.add('hello')
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
137
        wt.commit(message='add hello', rev_id=b"bla")
138
        with open('hello', 'w') as f:
139
            f.write('world')
140
        wt.commit(message='change hello', rev_id=b"bloe")
141
        wt.set_last_revision(b"bla")
142
        b.generate_revision_history(b"bla")
143
        with open('hello', 'w') as f:
144
            f.write('world')
145
        wt.commit(message='change hello', rev_id=b"bla2")
146
        with open('hello', 'w') as f:
147
            f.write('universe')
148
        wt.commit(message='change hello again', rev_id=b"bla3")
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
149
7406.3.5 by Jelmer Vernooij
Fix formatting.
150
        with b.repository.lock_read():
151
            graph = b.repository.get_graph()
152
            self.assertEquals(
153
                {b'bla2': (b'newbla2', (b"bloe",)), b'bla3': (b'newbla3', (b'newbla2',))},
154
                generate_simple_plan(
155
                    graph.find_difference(b.last_revision(), b"bloe")[0],
156
                    b"bla2", None, b"bloe",
157
                    graph, lambda y, _: b"new" + y))
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
158
159
    def test_generate_transpose_plan(self):
160
        wt = self.make_branch_and_tree('.')
161
        b = wt.branch
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
162
        with open('hello', 'w') as f:
163
            f.write('hello world')
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
164
        wt.add('hello')
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
165
        wt.commit(message='add hello', rev_id=b"bla")
166
        with open('hello', 'w') as f:
167
            f.write('world')
168
        wt.commit(message='change hello', rev_id=b"bloe")
169
        wt.set_last_revision(b"bla")
170
        b.generate_revision_history(b"bla")
171
        with open('hello', 'w') as f:
172
            f.write('world')
173
        wt.commit(message='change hello', rev_id=b"bla2")
174
        with open('hello', 'w') as f:
175
            f.write('universe')
176
        wt.commit(message='change hello again', rev_id=b"bla3")
177
        wt.set_last_revision(b"bla")
178
        b.generate_revision_history(b"bla")
179
        with open('hello', 'w') as f:
180
            f.write('somebar')
181
        wt.commit(message='change hello yet again', rev_id=b"blie")
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
182
        wt.set_last_revision(NULL_REVISION)
0.436.235 by Jelmer Vernooij
Avoid deprecated Branch.set_revision_history.
183
        b.generate_revision_history(NULL_REVISION)
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
184
        wt.add('hello')
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
185
        wt.commit(message='add hello', rev_id=b"lala")
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
186
0.436.79 by Jelmer Vernooij
Fix tests when using the latest version of bzr.
187
        b.repository.lock_read()
0.436.88 by Jelmer Vernooij
Avoid use of get_revision_graph() calls.
188
        graph = b.repository.get_graph()
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
189
        self.assertEquals({
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
190
            b'blie': (b'newblie', (b'lala',))},
7406.3.5 by Jelmer Vernooij
Fix formatting.
191
            generate_transpose_plan(graph.iter_ancestry(
192
                [b"blie"]),
193
                {b"bla": b"lala"}, graph, lambda y, _: b"new" + y))
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
194
        self.assertEquals({
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
195
            b'bla2': (b'newbla2', (b'lala',)),
196
            b'bla3': (b'newbla3', (b'newbla2',)),
197
            b'blie': (b'newblie', (b'lala',)),
198
            b'bloe': (b'newbloe', (b'lala',))},
7406.3.5 by Jelmer Vernooij
Fix formatting.
199
            generate_transpose_plan(graph.iter_ancestry(
200
                b.repository._all_revision_ids()),
201
                {b"bla": b"lala"}, graph, lambda y, _: b"new" + y))
0.436.79 by Jelmer Vernooij
Fix tests when using the latest version of bzr.
202
        b.repository.unlock()
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
203
0.436.31 by Jelmer Vernooij
Refactor generate_transpose_plan() to not take a repository object but
204
    def test_generate_transpose_plan_one(self):
0.436.89 by Jelmer Vernooij
Use tuples for parents.
205
        graph = Graph(DictParentsProvider({"bla": ("bloe",), "bloe": (), "lala": ()}))
7406.3.5 by Jelmer Vernooij
Fix formatting.
206
        self.assertEquals(
207
            {"bla": ("newbla", ("lala",))},
208
            generate_transpose_plan(graph.iter_ancestry(
209
                ["bla", "bloe"]), {"bloe": "lala"}, graph, lambda y, _: "new" + y))
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
210
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
211
    def test_plan_with_already_merged(self):
7457.1.1 by Jelmer Vernooij
Fix invalid escape sequence errors on Python 3.
212
        r"""We need to use a merge base that makes sense.
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
213
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
214
        A
215
        | \
216
        B  D
217
        | \|
218
        C  E
219
220
        Rebasing E on C should result in:
221
222
        A -> B -> C -> D -> E
223
224
        with a plan of:
225
226
        D -> (D', [C])
0.436.40 by Jelmer Vernooij
Adjust expectations.
227
        E -> (E', [D', C])
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
228
        """
229
        parents_map = {
7406.3.5 by Jelmer Vernooij
Fix formatting.
230
            "A": (),
231
            "B": ("A",),
232
            "C": ("B",),
233
            "D": ("A",),
234
            "E": ("D", "B")
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
235
        }
0.436.86 by Jelmer Vernooij
Fix some uses of get_revision_graph().
236
        graph = Graph(DictParentsProvider(parents_map))
7406.3.5 by Jelmer Vernooij
Fix formatting.
237
        self.assertEquals(
238
            {"D": ("D'", ("C",)), "E": ("E'", ("D'",))},
239
            generate_simple_plan(
240
                ["D", "E"], "D", None, "C", graph, lambda y, _: y + "'"))
0.436.55 by Jelmer Vernooij
Add functinality for skipping duplicate merges.
241
242
    def test_plan_with_already_merged_skip_merges(self):
7457.1.1 by Jelmer Vernooij
Fix invalid escape sequence errors on Python 3.
243
        r"""We need to use a merge base that makes sense.
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
244
0.436.55 by Jelmer Vernooij
Add functinality for skipping duplicate merges.
245
        A
246
        | \
247
        B  D
248
        | \|
249
        C  E
250
251
        Rebasing E on C should result in:
252
253
        A -> B -> C -> D'
254
255
        with a plan of:
256
257
        D -> (D', [C])
258
        """
259
        parents_map = {
7406.3.5 by Jelmer Vernooij
Fix formatting.
260
            "A": (),
261
            "B": ("A",),
262
            "C": ("B",),
263
            "D": ("A",),
264
            "E": ("D", "B")
0.436.55 by Jelmer Vernooij
Add functinality for skipping duplicate merges.
265
        }
0.436.86 by Jelmer Vernooij
Fix some uses of get_revision_graph().
266
        graph = Graph(DictParentsProvider(parents_map))
7406.3.5 by Jelmer Vernooij
Fix formatting.
267
        self.assertEquals(
268
            {"D": ("D'", ("C",))},
269
            generate_simple_plan(
270
                ["D", "E"], "D", None, "C", graph, lambda y, _: y + "'", True))
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
271
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
272
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
273
class RebaseStateTests(TestCaseWithTransport):
274
275
    def setUp(self):
276
        super(RebaseStateTests, self).setUp()
277
        self.wt = self.make_branch_and_tree('.')
0.436.192 by Jelmer Vernooij
Avoid reopening state when possible, allow subclasses.
278
        self.state = RebaseState1(self.wt)
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
279
280
    def test_rebase_plan_exists_false(self):
281
        self.assertFalse(self.state.has_plan())
282
283
    def test_rebase_plan_exists_empty(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
284
        self.wt._transport.put_bytes(REBASE_PLAN_FILENAME, b"")
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
285
        self.assertFalse(self.state.has_plan())
286
287
    def test_rebase_plan_exists(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
288
        self.wt._transport.put_bytes(REBASE_PLAN_FILENAME, b"foo")
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
289
        self.assertTrue(self.state.has_plan())
290
291
    def test_remove_rebase_plan(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
292
        self.wt._transport.put_bytes(REBASE_PLAN_FILENAME, b"foo")
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
293
        self.state.remove_plan()
294
        self.assertFalse(self.state.has_plan())
295
296
    def test_remove_rebase_plan_twice(self):
297
        self.state.remove_plan()
298
        self.assertFalse(self.state.has_plan())
299
300
    def test_write_rebase_plan(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
301
        with open('hello', 'w') as f:
302
            f.write('hello world')
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
303
        self.wt.add('hello')
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
304
        self.wt.commit(message='add hello', rev_id=b"bla")
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
305
        self.state.write_plan(
7406.3.5 by Jelmer Vernooij
Fix formatting.
306
            {b"oldrev": (b"newrev", [b"newparent1", b"newparent2"])})
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
307
        self.assertEqualDiff(b"""# Bazaar rebase plan 1
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
308
1 bla
309
oldrev newrev newparent1 newparent2
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
310
""", self.wt._transport.get_bytes(REBASE_PLAN_FILENAME))
311
312
    def test_read_rebase_plan_nonexistant(self):
313
        self.assertRaises(NoSuchFile, self.state.read_plan)
314
315
    def test_read_rebase_plan_empty(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
316
        self.wt._transport.put_bytes(REBASE_PLAN_FILENAME, b"")
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
317
        self.assertRaises(NoSuchFile, self.state.read_plan)
318
319
    def test_read_rebase_plan(self):
7406.3.5 by Jelmer Vernooij
Fix formatting.
320
        self.wt._transport.put_bytes(
321
            REBASE_PLAN_FILENAME,
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
322
            b"""# Bazaar rebase plan 1
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
323
1 bla
324
oldrev newrev newparent1 newparent2
325
""")
7406.3.5 by Jelmer Vernooij
Fix formatting.
326
        self.assertEquals(
327
            ((1, b"bla"), {b"oldrev": (b"newrev", (b"newparent1", b"newparent2"))}),
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
328
            self.state.read_plan())
0.436.145 by Jelmer Vernooij
Fix test.
329
0.436.9 by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue.
330
    def test_read_nonexistant(self):
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
331
        self.assertIs(None, self.state.read_active_revid())
0.436.9 by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue.
332
333
    def test_read_null(self):
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
334
        self.wt._transport.put_bytes(REBASE_CURRENT_REVID_FILENAME, NULL_REVISION)
335
        self.assertIs(None, self.state.read_active_revid())
0.436.9 by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue.
336
337
    def test_read(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
338
        self.wt._transport.put_bytes(REBASE_CURRENT_REVID_FILENAME, b"bla")
339
        self.assertEquals(b"bla", self.state.read_active_revid())
0.436.9 by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue.
340
341
    def test_write(self):
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
342
        self.state.write_active_revid(b"bloe")
343
        self.assertEquals(b"bloe", self.state.read_active_revid())
0.436.9 by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue.
344
345
    def test_write_null(self):
0.436.191 by Jelmer Vernooij
Move rebase state to a separate object.
346
        self.state.write_active_revid(None)
347
        self.assertIs(None, self.state.read_active_revid())
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
348
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
349
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
350
class RebaseTodoTests(TestCase):
0.436.145 by Jelmer Vernooij
Fix test.
351
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
352
    def test_done(self):
353
        class Repository:
354
            def has_revision(self, revid):
355
                return revid == "bloe"
7406.3.5 by Jelmer Vernooij
Fix formatting.
356
        self.assertEquals(
357
            [], list(rebase_todo(Repository(), {"bla": ("bloe", [])})))
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
358
359
    def test_notstarted(self):
360
        class Repository:
361
            def has_revision(self, revid):
362
                return False
7406.3.5 by Jelmer Vernooij
Fix formatting.
363
        self.assertEquals(["bla"], list(rebase_todo(Repository(), {"bla": ("bloe", [])})))
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
364
365
    def test_halfway(self):
366
        class Repository:
367
            def has_revision(self, revid):
368
                return revid == "bloe"
7406.3.5 by Jelmer Vernooij
Fix formatting.
369
        self.assertEquals(
370
            ["ha"],
371
            list(rebase_todo(Repository(), {"bla": ("bloe", []), "ha": ("hee", [])})))
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
372
0.436.246 by Jelmer Vernooij
Use record_iter_changes in rebase.
373
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
374
class ReplaySnapshotTests(TestCaseWithTransport):
0.436.246 by Jelmer Vernooij
Use record_iter_changes in rebase.
375
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
376
    def test_single_revision(self):
377
        wt = self.make_branch_and_tree(".")
378
        self.build_tree(['afile'])
379
        wt.add(["afile"])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
380
        wt.commit("bla", rev_id=b"oldcommit")
0.436.49 by Jelmer Vernooij
Fix locking.
381
        wt.branch.repository.lock_write()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
382
        CommitBuilderRevisionRewriter(wt.branch.repository)(b"oldcommit", b"newcommit", ())
0.436.49 by Jelmer Vernooij
Fix locking.
383
        wt.branch.repository.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
384
        oldrev = wt.branch.repository.get_revision(b"oldcommit")
385
        newrev = wt.branch.repository.get_revision(b"newcommit")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
386
        self.assertEquals([], newrev.parent_ids)
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
387
        self.assertEquals(b"newcommit", newrev.revision_id)
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
388
        self.assertEquals(oldrev.committer, newrev.committer)
389
        self.assertEquals(oldrev.timestamp, newrev.timestamp)
390
        self.assertEquals(oldrev.timezone, newrev.timezone)
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
391
        tree = wt.branch.repository.revision_tree(b"newcommit")
392
        self.assertEquals(b"newcommit", tree.get_file_revision("afile"))
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
393
0.436.34 by Jelmer Vernooij
Some more tests.
394
    def test_two_revisions(self):
395
        wt = self.make_branch_and_tree("old")
0.436.103 by Jelmer Vernooij
Loosen requirements about text parents a bit - check text sha1s instead.
396
        self.build_tree_contents([('old/afile', 'afilecontents'), ('old/notherfile', 'notherfilecontents')])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
397
        wt.add(["afile"], [b"somefileid"])
398
        wt.commit("bla", rev_id=b"oldparent")
0.436.34 by Jelmer Vernooij
Some more tests.
399
        wt.add(["notherfile"])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
400
        wt.commit("bla", rev_id=b"oldcommit")
0.436.34 by Jelmer Vernooij
Some more tests.
401
        oldrepos = wt.branch.repository
402
        wt = self.make_branch_and_tree("new")
0.436.103 by Jelmer Vernooij
Loosen requirements about text parents a bit - check text sha1s instead.
403
        self.build_tree_contents([('new/afile', 'afilecontents'), ('new/notherfile', 'notherfilecontents')])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
404
        wt.add(["afile"], [b"afileid"])
405
        wt.commit("bla", rev_id=b"newparent")
0.436.34 by Jelmer Vernooij
Some more tests.
406
        wt.branch.repository.fetch(oldrepos)
0.436.49 by Jelmer Vernooij
Fix locking.
407
        wt.branch.repository.lock_write()
7406.3.5 by Jelmer Vernooij
Fix formatting.
408
        CommitBuilderRevisionRewriter(wt.branch.repository)(
409
            b"oldcommit", b"newcommit", (b"newparent",))
0.436.49 by Jelmer Vernooij
Fix locking.
410
        wt.branch.repository.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
411
        oldrev = wt.branch.repository.get_revision(b"oldcommit")
412
        newrev = wt.branch.repository.get_revision(b"newcommit")
413
        self.assertEquals([b"newparent"], newrev.parent_ids)
414
        self.assertEquals(b"newcommit", newrev.revision_id)
0.436.34 by Jelmer Vernooij
Some more tests.
415
        self.assertEquals(oldrev.committer, newrev.committer)
416
        self.assertEquals(oldrev.timestamp, newrev.timestamp)
417
        self.assertEquals(oldrev.timezone, newrev.timezone)
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
418
        tree = wt.branch.repository.revision_tree(b"newcommit")
419
        self.assertEquals(b"afileid", tree.path2id("afile"))
420
        self.assertEquals(b"newcommit", tree.get_file_revision("notherfile"))
0.436.34 by Jelmer Vernooij
Some more tests.
421
422
    def test_two_revisions_no_renames(self):
423
        wt = self.make_branch_and_tree("old")
424
        self.build_tree(['old/afile', 'old/notherfile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
425
        wt.add(["afile"], [b"somefileid"])
426
        wt.commit("bla", rev_id=b"oldparent")
0.436.34 by Jelmer Vernooij
Some more tests.
427
        wt.add(["notherfile"])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
428
        wt.commit("bla", rev_id=b"oldcommit")
0.436.34 by Jelmer Vernooij
Some more tests.
429
        oldrepos = wt.branch.repository
430
        wt = self.make_branch_and_tree("new")
431
        self.build_tree(['new/afile', 'new/notherfile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
432
        wt.add(["afile"], [b"afileid"])
433
        wt.commit("bla", rev_id=b"newparent")
0.436.34 by Jelmer Vernooij
Some more tests.
434
        wt.branch.repository.fetch(oldrepos)
0.436.49 by Jelmer Vernooij
Fix locking.
435
        wt.branch.repository.lock_write()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
436
        CommitBuilderRevisionRewriter(wt.branch.repository)(
437
            b"oldcommit", b"newcommit", (b"newparent",))
0.436.49 by Jelmer Vernooij
Fix locking.
438
        wt.branch.repository.unlock()
0.436.34 by Jelmer Vernooij
Some more tests.
439
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
440
    def test_multi_revisions(self):
441
        wt = self.make_branch_and_tree("old")
7406.3.5 by Jelmer Vernooij
Fix formatting.
442
        self.build_tree_contents(
443
            [('old/afile', 'afilecontent'), ('old/sfile', 'sfilecontent'), ('old/notherfile', 'notherfilecontent')])
0.436.35 by Jelmer Vernooij
Make revid_renames argument mandatory.
444
        wt.add(['sfile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
445
        wt.add(["afile"], [b"somefileid"])
446
        wt.commit("bla", rev_id=b"oldgrandparent")
0.436.34 by Jelmer Vernooij
Some more tests.
447
        open("old/afile", "w").write("data")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
448
        wt.commit("bla", rev_id=b"oldparent")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
449
        wt.add(["notherfile"])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
450
        wt.commit("bla", rev_id=b"oldcommit")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
451
        oldrepos = wt.branch.repository
452
        wt = self.make_branch_and_tree("new")
7406.3.5 by Jelmer Vernooij
Fix formatting.
453
        self.build_tree_contents(
454
            [('new/afile', 'afilecontent'), ('new/sfile', 'sfilecontent'), ('new/notherfile', 'notherfilecontent')])
0.436.35 by Jelmer Vernooij
Make revid_renames argument mandatory.
455
        wt.add(['sfile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
456
        wt.add(["afile"], [b"afileid"])
457
        wt.commit("bla", rev_id=b"newgrandparent")
0.436.34 by Jelmer Vernooij
Some more tests.
458
        open("new/afile", "w").write("data")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
459
        wt.commit("bla", rev_id=b"newparent")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
460
        wt.branch.repository.fetch(oldrepos)
0.436.49 by Jelmer Vernooij
Fix locking.
461
        wt.branch.repository.lock_write()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
462
        CommitBuilderRevisionRewriter(wt.branch.repository)(
463
            b"oldcommit", b"newcommit", (b"newparent",))
0.436.49 by Jelmer Vernooij
Fix locking.
464
        wt.branch.repository.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
465
        oldrev = wt.branch.repository.get_revision(b"oldcommit")
466
        newrev = wt.branch.repository.get_revision(b"newcommit")
467
        self.assertEquals([b"newparent"], newrev.parent_ids)
468
        self.assertEquals(b"newcommit", newrev.revision_id)
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
469
        self.assertEquals(oldrev.committer, newrev.committer)
470
        self.assertEquals(oldrev.timestamp, newrev.timestamp)
471
        self.assertEquals(oldrev.timezone, newrev.timezone)
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
472
        tree = wt.branch.repository.revision_tree(b"newcommit")
473
        self.assertEquals(b"afileid", tree.path2id("afile"))
474
        self.assertEquals(b"newcommit", tree.get_file_revision("notherfile"))
475
        self.assertEquals(b"newgrandparent", tree.get_file_revision("sfile"))
0.436.34 by Jelmer Vernooij
Some more tests.
476
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
477
    def test_maps_ids(self):
478
        wt = self.make_branch_and_tree("old")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
479
        wt.commit("base", rev_id=b"base")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
480
        self.build_tree(['old/afile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
481
        wt.add(["afile"], ids=[b"originalid"])
482
        wt.commit("bla", rev_id=b"oldparent")
483
        with open("old/afile", "w") as f:
484
            f.write("bloe")
485
        wt.commit("bla", rev_id=b"oldcommit")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
486
        oldrepos = wt.branch.repository
487
        wt = self.make_branch_and_tree("new")
488
        self.build_tree(['new/afile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
489
        wt.add(["afile"], ids=[b"newid"])
490
        wt.commit("bla", rev_id=b"newparent")
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
491
        wt.branch.repository.fetch(oldrepos)
0.436.49 by Jelmer Vernooij
Fix locking.
492
        wt.branch.repository.lock_write()
7406.3.5 by Jelmer Vernooij
Fix formatting.
493
        CommitBuilderRevisionRewriter(wt.branch.repository)(
494
            b"oldcommit", b"newcommit", (b"newparent",))
0.436.49 by Jelmer Vernooij
Fix locking.
495
        wt.branch.repository.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
496
        oldrev = wt.branch.repository.get_revision(b"oldcommit")
497
        newrev = wt.branch.repository.get_revision(b"newcommit")
498
        self.assertEquals([b"newparent"], newrev.parent_ids)
499
        self.assertEquals(b"newcommit", newrev.revision_id)
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
500
        self.assertEquals(oldrev.committer, newrev.committer)
501
        self.assertEquals(oldrev.timestamp, newrev.timestamp)
502
        self.assertEquals(oldrev.timezone, newrev.timezone)
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
503
        tree = wt.branch.repository.revision_tree(b"newcommit")
504
        self.assertEquals(b"newid", tree.path2id("afile"))
505
        self.assertEquals(b"newcommit", tree.get_file_revision("afile"))
0.436.32 by Jelmer Vernooij
Properly detect invalid snapshot replays.
506
0.436.37 by Jelmer Vernooij
Store parents correctly.
507
508
class TestReplayWorkingtree(TestCaseWithTransport):
509
    def test_conflicts(self):
510
        wt = self.make_branch_and_tree("old")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
511
        wt.commit("base", rev_id=b"base")
0.436.37 by Jelmer Vernooij
Store parents correctly.
512
        self.build_tree(['old/afile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
513
        wt.add(["afile"], ids=[b"originalid"])
514
        wt.commit("bla", rev_id=b"oldparent")
515
        with open("old/afile", "w") as f:
516
            f.write("bloe")
517
        wt.commit("bla", rev_id=b"oldcommit")
0.436.37 by Jelmer Vernooij
Store parents correctly.
518
        oldrepos = wt.branch.repository
519
        wt = self.make_branch_and_tree("new")
520
        self.build_tree(['new/afile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
521
        wt.add(["afile"], ids=[b"newid"])
522
        wt.commit("bla", rev_id=b"newparent")
0.436.37 by Jelmer Vernooij
Store parents correctly.
523
        wt.branch.repository.fetch(oldrepos)
7406.3.5 by Jelmer Vernooij
Fix formatting.
524
        with wt.lock_write():
525
            replayer = WorkingTreeRevisionRewriter(wt, RebaseState1(wt))
526
            self.assertRaises(
527
                ConflictsInTree,
528
                replayer, b"oldcommit", b"newcommit",
529
                [b"newparent"], )
0.436.37 by Jelmer Vernooij
Store parents correctly.
530
531
    def test_simple(self):
532
        wt = self.make_branch_and_tree("old")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
533
        wt.commit("base", rev_id=b"base")
0.436.37 by Jelmer Vernooij
Store parents correctly.
534
        self.build_tree(['old/afile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
535
        wt.add(["afile"], ids=[b"originalid"])
536
        wt.commit("bla", rev_id=b"oldparent")
537
        with open("old/afile", "w") as f:
538
            f.write("bloe")
539
        wt.commit("bla", rev_id=b"oldcommit")
540
        wt = wt.controldir.sprout("new").open_workingtree()
0.436.37 by Jelmer Vernooij
Store parents correctly.
541
        self.build_tree(['new/bfile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
542
        wt.add(["bfile"], ids=[b"newid"])
543
        wt.commit("bla", rev_id=b"newparent")
0.436.203 by Jelmer Vernooij
Use camelcasing for class names.
544
        replayer = WorkingTreeRevisionRewriter(wt, RebaseState1(wt))
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
545
        replayer(b"oldcommit", b"newcommit", [b"newparent"])
546
        oldrev = wt.branch.repository.get_revision(b"oldcommit")
547
        newrev = wt.branch.repository.get_revision(b"newcommit")
548
        self.assertEquals([b"newparent"], newrev.parent_ids)
549
        self.assertEquals(b"newcommit", newrev.revision_id)
0.436.37 by Jelmer Vernooij
Store parents correctly.
550
        self.assertEquals(oldrev.timestamp, newrev.timestamp)
551
        self.assertEquals(oldrev.timezone, newrev.timezone)
552
553
    def test_multiple(self):
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
554
        # rebase from
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
555
        # base: []
556
        # oldparent: [base]
557
        # newparent: [base]
558
        # oldcommit: [oldparent, ghost]
559
        # create newcommit by rebasing oldcommit from oldparent to newparent,
560
        # keeping the merge of ghost.
561
        # Common base:
0.436.37 by Jelmer Vernooij
Store parents correctly.
562
        wt = self.make_branch_and_tree("old")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
563
        wt.commit("base", rev_id=b"base")
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
564
        # oldparent:
565
        self.build_tree_contents([('old/afile', 'base content')])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
566
        wt.add(["afile"], ids=[b"originalid"])
567
        wt.commit("bla", rev_id=b"oldparent")
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
568
        # oldcommit (the delta getting rebased)
569
        #  - change the content of afile to be 'bloe'
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
570
        with open("old/afile", "w") as f:
571
            f.write("bloe")
572
        wt.add_pending_merge(b"ghost")
573
        wt.commit("bla", rev_id=b"oldcommit")
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
574
        # newparent (the new base for the rebased commit)
7406.3.5 by Jelmer Vernooij
Fix formatting.
575
        new_tree = wt.controldir.sprout(
576
            "new", revision_id=b'base').open_workingtree()
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
577
        new_tree.branch.repository.fetch(wt.branch.repository)
578
        wt = new_tree
579
        self.build_tree_contents([('new/afile', 'base content')])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
580
        wt.add(["afile"], ids=[b"originalid"])
581
        wt.commit("bla", rev_id=b"newparent")
0.441.3 by Robert Collins
Update rebase to 1.6b3 API changes.
582
        # And do it!
0.436.62 by Jelmer Vernooij
Fix compatibility with packs.
583
        wt.lock_write()
0.436.203 by Jelmer Vernooij
Use camelcasing for class names.
584
        replayer = WorkingTreeRevisionRewriter(wt, RebaseState1(wt))
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
585
        replayer(b"oldcommit", b"newcommit", (b"newparent", b"ghost"))
0.436.62 by Jelmer Vernooij
Fix compatibility with packs.
586
        wt.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
587
        oldrev = wt.branch.repository.get_revision(b"oldcommit")
588
        newrev = wt.branch.repository.get_revision(b"newcommit")
589
        self.assertEquals([b"oldparent", b"ghost"], oldrev.parent_ids)
590
        self.assertEquals([b"newparent", b"ghost"], newrev.parent_ids)
591
        self.assertEquals(b"newcommit", newrev.revision_id)
0.436.37 by Jelmer Vernooij
Store parents correctly.
592
        self.assertEquals(oldrev.timestamp, newrev.timestamp)
593
        self.assertEquals(oldrev.timezone, newrev.timezone)
594
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
595
    def test_already_merged(self):
7457.1.1 by Jelmer Vernooij
Fix invalid escape sequence errors on Python 3.
596
        r"""We need to use a merge base that makes sense.
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
597
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
598
        A
599
        | \
600
        B  D
601
        | \|
602
        C  E
603
604
        Rebasing E on C should result in:
605
0.438.1 by Jelmer Vernooij
Split out function for determining rebase base.
606
        A -> B -> C -> D' -> E'
607
608
        Ancestry:
0.436.177 by Jelmer Vernooij
Remove trailing whitespace.
609
        A:
0.438.1 by Jelmer Vernooij
Split out function for determining rebase base.
610
        B: A
611
        C: A, B
612
        D: A
613
        E: A, B, D
614
        D': A, B, C
615
        E': A, B, C, D'
616
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
617
        """
618
        oldwt = self.make_branch_and_tree("old")
619
        self.build_tree(['old/afile'])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
620
        with open("old/afile", "w") as f:
621
            f.write("A\n" * 10)
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
622
        oldwt.add(["afile"])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
623
        oldwt.commit("base", rev_id=b"A")
624
        newwt = oldwt.controldir.sprout("new").open_workingtree()
625
        with open("old/afile", "w") as f:
7406.3.5 by Jelmer Vernooij
Fix formatting.
626
            f.write("A\n" * 10 + "B\n")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
627
        oldwt.commit("bla", rev_id=b"B")
628
        with open("old/afile", "w") as f:
629
            f.write("A\n" * 10 + "C\n")
630
        oldwt.commit("bla", rev_id=b"C")
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
631
        self.build_tree(['new/bfile'])
632
        newwt.add(["bfile"])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
633
        with open("new/bfile", "w") as f:
634
            f.write("D\n")
635
        newwt.commit("bla", rev_id=b"D")
636
        with open("new/afile", "w") as f:
7406.3.5 by Jelmer Vernooij
Fix formatting.
637
            f.write("E\n" + "A\n" * 10 + "B\n")
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
638
        with open("new/bfile", "w") as f:
639
            f.write("D\nE\n")
640
        newwt.add_pending_merge(b"B")
641
        newwt.commit("bla", rev_id=b"E")
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
642
        newwt.branch.repository.fetch(oldwt.branch.repository)
0.436.62 by Jelmer Vernooij
Fix compatibility with packs.
643
        newwt.lock_write()
0.436.203 by Jelmer Vernooij
Use camelcasing for class names.
644
        replayer = WorkingTreeRevisionRewriter(newwt, RebaseState1(newwt))
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
645
        replayer(b"D", b"D'", [b"C"])
0.436.62 by Jelmer Vernooij
Fix compatibility with packs.
646
        newwt.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
647
        oldrev = newwt.branch.repository.get_revision(b"D")
648
        newrev = newwt.branch.repository.get_revision(b"D'")
649
        self.assertEquals([b"C"], newrev.parent_ids)
0.436.62 by Jelmer Vernooij
Fix compatibility with packs.
650
        newwt.lock_write()
0.436.203 by Jelmer Vernooij
Use camelcasing for class names.
651
        replayer = WorkingTreeRevisionRewriter(newwt, RebaseState1(newwt))
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
652
        self.assertRaises(ConflictsInTree, replayer, b"E", b"E'", [b"D'"])
0.436.62 by Jelmer Vernooij
Fix compatibility with packs.
653
        newwt.unlock()
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
654
        with open("new/afile", 'r') as f:
655
            self.assertEquals("E\n" + "A\n" * 10 + "C\n", f.read())
7490.129.3 by Jelmer Vernooij
Split out bzr-specific Conflicts code.
656
        newwt.set_conflicts([])
7406.3.3 by Jelmer Vernooij
Fix python3 compatibility.
657
        oldrev = newwt.branch.repository.get_revision(b"E")
658
        replayer.commit_rebase(oldrev, b"E'")
659
        newrev = newwt.branch.repository.get_revision(b"E'")
660
        self.assertEquals([b"D'"], newrev.parent_ids)
661
        self.assertThat(
662
            newwt.branch,
663
            RevisionHistoryMatches([b"A", b"B", b"C", b"D'", b"E'"]))
0.436.39 by Jelmer Vernooij
Some more refactoring, add test that demonstrates #126743.
664
0.436.37 by Jelmer Vernooij
Store parents correctly.
665
0.436.34 by Jelmer Vernooij
Some more tests.
666
class TestReplaySnapshotError(TestCase):
0.436.248 by Jelmer Vernooij
Use feature flags.
667
0.436.34 by Jelmer Vernooij
Some more tests.
668
    def test_create(self):
669
        ReplaySnapshotError("message")