146
146
def test_object(self):
147
147
self.assertRaises(TypeError, RevisionSpec.from_string, object())
150
class TestRevisionSpec_dwim(TestRevisionSpec):
152
# Don't need to test revno's explicitly since TRS_revno already
153
# covers that well for us
154
def test_dwim_spec_revno(self):
155
self.assertInHistoryIs(2, 'r2', '2')
156
self.assertAsRevisionId('alt_r2', '1.1.1')
158
def test_dwim_spec_revid(self):
159
self.assertInHistoryIs(2, 'r2', 'r2')
161
def test_dwim_spec_tag(self):
162
self.tree.branch.tags.set_tag('footag', 'r1')
163
self.assertAsRevisionId('r1', 'footag')
164
self.tree.branch.tags.delete_tag('footag')
165
self.assertRaises(errors.InvalidRevisionSpec,
166
self.get_in_history, 'footag')
168
def test_dwim_spec_tag_that_looks_like_revno(self):
169
# Test that we slip past revno with things that look like revnos,
170
# but aren't. Tags are convenient for testing this since we can
171
# make them look however we want.
172
self.tree.branch.tags.set_tag('3', 'r2')
173
self.assertAsRevisionId('r2', '3')
174
self.build_tree(['tree/b'])
176
self.tree.commit('b', rev_id='r3')
177
self.assertAsRevisionId('r3', '3')
179
def test_dwim_spec_date(self):
180
self.assertAsRevisionId('r1', 'today')
182
def test_dwim_spec_branch(self):
183
self.assertInHistoryIs(None, 'alt_r2', 'tree2')
185
def test_dwim_spec_nonexistent(self):
186
self.assertInvalid('somethingrandom', invalid_as_revision_id=False)
187
self.assertInvalid('-1.1', invalid_as_revision_id=False)
188
self.assertInvalid('.1', invalid_as_revision_id=False)
189
self.assertInvalid('1..1', invalid_as_revision_id=False)
190
self.assertInvalid('1.2..1', invalid_as_revision_id=False)
191
self.assertInvalid('1.', invalid_as_revision_id=False)
149
def test_unregistered_spec(self):
150
self.assertRaises(errors.NoSuchRevisionSpec,
151
RevisionSpec.from_string, 'foo')
152
self.assertRaises(errors.NoSuchRevisionSpec,
153
RevisionSpec.from_string, '123a')
157
class TestRevnoFromString(TestCase):
159
def test_from_string_dotted_decimal(self):
160
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '-1.1')
161
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '.1')
162
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1..1')
163
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.2..1')
164
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.')
165
self.assertIsInstance(RevisionSpec.from_string('1.1'), RevisionSpec_revno)
166
self.assertIsInstance(RevisionSpec.from_string('1.1.3'), RevisionSpec_revno)
194
169
class TestRevisionSpec_revno(TestRevisionSpec):
652
627
def test_as_revision_id(self):
653
628
self.tree.branch.set_submit_branch('tree2')
654
629
self.assertAsRevisionId('alt_r2', 'branch:tree2')
657
class TestRevisionSpec_mainline(TestRevisionSpec):
659
def test_as_revision_id(self):
660
self.assertAsRevisionId('r1', 'mainline:1')
661
self.assertAsRevisionId('r2', 'mainline:1.1.1')
662
self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
663
spec = RevisionSpec.from_string('mainline:revid:alt_r22')
664
e = self.assertRaises(errors.InvalidRevisionSpec,
665
spec.as_revision_id, self.tree.branch)
666
self.assertContainsRe(str(e),
667
"Requested revision: 'mainline:revid:alt_r22' does not exist in"
670
def test_in_history(self):
671
self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
674
class TestRevisionSpec_annotate(TestRevisionSpec):
677
TestRevisionSpec.setUp(self)
678
self.tree = self.make_branch_and_tree('annotate-tree')
679
self.build_tree_contents([('annotate-tree/file1', '1\n')])
680
self.tree.add('file1')
681
self.tree.commit('r1', rev_id='r1')
682
self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
683
self.tree.commit('r2', rev_id='r2')
684
self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
686
def test_as_revision_id_r1(self):
687
self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
689
def test_as_revision_id_r2(self):
690
self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
692
def test_as_revision_id_uncommitted(self):
693
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
694
e = self.assertRaises(errors.InvalidRevisionSpec,
695
spec.as_revision_id, self.tree.branch)
696
self.assertContainsRe(str(e),
697
r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
698
" exist in branch: .*\nLine 3 has not been committed.")
700
def test_non_existent_line(self):
701
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
702
e = self.assertRaises(errors.InvalidRevisionSpec,
703
spec.as_revision_id, self.tree.branch)
704
self.assertContainsRe(str(e),
705
r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
706
" exist in branch: .*\nNo such line: 4")
708
def test_invalid_line(self):
709
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
710
e = self.assertRaises(errors.InvalidRevisionSpec,
711
spec.as_revision_id, self.tree.branch)
712
self.assertContainsRe(str(e),
713
r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
714
" exist in branch: .*\nNo such line: q")
716
def test_no_such_file(self):
717
spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
718
e = self.assertRaises(errors.InvalidRevisionSpec,
719
spec.as_revision_id, self.tree.branch)
720
self.assertContainsRe(str(e),
721
r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
722
" exist in branch: .*\nFile 'file2' is not versioned")
724
def test_no_such_file_with_colon(self):
725
spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
726
e = self.assertRaises(errors.InvalidRevisionSpec,
727
spec.as_revision_id, self.tree.branch)
728
self.assertContainsRe(str(e),
729
r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
730
" exist in branch: .*\nFile 'fi:le2' is not versioned")