~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Rory Yorke
  • Date: 2010-10-20 14:38:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5519.
  • Revision ID: rory.yorke@gmail.com-20101020143853-9kfd2ldcjfroh8jw
Show missing files in bzr status (bug 134168).

"bzr status" will now show missing files, that is, those added with "bzr
add" and then removed by non bzr means (e.g., rm).

Blackbox tests were added for this case, and tests were also added to
test_delta, since the implementation change is in bzrlib.delta.

Might also affect bug 189709.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
26
    foreign,
27
27
    lockable_files,
28
28
    lockdir,
29
 
    repository,
30
29
    revision,
31
30
    tests,
32
31
    trace,
33
32
    )
34
33
 
35
 
from bzrlib.repofmt import groupcompress_repo
36
 
 
37
34
# This is the dummy foreign revision control system, used 
38
35
# mainly here in the testsuite to test the foreign VCS infrastructure.
39
36
# It is basically standard Bazaar with some minor modifications to 
95
92
        self._base = a_bzrdir.transport.base
96
93
        self._ignore_fallbacks = False
97
94
        self.bzrdir = a_bzrdir
98
 
        foreign.ForeignBranch.__init__(self,
 
95
        foreign.ForeignBranch.__init__(self, 
99
96
            DummyForeignVcsMapping(DummyForeignVcs()))
100
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
 
97
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
101
98
            *args, **kwargs)
102
99
 
103
 
    def _get_checkout_format(self):
104
 
        """Return the most suitable metadir for a checkout of this branch.
105
 
        Weaves are used if this branch's repository uses weaves.
106
 
        """
107
 
        return self.bzrdir.checkout_metadir()
108
 
 
109
 
    def import_last_revision_info_and_tags(self, source, revno, revid,
110
 
                                           lossy=False):
111
 
        interbranch = InterToDummyVcsBranch(source, self)
112
 
        if lossy:
113
 
            result = interbranch.lossy_push(revid)
114
 
            revid = result.revidmap[revid]
115
 
        else:
116
 
            interbranch.push(revid)
117
 
        return (revno, revid)
118
 
 
119
 
 
120
 
class DummyForeignCommitBuilder(repository.RootCommitBuilder):
121
 
 
122
 
    def _generate_revision_if_needed(self):
123
 
        mapping = DummyForeignVcsMapping(DummyForeignVcs())
124
 
        if self._lossy:
125
 
            self._new_revision_id = mapping.revision_id_foreign_to_bzr(
126
 
                (str(self._timestamp), str(self._timezone), "UNKNOWN"))
127
 
            self.random_revid = False
128
 
        elif self._new_revision_id is not None:
129
 
            self.random_revid = False
130
 
        else:
131
 
            self._new_revision_id = self._gen_revision_id()
132
 
            self.random_revid = True
133
 
 
134
 
 
135
 
class DummyForeignVcsRepository(groupcompress_repo.CHKInventoryRepository,
136
 
    foreign.ForeignRepository):
137
 
    """Dummy foreign vcs repository."""
138
 
 
139
 
 
140
 
class DummyForeignVcsRepositoryFormat(groupcompress_repo.RepositoryFormat2a):
141
 
 
142
 
    repository_class = DummyForeignVcsRepository
143
 
    _commit_builder_class = DummyForeignCommitBuilder
144
 
 
145
 
    def get_format_string(self):
146
 
        return "Dummy Foreign Vcs Repository"
147
 
 
148
 
    def get_format_description(self):
149
 
        return "Dummy Foreign Vcs Repository"
150
 
 
151
100
 
152
101
class InterToDummyVcsBranch(branch.GenericInterBranch,
153
102
                            foreign.InterToForeignBranch):
168
117
        try:
169
118
            # This just handles simple cases, but that's good enough for tests
170
119
            my_history = self.target.revision_history()
171
 
            if stop_revision is None:
172
 
                stop_revision = self.source.last_revision()
173
 
            their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
174
 
            their_history.reverse()
 
120
            their_history = self.source.revision_history()
175
121
            if their_history[:min(len(my_history), len(their_history))] != my_history:
176
122
                raise errors.DivergedBranches(self.target, self.source)
177
123
            todo = their_history[len(my_history):]
227
173
        super(DummyForeignVcsBranchFormat, self).__init__()
228
174
        self._matchingbzrdir = DummyForeignVcsDirFormat()
