~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import datetime
18
 
import os
19
18
import time
20
19
 
21
20
from bzrlib import (
22
 
    branch,
23
 
    bzrdir,
24
21
    errors,
25
 
    repository,
 
22
    revision as _mod_revision,
26
23
    )
27
 
from bzrlib.builtins import merge
28
 
from bzrlib.tests import TestCase, TestCaseWithTransport
 
24
from bzrlib.tests import TestCaseWithTransport
29
25
from bzrlib.revisionspec import (
 
26
    RevisionInfo,
30
27
    RevisionSpec,
31
 
    RevisionSpec_revno,
 
28
    RevisionSpec_dwim,
32
29
    RevisionSpec_tag,
33
30
    )
34
31
 
50
47
 
51
48
        self.tree = self.make_branch_and_tree('tree')
52
49
        self.build_tree(['tree/a'])
 
50
        self.tree.lock_write()
 
51
        self.addCleanup(self.tree.unlock)
53
52
        self.tree.add(['a'])
54
53
        self.tree.commit('a', rev_id='r1')
55
54
 
56
55
        self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
57
56
        self.tree2.commit('alt', rev_id='alt_r2')
58
57
 
59
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
60
 
                                          revision_id='alt_r2')
61
 
        self.tree.set_pending_merges(['alt_r2'])
 
58
        self.tree.merge_from_branch(self.tree2.branch)
62
59
        self.tree.commit('second', rev_id='r2')
63
60
 
64
61
    def get_in_history(self, revision_spec):
74
71
                         ' %r != %r'
75
72
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
76
73
 
77
 
    def assertInvalid(self, revision_spec, extra=''):
 
74
    def assertInvalid(self, revision_spec, extra='',
 
75
                      invalid_as_revision_id=True):
78
76
        try:
79
77
            self.get_in_history(revision_spec)
80
78
        except errors.InvalidRevisionSpec, e:
81
79
            self.assertEqual(revision_spec, e.spec)
82
80
            self.assertEqual(extra, e.extra)
83
81
        else:
84
 
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
85
 
                      % (revision_spec,))
 
82
            self.fail('Expected InvalidRevisionSpec to be raised for'
 
83
                      ' %r.in_history' % (revision_spec,))
 
84
        if invalid_as_revision_id:
 
85
            try:
 
86
                spec = RevisionSpec.from_string(revision_spec)
 
87
                spec.as_revision_id(self.tree.branch)
 
88
            except errors.InvalidRevisionSpec, e:
 
89
                self.assertEqual(revision_spec, e.spec)
 
90
                self.assertEqual(extra, e.extra)
 
91
            else:
 
92
                self.fail('Expected InvalidRevisionSpec to be raised for'
 
93
                          ' %r.as_revision_id' % (revision_spec,))
 
94
 
 
95
    def assertAsRevisionId(self, revision_id, revision_spec):
 
96
        """Calling as_revision_id() should return the specified id."""
 
97
        spec = RevisionSpec.from_string(revision_spec)
 
98
        self.assertEqual(revision_id,
 
99
                         spec.as_revision_id(self.tree.branch))
 
100
 
 
101
    def get_as_tree(self, revision_spec, tree=None):
 
102
        if tree is None:
 
103
            tree = self.tree
 
104
        spec = RevisionSpec.from_string(revision_spec)
 
105
        return spec.as_tree(tree.branch)
 
106
 
 
107
 
 
108
class RevisionSpecMatchOnTrap(RevisionSpec):
 
109
 
 
110
    def _match_on(self, branch, revs):
 
111
        self.last_call = (branch, revs)
 
112
        return super(RevisionSpecMatchOnTrap, self)._match_on(branch, revs)
 
113
 
 
114
 
 
115
class TestRevisionSpecBase(TestRevisionSpec):
 
116
 
 
117
    def test_wants_revision_history(self):
 
118
        # If wants_revision_history = True, then _match_on should get the
 
119
        # branch revision history
 
120
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
 
121
        spec.in_history(self.tree.branch)
 
