~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_log.py

  • Committer: Martin Pool
  • Date: 2010-02-17 05:12:01 UTC
  • mfrom: (4797.2.16 2.1)
  • mto: This revision was merged to the branch mainline in revision 5037.
  • Revision ID: mbp@sourcefrog.net-20100217051201-1sd9dssoujfdc6c4
merge 2.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from itertools import izip
21
21
import os
 
22
import re
22
23
 
23
24
from bzrlib import (
24
25
    branchbuilder,
28
29
    tests,
29
30
    )
30
31
from bzrlib.tests import (
 
32
    script,
31
33
    test_log,
32
 
    features,
33
34
    )
34
35
 
35
36
 
76
77
                self.log_catcher = test_log.LogCatcher(*args, **kwargs)
77
78
                # Always return our own log formatter
78
79
                return self.log_catcher
79
 
        # Break cycle with closure over self on cleanup by removing method
80
 
        self.addCleanup(setattr, MyLogFormatter, "__new__", None)
81
80
 
82
81
        def getme(branch):
83
82
                # Always return our own log formatter class hijacking the
159
158
        self.make_linear_branch()
160
159
        self.assertLogRevnos(['-c1'], ['1'])
161
160
 
162
 
    def test_branch_revspec(self):
163
 
        foo = self.make_branch_and_tree('foo')
164
 
        bar = self.make_branch_and_tree('bar')
165
 
        self.build_tree(['foo/foo.txt', 'bar/bar.txt'])
166
 
        foo.add('foo.txt')
167
 
        bar.add('bar.txt')
168
 
        foo.commit(message='foo')
169
 
        bar.commit(message='bar')
170
 
        self.run_bzr('log -r branch:../bar', working_dir='foo')
171
 
        self.assertEqual([bar.branch.get_rev_id(1)],
172
 
                         [r.rev.revision_id
173
 
                          for r in self.get_captured_revisions()])
174
 
 
175
 
 
176
 
class TestLogExcludeCommonAncestry(TestLogWithLogCatcher):
177
 
 
178
 
    def test_exclude_common_ancestry_simple_revnos(self):
179
 
        self.make_linear_branch()
180
 
        self.assertLogRevnos(['-r1..3', '--exclude-common-ancestry'],
181
 
                             ['3', '2'])
182
 
 
183
161
 
184
162
class TestLogMergedLinearAncestry(TestLogWithLogCatcher):
185
163
 
189
167
        # stop calling run_bzr, there is no point) --vila 100118.
190
168
        builder = branchbuilder.BranchBuilder(self.get_transport())
191
169
        builder.start_series()
192
 
        # 1
193
 
        # | \
194
 
        # 2  1.1.1
195
 
        # | / |
196
 
        # 3  1.1.2
197
 
        # |   |
198
 
        # |  1.1.3
199
 
        # | / |
200
 
        # 4  1.1.4
201
 
        # | /
202
 
        # 5
203
 
 
204
170
        # mainline
205
171
        builder.build_snapshot('1', None, [
206
172
            ('add', ('', 'root-id', 'directory', ''))])
239
205
 
240
206
class Test_GenerateAllRevisions(TestLogWithLogCatcher):
241
207
 
242
 
    def setUp(self):
243
 
        super(Test_GenerateAllRevisions, self).setUp()
244
 
        builder = self.make_branch_with_many_merges()
245
 
        b = builder.get_branch()
246
 
        b.lock_read()
247
 
        self.addCleanup(b.unlock)
248
 
        self.branch = b
249
 
 
250
208
    def make_branch_with_many_merges(self, path='.', format=None):
251
209
        builder = branchbuilder.BranchBuilder(self.get_transport())
252
210
        builder.start_series()
268
226
        return builder
269
227
 
270
228
    def test_not_an_ancestor(self):
 
229
        builder = self.make_branch_with_many_merges()
 
230
        b = builder.get_branch()
 
231
        b.lock_read()
 
232
        self.addCleanup(b.unlock)
271
233
        self.assertRaises(errors.BzrCommandError,
272
234
                          log._generate_all_revisions,
273
 
                          self.branch, '1.1.1', '2.1.3', 'reverse',
 
235
                          b, '1.1.1', '2.1.3', 'reverse',
274
236
                          delayed_graph_generation=True)
275
237
 
276
238
    def test_wrong_order(self):
 
239
        builder = self.make_branch_with_many_merges()
 
240
        b = builder.get_branch()
 
241
        b.lock_read()
 
242
        self.addCleanup(b.unlock)
