146
139
def test_object(self):
147
140
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)
142
def test_unregistered_spec(self):
143
self.assertRaises(errors.NoSuchRevisionSpec,
144
RevisionSpec.from_string, 'foo')
145
self.assertRaises(errors.NoSuchRevisionSpec,
146
RevisionSpec.from_string, '123a')
150
class TestRevnoFromString(TestCase):
152
def test_from_string_dotted_decimal(self):
153
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '-1.1')
154
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '.1')
155
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1..1')
156
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.2..1')
157
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.')
158
self.assertIsInstance(RevisionSpec.from_string('1.1'), RevisionSpec_revno)
159
self.assertIsInstance(RevisionSpec.from_string('1.1.3'), RevisionSpec_revno)
194
162
class TestRevisionSpec_revno(TestRevisionSpec):
333
300
self.assertAsRevisionId('r2', '-1')
334
301
self.assertAsRevisionId('alt_r2', '1.1.1')
336
def test_as_tree(self):
337
tree = self.get_as_tree('0')
338
self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
339
tree = self.get_as_tree('1')
340
self.assertEquals('r1', tree.get_revision_id())
341
tree = self.get_as_tree('2')
342
self.assertEquals('r2', tree.get_revision_id())
343
tree = self.get_as_tree('-2')
344
self.assertEquals('r1', tree.get_revision_id())
345
tree = self.get_as_tree('-1')
346
self.assertEquals('r2', tree.get_revision_id())
347
tree = self.get_as_tree('1.1.1')
348
self.assertEquals('alt_r2', tree.get_revision_id())
351
304
class TestRevisionSpec_revid(TestRevisionSpec):
353
306
def test_in_history(self):
354
307
# We should be able to access revisions that are directly
355
308
# in the history.
356
309
self.assertInHistoryIs(1, 'r1', 'revid:r1')
357
310
self.assertInHistoryIs(2, 'r2', 'revid:r2')
359
312
def test_missing(self):
360
313
self.assertInvalid('revid:r3', invalid_as_revision_id=False)
578
531
def test_as_revision_id(self):
579
532
self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
581
def test_default(self):
582
# We don't have a parent to default to
583
self.assertRaises(errors.NotBranchError, self.get_in_history,
586
# Create a branch with a parent to default to
587
tree3 = self.tree.bzrdir.sprout('tree3').open_workingtree()
588
tree3.commit('foo', rev_id='r3')
590
self.assertInHistoryIs(2, 'r2', 'ancestor:')
593
535
class TestRevisionSpec_branch(TestRevisionSpec):
595
537
def test_non_exact_branch(self):
596
538
# It seems better to require an exact path to the branch
597
539
# Branch.open() rather than using Branch.open_containing()
622
564
new_tree = self.make_branch_and_tree('new_tree')
623
565
self.assertRaises(errors.NoCommits,
624
566
self.get_in_history, 'branch:new_tree')
625
self.assertRaises(errors.NoCommits,
626
self.get_as_tree, 'branch:new_tree')
628
568
def test_as_revision_id(self):
629
569
self.assertAsRevisionId('alt_r2', 'branch:tree2')
631
def test_as_tree(self):
632
tree = self.get_as_tree('branch:tree', self.tree2)
633
self.assertEquals('r2', tree.get_revision_id())
634
self.assertFalse(self.tree2.branch.repository.has_revision('r2'))
637
572
class TestRevisionSpec_submit(TestRevisionSpec):