122
 
 
123
        self.assertEqual((self.tree.branch, ['r1' ,'r2']),
 
124
                         spec.last_call)
 
125
 
 
126
    def test_wants_no_revision_history(self):
 
127
        # If wants_revision_history = False, then _match_on should get None for
 
128
        # the branch revision history
 
129
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
 
130
        spec.wants_revision_history = False
 
131
        spec.in_history(self.tree.branch)
 
132
 
 
133
        self.assertEqual((self.tree.branch, None), spec.last_call)
 
134
 
86
135
 
87
136
 
88
137
class TestOddRevisionSpec(TestRevisionSpec):
89
138
    """Test things that aren't normally thought of as revision specs"""
90
139
 
91
140
    def test_none(self):
92
 
        self.assertInHistoryIs(0, None, None)
 
141
        self.assertInHistoryIs(None, None, None)
93
142
 
94
143
    def test_object(self):
95
144
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
96
145
 
97
 
    def test_unregistered_spec(self):
98
 
        self.assertRaises(errors.NoSuchRevisionSpec,
99
 
                          RevisionSpec.from_string, 'foo')
100
 
        self.assertRaises(errors.NoSuchRevisionSpec,
101
 
                          RevisionSpec.from_string, '123a')
102
 
 
103
 
 
104
 
 
105
 
class TestRevnoFromString(TestCase):
106
 
 
107
 
    def test_from_string_dotted_decimal(self):
108
 
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '-1.1')
109
 
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '.1')
110
 
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1..1')
111
 
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.2..1')
112
 
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.')
113
 
        self.assertIsInstance(RevisionSpec.from_string('1.1'), RevisionSpec_revno)
114
 
        self.assertIsInstance(RevisionSpec.from_string('1.1.3'), RevisionSpec_revno)
 
146
 
 
147
class RevisionSpec_bork(RevisionSpec):
 
148
 
 
149
    prefix = 'irrelevant:'
 
150
 
 
151
    def _match_on(self, branch, revs):
 
152
        if self.spec == "bork":
 
153
            return RevisionInfo.from_revision_id(branch, "r1", revs)
 
154
        else:
 
155
            raise errors.InvalidRevisionSpec(self.spec, branch)
 
156
 
 
157
 
 
158
class TestRevisionSpec_dwim(TestRevisionSpec):
 
159
 
 
160
    # Don't need to test revno's explicitly since TRS_revno already
 
161
    # covers that well for us
 
162
    def test_dwim_spec_revno(self):
 
163
        self.assertInHistoryIs(2, 'r2', '2')
 
164
        self.assertAsRevisionId('alt_r2', '1.1.1')
 
165
 
 
166
    def test_dwim_spec_revid(self):
 
167
        self.assertInHistoryIs(2, 'r2', 'r2')
 
168
 
 
169
    def test_dwim_spec_tag(self):
 
170
        self.tree.branch.tags.set_tag('footag', 'r1')
 
171
        self.assertAsRevisionId('r1', 'footag')
 
172
        self.tree.branch.tags.delete_tag('footag')
 
173
        self.assertRaises(errors.InvalidRevisionSpec,
 
174
                          self.get_in_history, 'footag')
 
175
 
 
176
    def test_dwim_spec_tag_that_looks_like_revno(self):
 
177
        # Test that we slip past revno with things that look like revnos,
 
178
        # but aren't.  Tags are convenient for testing this since we can
 
179
        # make them look however we want.
 
180
        self.tree.branch.tags.set_tag('3', 'r2')
 
181
        self.assertAsRevisionId('r2', '3')
 
182
        self.build_tree(['tree/b'])
 
183
        self.tree.add(['b'])
 
184
        self.tree.commit('b', rev_id='r3')
 
185
        self.assertAsRevisionId('r3', '3')
 
186
 
 
187
    def test_dwim_spec_date(self):
 
188
        self.assertAsRevisionId('r1', 'today')
 
189
 
 
190
    def test_dwim_spec_branch(self):
 
191
        self.assertInHistoryIs(None, 'alt_r2', 'tree2')
 