229
175
 
230
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
231
 
            found_repository=None):
 
176
    def open(self, a_bzrdir, name=None, _found=False):
232
177
        if not _found:
233
178
            raise NotImplementedError
234
179
        try:
235
180
            transport = a_bzrdir.get_branch_transport(None, name=name)
236
181
            control_files = lockable_files.LockableFiles(transport, 'lock',
237
182
                                                         lockdir.LockDir)
238
 
            if found_repository is None:
239
 
                found_repository = a_bzrdir.find_repository()
240
183
            return DummyForeignVcsBranch(_format=self,
241
184
                              _control_files=control_files,
242
185
                              a_bzrdir=a_bzrdir,
243
 
                              _repository=found_repository)
 
186
                              _repository=a_bzrdir.find_repository())
244
187
        except errors.NoSuchFile:
245
188
            raise errors.NotBranchError(path=transport.base)
246
189
 
263
206
    def get_branch_format(self):
264
207
        return DummyForeignVcsBranchFormat()
265
208
 
266
 
    @property
267
 
    def repository_format(self):
268
 
        return DummyForeignVcsRepositoryFormat()
269
 
 
270
209
    def initialize_on_transport(self, transport):
271
210
        """Initialize a new bzrdir in the base directory of a Transport."""
272
211
        # Since we don't have a .bzr directory, inherit the
299
238
        self._control_files = lockable_files.LockableFiles(self.transport,
300
239
            "lock", lockable_files.TransportLock)
301
240
 
302
 
    def create_workingtree(self):
303
 
        # dirstate requires a ".bzr" entry to exist
304
 
        self.root_transport.put_bytes(".bzr", "foo")
305
 
        return super(DummyForeignVcsDir, self).create_workingtree()
306
 
 
307
241
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=True):
308
242
        if name is not None:
309
243
            raise errors.NoColocatedBranchSupport(self)
313
247
        """Produce a metadir suitable for cloning with."""
314
248
        return bzrdir.format_registry.make_bzrdir("default")
315
249
 
316
 
    def checkout_metadir(self):
317
 
        return self.cloning_metadir()
318
 
 
319
250
    def sprout(self, url, revision_id=None, force_new_repo=False,
320
251
               recurse='down', possible_transports=None,
321
252
               accelerator_tree=None, hardlink=False, stacked=False,
329
260
 
330
261
 
331
262
def register_dummy_foreign_for_test(testcase):
 
263
    controldir.ControlDirFormat.register_format(DummyForeignVcsDirFormat)
 
264
    testcase.addCleanup(controldir.ControlDirFormat.unregister_format,
 
265
                        DummyForeignVcsDirFormat)
332
266
    controldir.ControlDirFormat.register_prober(DummyForeignProber)
333
267
    testcase.addCleanup(controldir.ControlDirFormat.unregister_prober,
334
268
        DummyForeignProber)
335
 
    repository.format_registry.register(DummyForeignVcsRepositoryFormat())
336
 
    testcase.addCleanup(repository.format_registry.remove,
337
 
            DummyForeignVcsRepositoryFormat())
338
 
    branch.format_registry.register(DummyForeignVcsBranchFormat())
339
 
    testcase.addCleanup(branch.format_registry.remove,
340
 
            DummyForeignVcsBranchFormat())
341
269
    # We need to register the optimiser to make the dummy appears really
342
270
    # different from a regular bzr repository.
343
271
    branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
354
282
            raise errors.NotBranchError(path=transport.base)
355
283
        return DummyForeignVcsDirFormat()
356
284
 
357
 
    @classmethod
358
 
    def known_formats(cls):
359
 
        return set([DummyForeignVcsDirFormat()])
360
 
 
361
285
 
362
286
class ForeignVcsRegistryTests(tests.TestCase):
363
287
    """Tests for the ForeignVcsRegistry class."""
376
300
        reg = foreign.ForeignVcsRegistry()
377
301
        vcs = DummyForeignVcs()
378
302
        reg.register("dummy", vcs, "Dummy VCS")
379
 
        self.assertEquals((
380
 
            ("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
381
 
            reg.parse_revision_id("dummy-v1:some-foreign-revid"))
 
303
        self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)),
 
304
                          reg.parse_revision_id("dummy-v1:some-foreign-revid"))
382
305
 
383
306
 
384
307
class ForeignRevisionTests(tests.TestCase):