277
243
        self.assertRaises(errors.BzrCommandError,
278
244
                          log._generate_all_revisions,
279
 
                          self.branch, '5', '2.1.3', 'reverse',
 
245
                          b, '5', '2.1.3', 'reverse',
280
246
                          delayed_graph_generation=True)
281
247
 
282
 
    def test_no_start_rev_id_with_end_rev_id_being_a_merge(self):
283
 
        revs = log._generate_all_revisions(
284
 
            self.branch, None, '2.1.3',
285
 
            'reverse', delayed_graph_generation=True)
286
 
 
287
248
 
288
249
class TestLogRevSpecsWithPaths(TestLogWithLogCatcher):
289
250
 
382
343
 
383
344
    def test_log_bad_message_re(self):
384
345
        """Bad --message argument gives a sensible message
385
 
 
 
346
        
386
347
        See https://bugs.launchpad.net/bzr/+bug/251352
387
348
        """
388
349
        self.make_minimal_branch()
389
350
        out, err = self.run_bzr(['log', '-m', '*'], retcode=3)
390
 
        self.assertContainsRe(err, "ERROR.*Invalid pattern.*nothing to repeat")
391
 
        self.assertNotContainsRe(err, "Unprintable exception")
392
 
        self.assertEqual(out, '')
 
351
        self.assertEqual("bzr: ERROR: Invalid regular expression"
 
352
            " in log message filter"
 
353
            ": '*'"
 
354
            ": nothing to repeat\n", err)
 
355
        self.assertEqual('', out)
393
356
 
394
357
    def test_log_unsupported_timezone(self):
395
358
        self.make_linear_branch()
397
360
                            'options are "utc", "original", "local".'],
398
361
                           ['log', '--timezone', 'foo'])
399
362
 
400
 
    def test_log_exclude_ancestry_no_range(self):
401
 
        self.make_linear_branch()
402
 
        self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
403
 
                            ' requires -r with two revisions'],
404
 
                           ['log', '--exclude-common-ancestry'])
405
 
 
406
 
    def test_log_exclude_ancestry_single_revision(self):
407
 
        self.make_merged_branch()
408
 
        self.run_bzr_error(['bzr: ERROR: --exclude-common-ancestry'
409
 
                            ' requires two different revisions'],
410
 
                           ['log', '--exclude-common-ancestry',
411
 
                            '-r1.1.1..1.1.1'])
412
363
 
413
364
class TestLogTags(TestLog):
414
365
 
443
394
        self.assertContainsRe(log, r'tags: tag1')
444
395
 
445
396
 
446
 
class TestLogSignatures(TestLog):
447
 
 
448
 
    def test_log_with_signatures(self):
449
 
        self.requireFeature(features.gpgme)
450
 
 
451
 
        tree = self.make_linear_branch(format='dirstate-tags')
452
 
 
453
 
        log = self.run_bzr("log --signatures")[0]
454
 
        self.assertTrue('signature: no signature' in log)
455
 
 
456
 
    def test_log_without_signatures(self):
457
 
        self.requireFeature(features.gpgme)
458
 
 
459
 
        tree = self.make_linear_branch(format='dirstate-tags')
460
 
 
461
 
        log = self.run_bzr("log")[0]
462
 
        self.assertFalse('signature: no signature' in log)
463
 
 
464
 
 
465
397
class TestLogVerbose(TestLog):
466
398
 
467
399
    def setUp(self):
483
415
    def test_log_short_verbose(self):
484
416
        self.assertUseShortDeltaFormat(['log', '--short', '-v'])
485
417
 
486
 
    def test_log_s_verbose(self):
487
 
        self.assertUseShortDeltaFormat(['log', '-S', '-v'])
488
 
 
489
418
    def test_log_short_verbose_verbose(self):
490
419
        self.assertUseLongDeltaFormat(['log', '--short', '-vv'])
491
420
 
947
876
        self.prepare_tree()
948
877
        os.chdir("dir1")
949
878
        self.assertLogRevnos(['dir2', 'file5'], ['5', '3'])
950
 
 
951
 
 
952
 
class MainlineGhostTests(TestLogWithLogCatcher):
953
 
 
954
 
    def setUp(self):
955
 
        super(MainlineGhostTests, self).setUp()
956
 
        tree = self.make_branch_and_tree('')
957
 
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
958
 
        tree.add('')
959
 
        tree.commit('msg1', rev_id='rev1')
960
 
        tree.commit('msg2', rev_id='rev2')