192
 
 
193
    def test_dwim_spec_nonexistent(self):
 
194
        self.assertInvalid('somethingrandom', invalid_as_revision_id=False)
 
195
        self.assertInvalid('-1.1', invalid_as_revision_id=False)
 
196
        self.assertInvalid('.1', invalid_as_revision_id=False)
 
197
        self.assertInvalid('1..1', invalid_as_revision_id=False)
 
198
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
 
199
        self.assertInvalid('1.', invalid_as_revision_id=False)
 
200
 
 
201
    def test_append_dwim_revspec(self):
 
202
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
 
203
        def reset_dwim_revspecs():
 
204
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
 
205
        self.addCleanup(reset_dwim_revspecs)
 
206
        RevisionSpec_dwim.append_possible_revspec(RevisionSpec_bork)
 
207
        self.assertAsRevisionId('r1', 'bork')
 
208
 
 
209
    def test_append_lazy_dwim_revspec(self):
 
210
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
 
211
        def reset_dwim_revspecs():
 
212
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
 
213
        self.addCleanup(reset_dwim_revspecs)
 
214
        RevisionSpec_dwim.append_possible_lazy_revspec(
 
215
            "bzrlib.tests.test_revisionspec", "RevisionSpec_bork")
 
216
        self.assertAsRevisionId('r1', 'bork')
115
217
 
116
218
 
117
219
class TestRevisionSpec_revno(TestRevisionSpec):
118
220
 
119
221
    def test_positive_int(self):
120
 
        self.assertInHistoryIs(0, None, '0')
 
222
        self.assertInHistoryIs(0, 'null:', '0')
121
223
        self.assertInHistoryIs(1, 'r1', '1')
122
224
        self.assertInHistoryIs(2, 'r2', '2')
123
225
        self.assertInvalid('3')
124
226
 
125
227
    def test_dotted_decimal(self):
126
228
        self.assertInHistoryIs(None, 'alt_r2', '1.1.1')
 
229
        self.assertInvalid('1.1.123')
127
230
 
128
231
    def test_negative_int(self):
129
232
        self.assertInHistoryIs(2, 'r2', '-1')
134
237
        self.assertInHistoryIs(1, 'r1', '-100')
135
238
 
136
239
    def test_positive(self):
137
 
        self.assertInHistoryIs(0, None, 'revno:0')
 
240
        self.assertInHistoryIs(0, 'null:', 'revno:0')
138
241
        self.assertInHistoryIs(1, 'r1', 'revno:1')
139
242
        self.assertInHistoryIs(2, 'r2', 'revno:2')
140
243
 
223
326
        """Old revno:N:path tests"""
224
327
        wta = self.make_branch_and_tree('a')
225
328
        ba = wta.branch
226
 
        
 
329
 
227
330
        wta.commit('Commit one', rev_id='a@r-0-1')
228
331
        wta.commit('Commit two', rev_id='a@r-0-2')
229
332
        wta.commit('Commit three', rev_id='a@r-0-3')
247
350
        self.assertEqual((2, 'b@r-0-2'),
248
351
                         spec_in_history('revno:2:b/', None))
249
352
 
 
353
    def test_as_revision_id(self):
 
354
        self.assertAsRevisionId('null:', '0')
 
355
        self.assertAsRevisionId('r1', '1')
 
356
        self.assertAsRevisionId('r2', '2')
 
357
        self.assertAsRevisionId('r1', '-2')
 
358
        self.assertAsRevisionId('r2', '-1')
 
359
        self.assertAsRevisionId('alt_r2', '1.1.1')
 
360
 
 
361
    def test_as_tree(self):
 
362
        tree = self.get_as_tree('0')
 
363
        self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
 
364
        tree = self.get_as_tree('1')
 
365
        self.assertEquals('r1', tree.get_revision_id())
 
366
        tree = self.get_as_tree('2')
 
367
        self.assertEquals('r2', tree.get_revision_id())
 
368
        tree = self.get_as_tree('-2')
 
