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