/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-02 09:21:20 UTC
  • mfrom: (4396 +trunk)
  • mto: (4396.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4397.
  • Revision ID: v.ladeuil+lp@free.fr-20090602092120-xs1ikguqckiu820o
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    format_registry,
35
35
    )
36
36
from bzrlib.inventory import Inventory
37
 
from bzrlib.revision import Revision
 
37
from bzrlib.revision import (
 
38
    NULL_REVISION,
 
39
    Revision,
 
40
    )
38
41
from bzrlib.tests import (
39
42
    TestCase,
40
43
    TestCaseWithTransport,
110
113
        return isinstance(target, DummyForeignVcsBranch)
111
114
 
112
115
    def lossy_push(self, stop_revision=None):
 
116
        result = branch.BranchPushResult()
 
117
        result.source_branch = self.source
 
118
        result.target_branch = self.target
 
119
        result.old_revno, result.old_revid = self.target.last_revision_info()
113
120
        self.source.lock_read()
114
121
        try:
115
122
            # This just handles simple cases, but that's good enough for tests
129
136
                    (str(rev.timestamp), str(rev.timezone), 
130
137
                        str(self.target.revno())))
131
138
                parent_revno, parent_revid= self.target.last_revision_info()
132
 
                builder = self.target.get_commit_builder([parent_revid], 
 
139
                if parent_revid == NULL_REVISION:
 
140
                    parent_revids = []
 
141
                else:
 
142
                    parent_revids = [parent_revid]
 
143
                builder = self.target.get_commit_builder(parent_revids, 
133
144
                        self.target.get_config(), rev.timestamp,
134
145
                        rev.timezone, rev.committer, rev.properties,
135
146
                        new_revid)
138
149
                        new_ie = ie.copy()
139
150
                        new_ie.revision = None
140
151
                        builder.record_entry_contents(new_ie, 
141
 
                            [self.target.repository.get_inventory(parent_revid)],
 
152
                            [self.target.repository.revision_tree(parent_revid).inventory],
142
153
                            path, tree, 
143
154
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
144
155
                    builder.finish_inventory()
152
163
                    revid, revidmap[revid])
153
164
        finally:
154
165
            self.source.unlock()
155
 
        return revidmap
 
166
        result.new_revno, result.new_revid = self.target.last_revision_info()
 
167
        result.revidmap = revidmap
 
168
        return result
156
169
 
157
170
 
158
171
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
288
301
        self.assertEquals(mapp, rev.mapping)
289
302
 
290
303
 
291
 
class ShowForeignPropertiesTests(TestCase):
292
 
    """Tests for the show_foreign_properties() function."""
293
 
 
294
 
    def setUp(self):
295
 
        super(ShowForeignPropertiesTests, self).setUp()
296
 
        self.vcs = DummyForeignVcs()
297
 
        foreign.foreign_vcs_registry.register("dummy",
298
 
            self.vcs, "Dummy VCS")
299
 
 
300
 
    def tearDown(self):
301
 
        super(ShowForeignPropertiesTests, self).tearDown()
302
 
        foreign.foreign_vcs_registry.remove("dummy")
303
 
 
304
 
    def test_show_non_foreign(self):
305
 
        """Test use with a native (non-foreign) bzr revision."""
306
 
        self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid")))
307
 
 
308
 
    def test_show_imported(self):
309
 
        rev = Revision("dummy-v1:my-foreign-revid")
310
 
        self.assertEquals({ "dummy ding": "my/foreign\\revid" },
311
 
                          foreign.show_foreign_properties(rev))
312
 
 
313
 
    def test_show_direct(self):
314
 
        rev = foreign.ForeignRevision(("some", "foreign", "revid"),
315
 
                                      DummyForeignVcsMapping(self.vcs),
316
 
                                      "roundtrip-revid")
317
 
        self.assertEquals({ "dummy ding": "some/foreign\\revid" },
318
 
                          foreign.show_foreign_properties(rev))
319
 
 
320
 
 
321
304
class WorkingTreeFileUpdateTests(TestCaseWithTransport):
322
305
    """Tests for update_workingtree_fileids()."""
323
306
 
372
355
        dir = BzrDir.open("d")
373
356
        newdir = dir.sprout("e")
374
357
        self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
 
358
 
 
359
    def test_lossy_push_empty(self):
 
360
        source_tree = self.make_branch_and_tree("source")
 
361
        target_tree = self.make_branch_and_tree("target", 
 
362
            format=DummyForeignVcsDirFormat())
 
363
        pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
364
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
365
        self.assertEquals(NULL_REVISION, pushresult.new_revid)
 
366
        self.assertEquals({}, pushresult.revidmap)
 
367
 
 
368
    def test_lossy_push_simple(self):
 
369
        source_tree = self.make_branch_and_tree("source")
 
370
        self.build_tree(['source/a', 'source/b'])
 
371
        source_tree.add(['a', 'b'])
 
372
        revid1 = source_tree.commit("msg")
 
373
        target_tree = self.make_branch_and_tree("target", 
 
374
            format=DummyForeignVcsDirFormat())
 
375
        target_tree.branch.lock_write()
 
376
        try:
 
377
            pushresult = source_tree.branch.lossy_push(target_tree.branch)
 
378
        finally:
 
379
            target_tree.branch.unlock()
 
380
        self.assertEquals(NULL_REVISION, pushresult.old_revid)
 
381
        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
 
382
                           pushresult.revidmap)
 
383
        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)