369
        self.assertEquals('r1', tree.get_revision_id())
 
370
        tree = self.get_as_tree('-1')
 
371
        self.assertEquals('r2', tree.get_revision_id())
 
372
        tree = self.get_as_tree('1.1.1')
 
373
        self.assertEquals('alt_r2', tree.get_revision_id())
250
374
 
251
375
 
252
376
class TestRevisionSpec_revid(TestRevisionSpec):
253
 
    
 
377
 
254
378
    def test_in_history(self):
255
379
        # We should be able to access revisions that are directly
256
380
        # in the history.
257
381
        self.assertInHistoryIs(1, 'r1', 'revid:r1')
258
382
        self.assertInHistoryIs(2, 'r2', 'revid:r2')
259
 
        
 
383
 
260
384
    def test_missing(self):
261
 
        self.assertInvalid('revid:r3')
 
385
        self.assertInvalid('revid:r3', invalid_as_revision_id=False)
262
386
 
263
387
    def test_merged(self):
264
388
        """We can reach revisions in the ancestry"""
267
391
    def test_not_here(self):
268
392
        self.tree2.commit('alt third', rev_id='alt_r3')
269
393
        # It exists in tree2, but not in tree
270
 
        self.assertInvalid('revid:alt_r3')
 
394
        self.assertInvalid('revid:alt_r3', invalid_as_revision_id=False)
271
395
 
272
396
    def test_in_repository(self):
273
397
        """We can get any revision id in the repository"""
274
398
        # XXX: This may change in the future, but for now, it is true
275
399
        self.tree2.commit('alt third', rev_id='alt_r3')
276
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
277
 
                                          revision_id='alt_r3')
 
400
        self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
278
401
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
279
402
 
280
403
    def test_unicode(self):
284
407
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
285
408
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
286
409
 
 
410
    def test_as_revision_id(self):
 
411
        self.assertAsRevisionId('r1', 'revid:r1')
 
412
        self.assertAsRevisionId('r2', 'revid:r2')
 
413
        self.assertAsRevisionId('alt_r2', 'revid:alt_r2')
 
414
 
287
415
 
288
416
class TestRevisionSpec_last(TestRevisionSpec):
289
417
 
290
418
    def test_positive(self):
291
419
        self.assertInHistoryIs(2, 'r2', 'last:1')
292
420
        self.assertInHistoryIs(1, 'r1', 'last:2')
293
 
        self.assertInHistoryIs(0, None, 'last:3')
 
421
        self.assertInHistoryIs(0, 'null:', 'last:3')
294
422
 
295
423
    def test_empty(self):
296
424
        self.assertInHistoryIs(2, 'r2', 'last:')
315
443
            pass
316
444
        self.assertInvalid('last:Y', extra='\n' + str(e))
317
445
 
 
446
    def test_as_revision_id(self):
 
447
        self.assertAsRevisionId('r2', 'last:1')
 
448
        self.assertAsRevisionId('r1', 'last:2')
 
449
 
318
450
 
319
451
class TestRevisionSpec_before(TestRevisionSpec):
320
452
 
323
455
        self.assertInHistoryIs(1, 'r1', 'before:-1')
324
456
 
325
457
    def test_before_one(self):
326
 
        self.assertInHistoryIs(0, None, 'before:1')
 
458
        self.assertInHistoryIs(0, 'null:', 'before:1')
327
459
 
328
460
    def test_before_none(self):
