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