51
50
self.tree = self.make_branch_and_tree('tree')
52
51
self.build_tree(['tree/a'])
52
self.tree.lock_write()
53
self.addCleanup(self.tree.unlock)
53
54
self.tree.add(['a'])
54
55
self.tree.commit('a', rev_id='r1')
56
57
self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
57
58
self.tree2.commit('alt', rev_id='alt_r2')
59
self.tree.branch.repository.fetch(self.tree2.branch.repository,
61
self.tree.set_pending_merges(['alt_r2'])
60
self.tree.merge_from_branch(self.tree2.branch)
62
61
self.tree.commit('second', rev_id='r2')
64
63
def get_in_history(self, revision_spec):
84
83
self.fail('Expected InvalidRevisionSpec to be raised for %s'
85
84
% (revision_spec,))
86
def assertAsRevisionId(self, revision_id, revision_spec):
87
"""Calling as_revision_id() should return the specified id."""
88
spec = RevisionSpec.from_string(revision_spec)
89
self.assertEqual(revision_id,
90
spec.as_revision_id(self.tree.branch))
88
93
class TestOddRevisionSpec(TestRevisionSpec):
89
94
"""Test things that aren't normally thought of as revision specs"""
91
96
def test_none(self):
92
self.assertInHistoryIs(0, None, None)
97
self.assertInHistoryIs(None, None, None)
94
99
def test_object(self):
95
100
self.assertRaises(TypeError, RevisionSpec.from_string, object())
117
122
class TestRevisionSpec_revno(TestRevisionSpec):
119
124
def test_positive_int(self):
120
self.assertInHistoryIs(0, None, '0')
125
self.assertInHistoryIs(0, 'null:', '0')
121
126
self.assertInHistoryIs(1, 'r1', '1')
122
127
self.assertInHistoryIs(2, 'r2', '2')
123
128
self.assertInvalid('3')
134
139
self.assertInHistoryIs(1, 'r1', '-100')
136
141
def test_positive(self):
137
self.assertInHistoryIs(0, None, 'revno:0')
142
self.assertInHistoryIs(0, 'null:', 'revno:0')
138
143
self.assertInHistoryIs(1, 'r1', 'revno:1')
139
144
self.assertInHistoryIs(2, 'r2', 'revno:2')
247
252
self.assertEqual((2, 'b@r-0-2'),
248
253
spec_in_history('revno:2:b/', None))
255
def test_as_revision_id(self):
256
self.assertAsRevisionId('null:', '0')
257
self.assertAsRevisionId('r1', '1')
258
self.assertAsRevisionId('r2', '2')
259
self.assertAsRevisionId('r1', '-2')
260
self.assertAsRevisionId('r2', '-1')
261
self.assertAsRevisionId('alt_r2', '1.1.1')
252
264
class TestRevisionSpec_revid(TestRevisionSpec):
284
296
self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
285
297
self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
299
def test_as_revision_id(self):
300
self.assertAsRevisionId('r1', 'revid:r1')
301
self.assertAsRevisionId('r2', 'revid:r2')
302
self.assertAsRevisionId('alt_r2', 'revid:alt_r2')
288
305
class TestRevisionSpec_last(TestRevisionSpec):
290
307
def test_positive(self):
291
308
self.assertInHistoryIs(2, 'r2', 'last:1')
292
309
self.assertInHistoryIs(1, 'r1', 'last:2')
293
self.assertInHistoryIs(0, None, 'last:3')
310
self.assertInHistoryIs(0, 'null:', 'last:3')
295
312
def test_empty(self):
296
313
self.assertInHistoryIs(2, 'r2', 'last:')
316
333
self.assertInvalid('last:Y', extra='\n' + str(e))
335
def test_as_revision_id(self):
336
self.assertAsRevisionId('r2', 'last:1')
337
self.assertAsRevisionId('r1', 'last:2')
319
340
class TestRevisionSpec_before(TestRevisionSpec):
323
344
self.assertInHistoryIs(1, 'r1', 'before:-1')
325
346
def test_before_one(self):
326
self.assertInHistoryIs(0, None, 'before:1')
347
self.assertInHistoryIs(0, 'null:', 'before:1')
328
349
def test_before_none(self):
329
350
self.assertInvalid('before:0',
344
365
new_tree.commit('first', rev_id='new_r1')
345
366
self.tree.branch.repository.fetch(new_tree.branch.repository,
346
367
revision_id='new_r1')
347
self.assertInHistoryIs(0, None, 'before:revid:new_r1')
368
self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
370
def test_as_revision_id(self):
371
self.assertAsRevisionId('r1', 'before:revid:r2')
372
self.assertAsRevisionId('r1', 'before:2')
373
self.assertAsRevisionId('r1', 'before:1.1.1')
374
self.assertAsRevisionId('r1', 'before:revid:alt_r2')
350
377
class TestRevisionSpec_tag(TestRevisionSpec):
352
379
def make_branch_and_tree(self, relpath):
353
380
# override format as the default one may not support tags
354
control = bzrdir.BzrDir.create(relpath)
355
control.create_repository()
356
branch.BzrBranchExperimental.initialize(control)
357
return control.create_workingtree()
381
return TestRevisionSpec.make_branch_and_tree(
382
self, relpath, format='dirstate-tags')
359
384
def test_from_string_tag(self):
360
385
spec = RevisionSpec.from_string('tag:bzr-0.14')
364
389
def test_lookup_tag(self):
365
390
self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
366
391
self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
392
self.tree.branch.tags.set_tag('null_rev', 'null:')
393
self.assertInHistoryIs(0, 'null:', 'tag:null_rev')
368
395
def test_failed_lookup(self):
369
396
# tags that don't exist give a specific message: arguably we should
372
399
self.get_in_history,
373
400
'tag:some-random-tag')
402
def test_as_revision_id(self):
403
self.tree.branch.tags.set_tag('my-tag', 'r2')
404
self.tree.branch.tags.set_tag('null_rev', 'null:')
405
self.assertAsRevisionId('r2', 'tag:my-tag')
406
self.assertAsRevisionId('null:', 'tag:null_rev')
407
self.assertAsRevisionId('r1', 'before:tag:my-tag')
376
410
class TestRevisionSpec_date(TestRevisionSpec):
408
442
self.assertInHistoryIs(2, 'new_r2',
409
443
'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
445
def test_as_revision_id(self):
446
self.assertAsRevisionId('new_r2', 'date:today')
412
449
class TestRevisionSpec_ancestor(TestRevisionSpec):
451
488
spec_in_history, 'ancestor:tree',
491
def test_as_revision_id(self):
492
self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
455
495
class TestRevisionSpec_branch(TestRevisionSpec):
485
525
self.assertRaises(errors.NoCommits,
486
526
self.get_in_history, 'branch:new_tree')
528
def test_as_revision_id(self):
529
self.assertAsRevisionId('alt_r2', 'branch:tree2')
489
532
class TestRevisionSpec_submit(TestRevisionSpec):
500
543
# submit branch overrides parent branch
501
544
self.tree.branch.set_submit_branch('tree2')
502
545
self.assertInHistoryIs(None, 'alt_r2', 'submit:')
547
def test_as_revision_id(self):
548
self.tree.branch.set_submit_branch('tree2')
549
self.assertAsRevisionId('alt_r2', 'branch:tree2')