329
461
        self.assertInvalid('before:0',
342
474
    def test_alt_no_parents(self):
343
475
        new_tree = self.make_branch_and_tree('new_tree')
344
476
        new_tree.commit('first', rev_id='new_r1')
345
 
        self.tree.branch.repository.fetch(new_tree.branch.repository,
346
 
                                          revision_id='new_r1')
347
 
        self.assertInHistoryIs(0, None, 'before:revid:new_r1')
 
477
        self.tree.branch.fetch(new_tree.branch, 'new_r1')
 
478
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
 
479
 
 
480
    def test_as_revision_id(self):
 
481
        self.assertAsRevisionId('r1', 'before:revid:r2')
 
482
        self.assertAsRevisionId('r1', 'before:2')
 
483
        self.assertAsRevisionId('r1', 'before:1.1.1')
 
484
        self.assertAsRevisionId('r1', 'before:revid:alt_r2')
348
485
 
349
486
 
350
487
class TestRevisionSpec_tag(TestRevisionSpec):
351
 
    
 
488
 
352
489
    def make_branch_and_tree(self, relpath):
353
490
        # override format as the default one may not support tags
354
 
        control = bzrdir.BzrDir.create(relpath)
355
 
        control.create_repository()
356
 
        branch.BzrBranchExperimental.initialize(control)
357
 
        return control.create_workingtree()
 
491
        return TestRevisionSpec.make_branch_and_tree(
 
492
            self, relpath, format='dirstate-tags')
358
493
 
359
494
    def test_from_string_tag(self):
360
495
        spec = RevisionSpec.from_string('tag:bzr-0.14')
364
499
    def test_lookup_tag(self):
365
500
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
366
501
        self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
 
502
        self.tree.branch.tags.set_tag('null_rev', 'null:')
 
503
        self.assertInHistoryIs(0, 'null:', 'tag:null_rev')
367
504
 
368
505
    def test_failed_lookup(self):
369
506
        # tags that don't exist give a specific message: arguably we should
372
509
            self.get_in_history,
373
510
            'tag:some-random-tag')
374
511
 
 
512
    def test_as_revision_id(self):
 
513
        self.tree.branch.tags.set_tag('my-tag', 'r2')
 
514
        self.tree.branch.tags.set_tag('null_rev', 'null:')
 
515
        self.assertAsRevisionId('r2', 'tag:my-tag')
 
516
        self.assertAsRevisionId('null:', 'tag:null_rev')
 
517
        self.assertAsRevisionId('r1', 'before:tag:my-tag')
 
518
 
375
519
 
376
520
class TestRevisionSpec_date(TestRevisionSpec):
377
521
 
408
552
        self.assertInHistoryIs(2, 'new_r2',
409
553
            'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
410
554
 
 
555
    def test_as_revision_id(self):
 
556
        self.assertAsRevisionId('new_r2', 'date:today')
 
557
 
411
558
 
412
559
class TestRevisionSpec_ancestor(TestRevisionSpec):
413
 
    
 
560
 
414
561
    def test_non_exact_branch(self):
415
562
        # It seems better to require an exact path to the branch
416
563
        # Branch.open() rather than using Branch.open_containing()
446
593
        self.assertRaises(errors.NoCommits,
447
594
                          spec_in_history, 'ancestor:new_tree',
448
595
                                           self.tree.branch)
449
 
                        
 
596
 
450
597
        self.assertRaises(errors.NoCommits,
451
598
                          spec_in_history, 'ancestor:tree',
452
599
                                           new_tree.branch)
453
600
 
 
601
    def test_as_revision_id(self):
 
602
        self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
 
603
 
 
604
    def test_default(self):
 
605
        # We don't have a parent to default to
 
606
        self.assertRaises(errors.NotBranchError, self.get_in_history,
 
607
                          'ancestor:')
 
608
 
 
609
        # Create a branch with a parent to default to
 
610
        tree3 = self.tree.bzrdir.sprout('tree3').open_workingtree()
 
611
        tree3.commit('foo', rev_id='r3')
 
612
        self.tree = tree3
 
613
        self.assertInHistoryIs(2, 'r2', 'ancestor:')
 
614
 
454
615
 
455
616
class TestRevisionSpec_branch(TestRevisionSpec):
456
 
    
 
617
 
457
618
    def test_non_exact_branch(self):
458
619
        # It seems better to require an exact path to the branch
459
620
        # Branch.open() rather than using Branch.open_containing()
478
639
        # XXX: Right now, we use fetch() to make sure the remote revisions
479
640
        # have been pulled into the local branch. We may change that
480
641
        # behavior in the future.
481
 
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
 
642
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
482
643
 
483
644
    def test_no_commits(self):
484
645
        new_tree = self.make_branch_and_tree('new_tree')
485
646
        self.assertRaises(errors.NoCommits,
486
647
                          self.get_in_history, 'branch:new_tree')
 
648
        self.assertRaises(errors.NoCommits,
 
649
                          self.get_as_tree, 'branch:new_tree')
 
650
 
 
651
    def test_as_revision_id(self):
 
652
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
653
 
 
654
    def test_as_tree(self):
 
655
        tree = self.get_as_tree('branch:tree', self.tree2)
 
656
        self.assertEquals('r2', tree.get_revision_id())
 
657
        self.assertFalse(self.tree2.branch.repository.has_revision('r2'))
487
658
 
488
659
 
489
660
class TestRevisionSpec_submit(TestRevisionSpec):
500
671
        # submit branch overrides parent branch
501
672
        self.tree.branch.set_submit_branch('tree2')
502
673
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')
 
674
 
 
675
    def test_as_revision_id(self):
 
676
        self.tree.branch.set_submit_branch('tree2')
 
677
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
678
 
 
679
 
 
680
class TestRevisionSpec_mainline(TestRevisionSpec):
 
681
 
 
682
    def test_as_revision_id(self):
 
683
        self.assertAsRevisionId('r1', 'mainline:1')
 
684
        self.assertAsRevisionId('r2', 'mainline:1.1.1')
 
685
        self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
 
686
        spec = RevisionSpec.from_string('mainline:revid:alt_r22')
 
687
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
688
                              spec.as_revision_id, self.tree.branch)
 
