121
119
# If wants_revision_history = True, then _match_on should get the
122
120
# branch revision history
123
121
spec = RevisionSpecMatchOnTrap('foo', _internal=True)
124
spec.in_history(self.tree.branch)
122
spec.wants_revision_history = True
123
self.callDeprecated(['RevisionSpec.wants_revision_history was '
124
'deprecated in 2.5 (RevisionSpecMatchOnTrap).'],
125
spec.in_history, self.tree.branch)
126
127
self.assertEqual((self.tree.branch, ['r1' ,'r2']),
190
201
self.assertInvalid('1.2..1', invalid_as_revision_id=False)
191
202
self.assertInvalid('1.', invalid_as_revision_id=False)
204
def test_append_dwim_revspec(self):
205
original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
206
def reset_dwim_revspecs():
207
RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
208
self.addCleanup(reset_dwim_revspecs)
209
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_bork)
210
self.assertAsRevisionId('r1', 'bork')
212
def test_append_lazy_dwim_revspec(self):
213
original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
214
def reset_dwim_revspecs():
215
RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
216
self.addCleanup(reset_dwim_revspecs)
217
RevisionSpec_dwim.append_possible_lazy_revspec(
218
"bzrlib.tests.test_revisionspec", "RevisionSpec_bork")
219
self.assertAsRevisionId('r1', 'bork')
194
222
class TestRevisionSpec_revno(TestRevisionSpec):
336
364
def test_as_tree(self):
337
365
tree = self.get_as_tree('0')
338
self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
366
self.assertEqual(_mod_revision.NULL_REVISION, tree.get_revision_id())
339
367
tree = self.get_as_tree('1')
340
self.assertEquals('r1', tree.get_revision_id())
368
self.assertEqual('r1', tree.get_revision_id())
341
369
tree = self.get_as_tree('2')
342
self.assertEquals('r2', tree.get_revision_id())
370
self.assertEqual('r2', tree.get_revision_id())
343
371
tree = self.get_as_tree('-2')
344
self.assertEquals('r1', tree.get_revision_id())
372
self.assertEqual('r1', tree.get_revision_id())
345
373
tree = self.get_as_tree('-1')
346
self.assertEquals('r2', tree.get_revision_id())
374
self.assertEqual('r2', tree.get_revision_id())
347
375
tree = self.get_as_tree('1.1.1')
348
self.assertEquals('alt_r2', tree.get_revision_id())
376
self.assertEqual('alt_r2', tree.get_revision_id())
351
379
class TestRevisionSpec_revid(TestRevisionSpec):
652
678
def test_as_revision_id(self):
653
679
self.tree.branch.set_submit_branch('tree2')
654
680
self.assertAsRevisionId('alt_r2', 'branch:tree2')
683
class TestRevisionSpec_mainline(TestRevisionSpec):
685
def test_as_revision_id(self):
686
self.assertAsRevisionId('r1', 'mainline:1')
687
self.assertAsRevisionId('r2', 'mainline:1.1.1')
688
self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
689
spec = RevisionSpec.from_string('mainline:revid:alt_r22')
690
e = self.assertRaises(errors.InvalidRevisionSpec,
691
spec.as_revision_id, self.tree.branch)
692
self.assertContainsRe(str(e),
693
"Requested revision: 'mainline:revid:alt_r22' does not exist in"
696
def test_in_history(self):
697
self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
700
class TestRevisionSpec_annotate(TestRevisionSpec):
703
super(TestRevisionSpec_annotate, self).setUp()
704
self.tree = self.make_branch_and_tree('annotate-tree')
705
self.build_tree_contents([('annotate-tree/file1', '1\n')])
706
self.tree.add('file1')
707
self.tree.commit('r1', rev_id='r1')
708
self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
709
self.tree.commit('r2', rev_id='r2')
710
self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
712
def test_as_revision_id_r1(self):
713
self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
715
def test_as_revision_id_r2(self):
716
self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
718
def test_as_revision_id_uncommitted(self):
719
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
720
e = self.assertRaises(errors.InvalidRevisionSpec,
721
spec.as_revision_id, self.tree.branch)
722
self.assertContainsRe(str(e),
723
r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
724
" exist in branch: .*\nLine 3 has not been committed.")
726
def test_non_existent_line(self):
727
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
728
e = self.assertRaises(errors.InvalidRevisionSpec,
729
spec.as_revision_id, self.tree.branch)
730
self.assertContainsRe(str(e),
731
r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
732
" exist in branch: .*\nNo such line: 4")
734
def test_invalid_line(self):
735
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
736
e = self.assertRaises(errors.InvalidRevisionSpec,
737
spec.as_revision_id, self.tree.branch)
738
self.assertContainsRe(str(e),
739
r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
740
" exist in branch: .*\nNo such line: q")
742
def test_no_such_file(self):
743
spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
744
e = self.assertRaises(errors.InvalidRevisionSpec,
745
spec.as_revision_id, self.tree.branch)
746
self.assertContainsRe(str(e),
747
r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
748
" exist in branch: .*\nFile 'file2' is not versioned")
750
def test_no_such_file_with_colon(self):
751
spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
752
e = self.assertRaises(errors.InvalidRevisionSpec,
753
spec.as_revision_id, self.tree.branch)
754
self.assertContainsRe(str(e),
755
r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
756
" exist in branch: .*\nFile 'fi:le2' is not versioned")