37
37
return RevisionSpec.from_string(spec).in_history(branch)
40
def spec_in_branch(spec, branch, *args, **kwargs):
41
"""A simple helper to change a revision spec into a branch search"""
42
return RevisionSpec.from_string(spec).in_branch(branch, *args, **kwargs)
40
45
# Basic class, which just creates a really basic set of revisions
41
46
class TestRevisionSpec(TestCaseWithTransport):
50
55
self.tree = self.make_branch_and_tree('tree')
51
56
self.build_tree(['tree/a'])
53
self.tree.commit('a', rev_id='r1')
55
self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
56
self.tree2.commit('alt', rev_id='alt_r2')
58
self.tree.branch.repository.fetch(self.tree2.branch.repository,
60
self.tree.set_pending_merges(['alt_r2'])
61
self.tree.commit('second', rev_id='r2')
57
self.tree.lock_write()
60
self.tree.commit('a', rev_id='r1')
62
self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
63
self.tree2.commit('alt', rev_id='alt_r2')
65
self.tree.merge_from_branch(self.tree2.branch)
66
self.tree.commit('second', rev_id='r2')
63
70
def get_in_history(self, revision_spec):
64
71
return spec_in_history(revision_spec, self.tree.branch)
73
def get_in_branch(self, revision_spec, *args, **kwargs):
74
return spec_in_branch(revision_spec, self.tree.branch, *args, **kwargs)
66
76
def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
67
77
rev_info = self.get_in_history(revision_spec)
68
78
self.assertEqual(exp_revno, rev_info.revno,
83
93
self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
94
% (revision_spec,))
96
def assertInBranchSupportsNeedRevno(self, revision_spec,
97
has_simple_revno=True):
98
"""Assert that the in_branch() helper supports need_revno
100
If need_revno=False, then the RevisionInfo can have None for revno.
101
But if it has a real number, then it should be the same as when
102
need_revno=True is passed.
104
:param revision_spec: The revision spec to test.
105
:param has_simple_revno: If true, then 'need_revno=True' must set the
106
.revno property to something other than None.
108
info_true = self.get_in_branch(revision_spec, need_revno=True)
110
self.assertIsNot(None, info_true.revno)
112
self.assertIs(None, info_true.revno)
113
info_false = self.get_in_branch(revision_spec, need_revno=False)
114
if info_false.revno is not None:
115
self.assertEqual(info_true.revno, info_false.revno)
87
118
class TestOddRevisionSpec(TestRevisionSpec):
88
119
"""Test things that aren't normally thought of as revision specs"""
246
277
self.assertEqual((2, 'b@r-0-2'),
247
278
spec_in_history('revno:2:b/', None))
280
def test_supports_need_revno(self):
281
self.assertInBranchSupportsNeedRevno('1')
282
self.assertInBranchSupportsNeedRevno('2')
283
self.assertInBranchSupportsNeedRevno('1.1.1',
284
has_simple_revno=False)
251
287
class TestRevisionSpec_revid(TestRevisionSpec):
283
319
self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
284
320
self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
322
def test_supports_need_revno(self):
323
self.assertInBranchSupportsNeedRevno('revid:r1')
324
self.assertInBranchSupportsNeedRevno('revid:r2')
325
self.assertInBranchSupportsNeedRevno('revid:alt_r2',
326
has_simple_revno=False)
287
329
class TestRevisionSpec_last(TestRevisionSpec):
315
357
self.assertInvalid('last:Y', extra='\n' + str(e))
359
def test_supports_need_revno(self):
360
self.assertInBranchSupportsNeedRevno('last:1')
318
363
class TestRevisionSpec_before(TestRevisionSpec):
345
390
revision_id='new_r1')
346
391
self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
393
def test_supports_need_revno(self):
394
self.assertInBranchSupportsNeedRevno('before:2')
395
self.assertInBranchSupportsNeedRevno('before:revid:r2')
349
398
class TestRevisionSpec_tag(TestRevisionSpec):
369
418
self.get_in_history,
370
419
'tag:some-random-tag')
421
def test_supports_need_revno(self):
422
self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
423
self.assertInBranchSupportsNeedRevno('tag:bzr-0.14')
373
426
class TestRevisionSpec_date(TestRevisionSpec):
405
458
self.assertInHistoryIs(2, 'new_r2',
406
459
'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
461
def test_supports_need_revno(self):
462
self.assertInBranchSupportsNeedRevno('date:today')
409
465
class TestRevisionSpec_ancestor(TestRevisionSpec):
448
504
spec_in_history, 'ancestor:tree',
507
def test_supports_need_revno(self):
508
self.assertInBranchSupportsNeedRevno('ancestor:tree2',
509
has_simple_revno=False)
452
512
class TestRevisionSpec_branch(TestRevisionSpec):
482
542
self.assertRaises(errors.NoCommits,
483
543
self.get_in_history, 'branch:new_tree')
545
def test_supports_need_revno(self):
546
self.assertInBranchSupportsNeedRevno('branch:tree2',
547
has_simple_revno=False)
486
550
class TestRevisionSpec_submit(TestRevisionSpec):
497
561
# submit branch overrides parent branch
498
562
self.tree.branch.set_submit_branch('tree2')
499
563
self.assertInHistoryIs(None, 'alt_r2', 'submit:')
565
def test_supports_need_revno(self):
566
self.tree.branch.set_submit_branch('tree2')
567
self.assertInBranchSupportsNeedRevno('submit:',
568
has_simple_revno=False)