689
        self.assertContainsRe(str(e),
 
690
            "Requested revision: 'mainline:revid:alt_r22' does not exist in"
 
691
            " branch: ")
 
692
 
 
693
    def test_in_history(self):
 
694
        self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
 
695
 
 
696
 
 
697
class TestRevisionSpec_annotate(TestRevisionSpec):
 
698
 
 
699
    def setUp(self):
 
700
        TestRevisionSpec.setUp(self)
 
701
        self.tree = self.make_branch_and_tree('annotate-tree')
 
702
        self.build_tree_contents([('annotate-tree/file1', '1\n')])
 
703
        self.tree.add('file1')
 
704
        self.tree.commit('r1', rev_id='r1')
 
705
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
 
706
        self.tree.commit('r2', rev_id='r2')
 
707
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
 
708
 
 
709
    def test_as_revision_id_r1(self):
 
710
        self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
 
711
 
 
712
    def test_as_revision_id_r2(self):
 
713
        self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
 
714
 
 
715
    def test_as_revision_id_uncommitted(self):
 
716
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
 
717
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
718
                              spec.as_revision_id, self.tree.branch)
 
719
        self.assertContainsRe(str(e),
 
720
            r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
 
721
            " exist in branch: .*\nLine 3 has not been committed.")
 
722
 
 
723
    def test_non_existent_line(self):
 
724
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
 
725
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
726
                              spec.as_revision_id, self.tree.branch)
 
727
        self.assertContainsRe(str(e),
 
728
            r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
 
729
            " exist in branch: .*\nNo such line: 4")
 
730
 
 
731
    def test_invalid_line(self):
 
732
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
 
733
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
734
                              spec.as_revision_id, self.tree.branch)
 
735
        self.assertContainsRe(str(e),
 
736
            r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
 
737
            " exist in branch: .*\nNo such line: q")
 
738
 
 
739
    def test_no_such_file(self):
 
740
        spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
 
741
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
742
                              spec.as_revision_id, self.tree.branch)
 
743
        self.assertContainsRe(str(e),
 
744
            r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
 
745
            " exist in branch: .*\nFile 'file2' is not versioned")
 
746
 
 
747
    def test_no_such_file_with_colon(self):
 
748
        spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
 
749
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
750
                              spec.as_revision_id, self.tree.branch)
 
751
        self.assertContainsRe(str(e),
 
752
            r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
 
753
            " exist in branch: .*\nFile 'fi:le2' is not versioned")