146
146
def test_object(self):
147
147
self.assertRaises(TypeError, RevisionSpec.from_string, object())
150
class RevisionSpec_bork(RevisionSpec):
152
prefix = 'irrelevant:'
154
def _match_on(self, branch, revs):
155
if self.spec == "bork":
156
return RevisionInfo.from_revision_id(branch, "r1")
158
raise errors.InvalidRevisionSpec(self.spec, branch)
161
class TestRevisionSpec_dwim(TestRevisionSpec):
163
# Don't need to test revno's explicitly since TRS_revno already
164
# covers that well for us
165
def test_dwim_spec_revno(self):
166
self.assertInHistoryIs(2, 'r2', '2')
167
self.assertAsRevisionId('alt_r2', '1.1.1')
169
def test_dwim_spec_revid(self):
170
self.assertInHistoryIs(2, 'r2', 'r2')
172
def test_dwim_spec_tag(self):
173
self.tree.branch.tags.set_tag('footag', 'r1')
174
self.assertAsRevisionId('r1', 'footag')
175
self.tree.branch.tags.delete_tag('footag')
176
self.assertRaises(errors.InvalidRevisionSpec,
177
self.get_in_history, 'footag')
179
def test_dwim_spec_tag_that_looks_like_revno(self):
180
# Test that we slip past revno with things that look like revnos,
181
# but aren't. Tags are convenient for testing this since we can
182
# make them look however we want.
183
self.tree.branch.tags.set_tag('3', 'r2')
184
self.assertAsRevisionId('r2', '3')
185
self.build_tree(['tree/b'])
187
self.tree.commit('b', rev_id='r3')
188
self.assertAsRevisionId('r3', '3')
190
def test_dwim_spec_date(self):
191
self.assertAsRevisionId('r1', 'today')
193
def test_dwim_spec_branch(self):
194
self.assertInHistoryIs(None, 'alt_r2', 'tree2')
196
def test_dwim_spec_nonexistent(self):
197
self.assertInvalid('somethingrandom', invalid_as_revision_id=False)
198
self.assertInvalid('-1.1', invalid_as_revision_id=False)
199
self.assertInvalid('.1', invalid_as_revision_id=False)
200
self.assertInvalid('1..1', invalid_as_revision_id=False)
201
self.assertInvalid('1.2..1', invalid_as_revision_id=False)
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')
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)
222
169
class TestRevisionSpec_revno(TestRevisionSpec):
364
311
def test_as_tree(self):
365
312
tree = self.get_as_tree('0')
366
self.assertEqual(_mod_revision.NULL_REVISION, tree.get_revision_id())
313
self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
367
314
tree = self.get_as_tree('1')
368
self.assertEqual('r1', tree.get_revision_id())
315
self.assertEquals('r1', tree.get_revision_id())
369
316
tree = self.get_as_tree('2')
370
self.assertEqual('r2', tree.get_revision_id())
317
self.assertEquals('r2', tree.get_revision_id())
371
318
tree = self.get_as_tree('-2')
372
self.assertEqual('r1', tree.get_revision_id())
319
self.assertEquals('r1', tree.get_revision_id())
373
320
tree = self.get_as_tree('-1')
374
self.assertEqual('r2', tree.get_revision_id())
321
self.assertEquals('r2', tree.get_revision_id())
375
322
tree = self.get_as_tree('1.1.1')
376
self.assertEqual('alt_r2', tree.get_revision_id())
323
self.assertEquals('alt_r2', tree.get_revision_id())
379
326
class TestRevisionSpec_revid(TestRevisionSpec):
678
627
def test_as_revision_id(self):
679
628
self.tree.branch.set_submit_branch('tree2')
680
629
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")