74
75
% (revision_spec, exp_revision_id, rev_info.rev_id))
76
def assertInvalid(self, revision_spec, extra=''):
77
def assertInvalid(self, revision_spec, extra='',
78
invalid_as_revision_id=True):
78
80
self.get_in_history(revision_spec)
79
81
except errors.InvalidRevisionSpec, e:
80
82
self.assertEqual(revision_spec, e.spec)
81
83
self.assertEqual(extra, e.extra)
83
self.fail('Expected InvalidRevisionSpec to be raised for %s'
85
self.fail('Expected InvalidRevisionSpec to be raised for'
86
' %r.in_history' % (revision_spec,))
87
if invalid_as_revision_id:
89
spec = RevisionSpec.from_string(revision_spec)
90
spec.as_revision_id(self.tree.branch)
91
except errors.InvalidRevisionSpec, e:
92
self.assertEqual(revision_spec, e.spec)
93
self.assertEqual(extra, e.extra)
95
self.fail('Expected InvalidRevisionSpec to be raised for'
96
' %r.as_revision_id' % (revision_spec,))
86
98
def assertAsRevisionId(self, revision_id, revision_spec):
87
99
"""Calling as_revision_id() should return the specified id."""
89
101
self.assertEqual(revision_id,
90
102
spec.as_revision_id(self.tree.branch))
104
def get_as_tree(self, revision_spec, tree=None):
107
spec = RevisionSpec.from_string(revision_spec)
108
return spec.as_tree(tree.branch)
93
111
class RevisionSpecMatchOnTrap(RevisionSpec):
159
177
def test_dotted_decimal(self):
160
178
self.assertInHistoryIs(None, 'alt_r2', '1.1.1')
179
self.assertInvalid('1.1.123')
162
181
def test_negative_int(self):
163
182
self.assertInHistoryIs(2, 'r2', '-1')
257
276
"""Old revno:N:path tests"""
258
277
wta = self.make_branch_and_tree('a')
261
280
wta.commit('Commit one', rev_id='a@r-0-1')
262
281
wta.commit('Commit two', rev_id='a@r-0-2')
263
282
wta.commit('Commit three', rev_id='a@r-0-3')
289
308
self.assertAsRevisionId('r2', '-1')
290
309
self.assertAsRevisionId('alt_r2', '1.1.1')
311
def test_as_tree(self):
312
tree = self.get_as_tree('0')
313
self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
314
tree = self.get_as_tree('1')
315
self.assertEquals('r1', tree.get_revision_id())
316
tree = self.get_as_tree('2')
317
self.assertEquals('r2', tree.get_revision_id())
318
tree = self.get_as_tree('-2')
319
self.assertEquals('r1', tree.get_revision_id())
320
tree = self.get_as_tree('-1')
321
self.assertEquals('r2', tree.get_revision_id())
322
tree = self.get_as_tree('1.1.1')
323
self.assertEquals('alt_r2', tree.get_revision_id())
293
326
class TestRevisionSpec_revid(TestRevisionSpec):
295
328
def test_in_history(self):
296
329
# We should be able to access revisions that are directly
297
330
# in the history.
298
331
self.assertInHistoryIs(1, 'r1', 'revid:r1')
299
332
self.assertInHistoryIs(2, 'r2', 'revid:r2')
301
334
def test_missing(self):
302
self.assertInvalid('revid:r3')
335
self.assertInvalid('revid:r3', invalid_as_revision_id=False)
304
337
def test_merged(self):
305
338
"""We can reach revisions in the ancestry"""
308
341
def test_not_here(self):
309
342
self.tree2.commit('alt third', rev_id='alt_r3')
310
343
# It exists in tree2, but not in tree
311
self.assertInvalid('revid:alt_r3')
344
self.assertInvalid('revid:alt_r3', invalid_as_revision_id=False)
313
346
def test_in_repository(self):
314
347
"""We can get any revision id in the repository"""
406
439
class TestRevisionSpec_tag(TestRevisionSpec):
408
441
def make_branch_and_tree(self, relpath):
409
442
# override format as the default one may not support tags
410
443
return TestRevisionSpec.make_branch_and_tree(
512
545
self.assertRaises(errors.NoCommits,
513
546
spec_in_history, 'ancestor:new_tree',
514
547
self.tree.branch)
516
549
self.assertRaises(errors.NoCommits,
517
550
spec_in_history, 'ancestor:tree',
520
553
def test_as_revision_id(self):
521
554
self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
556
def test_default(self):
557
# We don't have a parent to default to
558
self.assertRaises(errors.NotBranchError, self.get_in_history,
561
# Create a branch with a parent to default to
562
tree3 = self.tree.bzrdir.sprout('tree3').open_workingtree()
563
tree3.commit('foo', rev_id='r3')
565
self.assertInHistoryIs(2, 'r2', 'ancestor:')
524
568
class TestRevisionSpec_branch(TestRevisionSpec):
526
570
def test_non_exact_branch(self):
527
571
# It seems better to require an exact path to the branch
528
572
# Branch.open() rather than using Branch.open_containing()
553
597
new_tree = self.make_branch_and_tree('new_tree')
554
598
self.assertRaises(errors.NoCommits,
555
599
self.get_in_history, 'branch:new_tree')
600
self.assertRaises(errors.NoCommits,
601
self.get_as_tree, 'branch:new_tree')
557
603
def test_as_revision_id(self):
558
604
self.assertAsRevisionId('alt_r2', 'branch:tree2')
606
def test_as_tree(self):
607
tree = self.get_as_tree('branch:tree', self.tree2)
608
self.assertEquals('r2', tree.get_revision_id())
609
self.assertFalse(self.tree2.branch.repository.has_revision('r2'))
561
612
class TestRevisionSpec_submit(TestRevisionSpec):