~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Lukáš Lalinský
  • Date: 2008-08-28 13:41:15 UTC
  • mto: (3732.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3733.
  • Revision ID: lalinsky@gmail.com-20080828134115-265uyumclq5qvetg
Fix `bzr st -rbranch:PATH_TO_BRANCH`

* Add RevisionSpec.as_tree which returns a tree representation of the revision specifier. This might return a remote revision tree.
* Make status use this new method and not require RevisionSpec.as_revision_id, which for RevisionSpec_branch fetches data to the local repository.
* Refactor common code for getting either a revision tree or a tree/branch's basis tree into a private function _get_revision_tree and make it use RevisionSpec.as_tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    bzrdir,
24
24
    errors,
25
25
    repository,
 
26
    revision as _mod_revision,
26
27
    )
27
28
from bzrlib.tests import TestCase, TestCaseWithTransport
28
29
from bzrlib.revisionspec import (
100
101
        self.assertEqual(revision_id,
101
102
                         spec.as_revision_id(self.tree.branch))
102
103
 
 
104
    def get_as_tree(self, revision_spec, tree=None):
 
105
        if tree is None:
 
106
            tree = self.tree
 
107
        spec = RevisionSpec.from_string(revision_spec)
 
108
        return spec.as_tree(tree.branch)
 
109
 
103
110
 
104
111
class RevisionSpecMatchOnTrap(RevisionSpec):
105
112
 
300
307
        self.assertAsRevisionId('r2', '-1')
301
308
        self.assertAsRevisionId('alt_r2', '1.1.1')
302
309
 
 
310
    def test_as_tree(self):
 
311
        tree = self.get_as_tree('0')
 
312
        self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
 
313
        tree = self.get_as_tree('1')
 
314
        self.assertEquals('r1', tree.get_revision_id())
 
315
        tree = self.get_as_tree('2')
 
316
        self.assertEquals('r2', tree.get_revision_id())
 
317
        tree = self.get_as_tree('-2')
 
318
        self.assertEquals('r1', tree.get_revision_id())
 
319
        tree = self.get_as_tree('-1')
 
320
        self.assertEquals('r2', tree.get_revision_id())
 
321
        tree = self.get_as_tree('1.1.1')
 
322
        self.assertEquals('alt_r2', tree.get_revision_id())
 
323
 
303
324
 
304
325
class TestRevisionSpec_revid(TestRevisionSpec):
305
326
    
564
585
        new_tree = self.make_branch_and_tree('new_tree')
565
586
        self.assertRaises(errors.NoCommits,
566
587
                          self.get_in_history, 'branch:new_tree')
 
588
        self.assertRaises(errors.NoCommits,
 
589
                          self.get_as_tree, 'branch:new_tree')
567
590
 
568
591
    def test_as_revision_id(self):
569
592
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
570
593
 
 
594
    def test_as_tree(self):
 
595
        tree = self.get_as_tree('branch:tree', self.tree2)
 
596
        self.assertEquals('r2', tree.get_revision_id())
 
597
        self.assertFalse(self.tree2.branch.repository.has_revision('r2'))
 
598
 
571
599
 
572
600
class TestRevisionSpec_submit(TestRevisionSpec):
573
601