961
 
 
962
 
    def test_log_range(self):
963
 
        self.assertLogRevnos(["-r1..2"], ["2", "1"])
964
 
 
965
 
    def test_log_norange(self):
966
 
        self.assertLogRevnos([], ["2", "1"])
967
 
 
968
 
    def test_log_range_open_begin(self):
969
 
        self.knownFailure("log with ghosts fails. bug #726466")
970
 
        (stdout, stderr) = self.run_bzr(['log', '-r..2'], retcode=3)
971
 
        self.assertEqual(["2", "1"],
972
 
                         [r.revno for r in self.get_captured_revisions()])
973
 
        self.assertEquals("bzr: ERROR: Further revision history missing.", stderr)
974
 
 
975
 
    def test_log_range_open_end(self):
976
 
        self.assertLogRevnos(["-r1.."], ["2", "1"])
977
 
 
978
 
class TestLogMatch(TestLogWithLogCatcher):
979
 
    def prepare_tree(self):
980
 
        tree = self.make_branch_and_tree('')
981
 
        self.build_tree(
982
 
            ['/hello.txt', '/goodbye.txt'])
983
 
        tree.add('hello.txt')
984
 
        tree.commit(message='message1', committer='committer1', authors=['author1'])
985
 
        tree.add('goodbye.txt')
986
 
        tree.commit(message='message2', committer='committer2', authors=['author2'])
987
 
    
988
 
    def test_message(self):
989
 
        self.prepare_tree()
990
 
        self.assertLogRevnos(["-m", "message1"], ["1"])
991
 
        self.assertLogRevnos(["-m", "message2"], ["2"])
992
 
        self.assertLogRevnos(["-m", "message"], ["2", "1"])
993
 
        self.assertLogRevnos(["-m", "message1", "-m", "message2"], ["2", "1"])
994
 
        self.assertLogRevnos(["--match-message", "message1"], ["1"])
995
 
        self.assertLogRevnos(["--match-message", "message2"], ["2"])
996
 
        self.assertLogRevnos(["--match-message", "message"], ["2", "1"])
997
 
        self.assertLogRevnos(["--match-message", "message1", 
998
 
                              "--match-message", "message2"], ["2", "1"])
999
 
        self.assertLogRevnos(["--message", "message1"], ["1"])
1000
 
        self.assertLogRevnos(["--message", "message2"], ["2"])
1001
 
        self.assertLogRevnos(["--message", "message"], ["2", "1"])
1002
 
        self.assertLogRevnos(["--match-message", "message1", 
1003
 
                              "--message", "message2"], ["2", "1"])
1004
 
        self.assertLogRevnos(["--message", "message1", 
1005
 
                              "--match-message", "message2"], ["2", "1"])
1006
 
 
1007
 
    def test_committer(self):
1008
 
        self.prepare_tree()
1009
 
        self.assertLogRevnos(["-m", "committer1"], ["1"])
1010
 
        self.assertLogRevnos(["-m", "committer2"], ["2"])
1011
 
        self.assertLogRevnos(["-m", "committer"], ["2", "1"])
1012
 
        self.assertLogRevnos(["-m", "committer1", "-m", "committer2"], 
1013
 
                             ["2", "1"])
1014
 
        self.assertLogRevnos(["--match-committer", "committer1"], ["1"])
1015
 
        self.assertLogRevnos(["--match-committer", "committer2"], ["2"])
1016
 
        self.assertLogRevnos(["--match-committer", "committer"], ["2", "1"])
1017
 
        self.assertLogRevnos(["--match-committer", "committer1", 
1018
 
                              "--match-committer", "committer2"], ["2", "1"])
1019
 
 
1020
 
    def test_author(self):
1021
 
        self.prepare_tree()
1022
 
        self.assertLogRevnos(["-m", "author1"], ["1"])
1023
 
        self.assertLogRevnos(["-m", "author2"], ["2"])
1024
 
        self.assertLogRevnos(["-m", "author"], ["2", "1"])
1025
 
        self.assertLogRevnos(["-m", "author1", "-m", "author2"], 
1026
 
                             ["2", "1"])
1027
 
        self.assertLogRevnos(["--match-author", "author1"], ["1"])
1028
 
        self.assertLogRevnos(["--match-author", "author2"], ["2"])
1029
 
        self.assertLogRevnos(["--match-author", "author"], ["2", "1"])
1030
 
        self.assertLogRevnos(["--match-author", "author1", 
1031
 
                              "--match-author", "author2"], ["2", "1"])