53
50
self.tree.lock_write()
54
51
self.addCleanup(self.tree.unlock)
55
52
self.tree.add(['a'])
56
self.tree.commit('a', rev_id='r1')
53
self.tree.commit('a', rev_id=b'r1')
58
self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
59
self.tree2.commit('alt', rev_id='alt_r2')
55
self.tree2 = self.tree.controldir.sprout('tree2').open_workingtree()
56
self.tree2.commit('alt', rev_id=b'alt_r2')
61
58
self.tree.merge_from_branch(self.tree2.branch)
62
self.tree.commit('second', rev_id='r2')
59
self.tree.commit('second', rev_id=b'r2')
64
61
def get_in_history(self, revision_spec):
65
62
return spec_in_history(revision_spec, self.tree.branch)
118
115
class TestRevisionSpecBase(TestRevisionSpec):
120
def test_wants_revision_history(self):
121
# If wants_revision_history = True, then _match_on should get the
122
# branch revision history
123
spec = RevisionSpecMatchOnTrap('foo', _internal=True)
124
spec.in_history(self.tree.branch)
126
self.assertEqual((self.tree.branch, ['r1' ,'r2']),
129
117
def test_wants_no_revision_history(self):
130
118
# If wants_revision_history = False, then _match_on should get None for
131
119
# the branch revision history
132
120
spec = RevisionSpecMatchOnTrap('foo', _internal=True)
133
spec.wants_revision_history = False
134
121
spec.in_history(self.tree.branch)
136
123
self.assertEqual((self.tree.branch, None), spec.last_call)
190
188
self.assertInvalid('1.2..1', invalid_as_revision_id=False)
191
189
self.assertInvalid('1.', invalid_as_revision_id=False)
191
def test_append_dwim_revspec(self):
192
original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
193
def reset_dwim_revspecs():
194
RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
195
self.addCleanup(reset_dwim_revspecs)
196
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_bork)
197
self.assertAsRevisionId('r1', 'bork')
199
def test_append_lazy_dwim_revspec(self):
200
original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
201
def reset_dwim_revspecs():
202
RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
203
self.addCleanup(reset_dwim_revspecs)
204
RevisionSpec_dwim.append_possible_lazy_revspec(
205
"breezy.tests.test_revisionspec", "RevisionSpec_bork")
206
self.assertAsRevisionId('r1', 'bork')
194
209
class TestRevisionSpec_revno(TestRevisionSpec):
302
317
wta = self.make_branch_and_tree('a')
305
wta.commit('Commit one', rev_id='a@r-0-1')
306
wta.commit('Commit two', rev_id='a@r-0-2')
307
wta.commit('Commit three', rev_id='a@r-0-3')
320
wta.commit('Commit one', rev_id=b'a@r-0-1')
321
wta.commit('Commit two', rev_id=b'a@r-0-2')
322
wta.commit('Commit three', rev_id=b'a@r-0-3')
309
324
wtb = self.make_branch_and_tree('b')
312
wtb.commit('Commit one', rev_id='b@r-0-1')
313
wtb.commit('Commit two', rev_id='b@r-0-2')
314
wtb.commit('Commit three', rev_id='b@r-0-3')
327
wtb.commit('Commit one', rev_id=b'b@r-0-1')
328
wtb.commit('Commit two', rev_id=b'b@r-0-2')
329
wtb.commit('Commit three', rev_id=b'b@r-0-3')
317
332
self.assertEqual((1, 'a@r-0-1'),
336
351
def test_as_tree(self):
337
352
tree = self.get_as_tree('0')
338
self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
353
self.assertEqual(_mod_revision.NULL_REVISION, tree.get_revision_id())
339
354
tree = self.get_as_tree('1')
340
self.assertEquals('r1', tree.get_revision_id())
355
self.assertEqual('r1', tree.get_revision_id())
341
356
tree = self.get_as_tree('2')
342
self.assertEquals('r2', tree.get_revision_id())
357
self.assertEqual('r2', tree.get_revision_id())
343
358
tree = self.get_as_tree('-2')
344
self.assertEquals('r1', tree.get_revision_id())
359
self.assertEqual('r1', tree.get_revision_id())
345
360
tree = self.get_as_tree('-1')
346
self.assertEquals('r2', tree.get_revision_id())
361
self.assertEqual('r2', tree.get_revision_id())
347
362
tree = self.get_as_tree('1.1.1')
348
self.assertEquals('alt_r2', tree.get_revision_id())
363
self.assertEqual('alt_r2', tree.get_revision_id())
351
366
class TestRevisionSpec_revid(TestRevisionSpec):
364
379
self.assertInHistoryIs(None, 'alt_r2', 'revid:alt_r2')
366
381
def test_not_here(self):
367
self.tree2.commit('alt third', rev_id='alt_r3')
382
self.tree2.commit('alt third', rev_id=b'alt_r3')
368
383
# It exists in tree2, but not in tree
369
384
self.assertInvalid('revid:alt_r3', invalid_as_revision_id=False)
371
386
def test_in_repository(self):
372
387
"""We can get any revision id in the repository"""
373
388
# XXX: This may change in the future, but for now, it is true
374
self.tree2.commit('alt third', rev_id='alt_r3')
375
self.tree.branch.repository.fetch(self.tree2.branch.repository,
376
revision_id='alt_r3')
389
self.tree2.commit('alt third', rev_id=b'alt_r3')
390
self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
377
391
self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
379
393
def test_unicode(self):
500
513
super(TestRevisionSpec, self).setUp()
502
515
new_tree = self.make_branch_and_tree('new_tree')
503
new_tree.commit('Commit one', rev_id='new_r1',
516
new_tree.commit('Commit one', rev_id=b'new_r1',
504
517
timestamp=time.time() - 60*60*24)
505
new_tree.commit('Commit two', rev_id='new_r2')
506
new_tree.commit('Commit three', rev_id='new_r3')
518
new_tree.commit('Commit two', rev_id=b'new_r2')
519
new_tree.commit('Commit three', rev_id=b'new_r3')
508
521
self.tree = new_tree
557
570
def test_unrelated(self):
558
571
new_tree = self.make_branch_and_tree('new_tree')
560
new_tree.commit('Commit one', rev_id='new_r1')
561
new_tree.commit('Commit two', rev_id='new_r2')
562
new_tree.commit('Commit three', rev_id='new_r3')
573
new_tree.commit('Commit one', rev_id=b'new_r1')
574
new_tree.commit('Commit two', rev_id=b'new_r2')
575
new_tree.commit('Commit three', rev_id=b'new_r3')
564
577
# With no common ancestor, we should raise another user error
565
578
self.assertRaises(errors.NoCommonAncestor,
607
620
def test_unrelated(self):
608
621
new_tree = self.make_branch_and_tree('new_tree')
610
new_tree.commit('Commit one', rev_id='new_r1')
611
new_tree.commit('Commit two', rev_id='new_r2')
612
new_tree.commit('Commit three', rev_id='new_r3')
623
new_tree.commit('Commit one', rev_id=b'new_r1')
624
new_tree.commit('Commit two', rev_id=b'new_r2')
625
new_tree.commit('Commit three', rev_id=b'new_r3')
614
627
self.assertInHistoryIs(None, 'new_r3', 'branch:new_tree')
616
629
# XXX: Right now, we use fetch() to make sure the remote revisions
617
630
# have been pulled into the local branch. We may change that
618
631
# behavior in the future.
619
self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
632
self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
621
634
def test_no_commits(self):
622
635
new_tree = self.make_branch_and_tree('new_tree')
652
665
def test_as_revision_id(self):
653
666
self.tree.branch.set_submit_branch('tree2')
654
667
self.assertAsRevisionId('alt_r2', 'branch:tree2')
670
class TestRevisionSpec_mainline(TestRevisionSpec):
672
def test_as_revision_id(self):
673
self.assertAsRevisionId('r1', 'mainline:1')
674
self.assertAsRevisionId('r2', 'mainline:1.1.1')
675
self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
676
spec = RevisionSpec.from_string('mainline:revid:alt_r22')
677
e = self.assertRaises(errors.InvalidRevisionSpec,
678
spec.as_revision_id, self.tree.branch)
679
self.assertContainsRe(str(e),
680
"Requested revision: 'mainline:revid:alt_r22' does not exist in"
683
def test_in_history(self):
684
self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
687
class TestRevisionSpec_annotate(TestRevisionSpec):
690
super(TestRevisionSpec_annotate, self).setUp()
691
self.tree = self.make_branch_and_tree('annotate-tree')
692
self.build_tree_contents([('annotate-tree/file1', b'1\n')])
693
self.tree.add('file1')
694
self.tree.commit('r1', rev_id=b'r1')
695
self.build_tree_contents([('annotate-tree/file1', b'2\n1\n')])
696
self.tree.commit('r2', rev_id=b'r2')
697
self.build_tree_contents([('annotate-tree/file1', b'2\n1\n3\n')])
699
def test_as_revision_id_r1(self):
700
self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
702
def test_as_revision_id_r2(self):
703
self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
705
def test_as_revision_id_uncommitted(self):
706
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
707
e = self.assertRaises(errors.InvalidRevisionSpec,
708
spec.as_revision_id, self.tree.branch)
709
self.assertContainsRe(str(e),
710
r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
711
" exist in branch: .*\nLine 3 has not been committed.")
713
def test_non_existent_line(self):
714
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
715
e = self.assertRaises(errors.InvalidRevisionSpec,
716
spec.as_revision_id, self.tree.branch)
717
self.assertContainsRe(str(e),
718
r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
719
" exist in branch: .*\nNo such line: 4")
721
def test_invalid_line(self):
722
spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
723
e = self.assertRaises(errors.InvalidRevisionSpec,
724
spec.as_revision_id, self.tree.branch)
725
self.assertContainsRe(str(e),
726
r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
727
" exist in branch: .*\nNo such line: q")
729
def test_no_such_file(self):
730
spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
731
e = self.assertRaises(errors.InvalidRevisionSpec,
732
spec.as_revision_id, self.tree.branch)
733
self.assertContainsRe(str(e),
734
r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
735
" exist in branch: .*\nFile 'file2' is not versioned")
737
def test_no_such_file_with_colon(self):
738
spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
739
e = self.assertRaises(errors.InvalidRevisionSpec,
740
spec.as_revision_id, self.tree.branch)
741
self.assertContainsRe(str(e),
742
r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
743
" exist in branch: .*\nFile 'fi:le2' is not versioned")