/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
"""Tests for the info command of bzr."""
19
19
 
 
20
import shutil
20
21
import sys
21
22
 
22
23
from bzrlib import (
23
24
    branch,
24
25
    bzrdir,
 
26
    controldir,
25
27
    errors,
26
28
    info,
27
29
    osutils,
29
31
    upgrade,
30
32
    urlutils,
31
33
    )
 
34
from bzrlib.tests.matchers import ContainsNoVfsCalls
32
35
from bzrlib.transport import memory
33
36
 
34
37
 
45
48
        self.assertEqual(out, '')
46
49
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
47
50
 
 
51
    def test_info_empty_controldir(self):
 
52
        self.make_bzrdir('ctrl')
 
53
        out, err = self.run_bzr('info ctrl')
 
54
        self.assertEquals(out,
 
55
            'Empty control directory (format: 2a or pack-0.92)\n'
 
56
            'Location:\n'
 
57
            '  control directory: ctrl\n')
 
58
        self.assertEquals(err, '')
 
59
 
 
60
    def test_info_dangling_branch_reference(self):
 
61
        br = self.make_branch('target')
 
62
        br.create_checkout('from', lightweight=True)
 
63
        shutil.rmtree('target')
 
64
        out, err = self.run_bzr('info from')
 
65
        self.assertEquals(out,
 
66
            'Dangling branch reference (format: 2a or pack-0.92)\n'
 
67
            'Location:\n'
 
68
            '   control directory: from\n'
 
69
            '  checkout of branch: target\n')
 
70
        self.assertEquals(err, '')
 
71
 
48
72
    def test_info_standalone(self):
49
73
        transport = self.get_transport()
50
74
 
51
75
        # Create initial standalone branch
52
 
        tree1 = self.make_branch_and_tree('standalone', 'weave')
 
76
        tree1 = self.make_branch_and_tree('standalone', 'knit')
53
77
        self.build_tree(['standalone/a'])
54
78
        tree1.add('a')
55
79
        branch1 = tree1.branch
56
80
 
57
81
        out, err = self.run_bzr('info standalone')
58
82
        self.assertEqualDiff(
59
 
"""Standalone tree (format: weave)
 
83
"""Standalone tree (format: knit)
60
84
Location:
61
85
  branch root: standalone
62
86
""", out)
65
89
        # Standalone branch - verbose mode
66
90
        out, err = self.run_bzr('info standalone -v')
67
91
        self.assertEqualDiff(
68
 
"""Standalone tree (format: weave)
 
92
"""Standalone tree (format: knit)
69
93
Location:
70
94
  branch root: standalone
71
95
 
72
96
Format:
73
 
       control: All-in-one format 6
74
 
  working tree: Working tree format 2
75
 
        branch: Branch format 4
76
 
    repository: Weave repository format 6
 
97
       control: Meta directory format 1
 
98
  working tree: Working tree format 3
 
99
        branch: Branch format 5
 
100
    repository: Knit repository format 1
77
101
 
78
102
In the working tree:
79
103
         0 unchanged
96
120
        # Standalone branch - really verbose mode
97
121
        out, err = self.run_bzr('info standalone -vv')
98
122
        self.assertEqualDiff(
99
 
"""Standalone tree (format: weave)
 
123
"""Standalone tree (format: knit)
100
124
Location:
101
125
  branch root: standalone
102
126
 
103
127
Format:
104
 
       control: All-in-one format 6
105
 
  working tree: Working tree format 2
106
 
        branch: Branch format 4
107
 
    repository: Weave repository format 6
 
128
       control: Meta directory format 1
 
129
  working tree: Working tree format 3
 
130
        branch: Branch format 5
 
131
    repository: Knit repository format 1
108
132
 
109
133
In the working tree:
110
134
         0 unchanged
125
149
""", out)
126
150
        self.assertEqual('', err)
127
151
        tree1.commit('commit one')
128
 
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
 
152
        rev = branch1.repository.get_revision(branch1.last_revision())
129
153
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
130
154
 
131
155
        # Branch standalone with push location
134
158
 
135
159
        out, err = self.run_bzr('info branch')
136
160
        self.assertEqualDiff(
137
 
"""Standalone tree (format: weave)
 
161
"""Standalone tree (format: knit)
138
162
Location:
139
163
  branch root: branch
140
164
 
146
170
 
147
171
        out, err = self.run_bzr('info branch --verbose')
148
172
        self.assertEqualDiff(
149
 
"""Standalone tree (format: weave)
 
173
"""Standalone tree (format: knit)
150
174
Location:
151
175
  branch root: branch
152
176
 
155
179
  parent branch: standalone
156
180
 
157
181
Format:
158
 
       control: All-in-one format 6
159
 
  working tree: Working tree format 2
160
 
        branch: Branch format 4
161
 
    repository: Weave repository format 6
 
182
       control: Meta directory format 1
 
183
  working tree: Working tree format 3
 
184
        branch: Branch format 5
 
185
    repository: Knit repository format 1
162
186
 
163
187
In the working tree:
164
188
         1 unchanged
187
211
        branch1.bzrdir.sprout('bound')
188
212
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
189
213
        upgrade.upgrade('bound', knit1_format)
190
 
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
 
214
        branch3 = controldir.ControlDir.open('bound').open_branch()
191
215
        branch3.bind(branch1)
192
216
        bound_tree = branch3.bzrdir.open_workingtree()
193
217
        out, err = self.run_bzr('info -v bound')
213
237
         0 removed
214
238
         0 renamed
215
239
         0 unknown
216
 
         1 ignored
 
240
         0 ignored
217
241
         0 versioned subdirectories
218
242
 
219
243
Branch history:
232
256
        self.assertEqual('', err)
233
257
 
234
258
        # Checkout standalone (same as above, but does not have parent set)
235
 
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
259
        branch4 = controldir.ControlDir.create_branch_convenience('checkout',
236
260
            format=knit1_format)
237
261
        branch4.bind(branch1)
238
262
        branch4.bzrdir.open_workingtree().update()
276
300
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
277
301
        branch5 = tree5.branch
278
302
        out, err = self.run_bzr('info -v lightcheckout')
 
303
        if "metaweave" in bzrdir.format_registry:
 
304
            format_description = "knit or metaweave"
 
305
        else:
 
306
            format_description = "knit"
279
307
        self.assertEqualDiff(
280
308
"""Lightweight checkout (format: %s)
281
309
Location:
284
312
 
285
313
Format:
286
314
       control: Meta directory format 1
287
 
  working tree: Working tree format 6
288
 
        branch: Branch format 4
289
 
    repository: Weave repository format 6
 
315
  working tree: Working tree format 3
 
316
        branch: Branch format 5
 
317
    repository: Knit repository format 1
290
318
 
291
319
In the working tree:
292
320
         1 unchanged
306
334
 
307
335
Repository:
308
336
         1 revision
309
 
""" % (self._repo_strings, datestring_first, datestring_first,), out)
 
337
""" % (format_description, datestring_first, datestring_first,), out)
310
338
        self.assertEqual('', err)
311
339
 
312
340
        # Update initial standalone branch
313
341
        self.build_tree(['standalone/b'])
314
342
        tree1.add('b')
315
343
        tree1.commit('commit two')
316
 
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
 
344
        rev = branch1.repository.get_revision(branch1.last_revision())
317
345
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
318
346
 
319
347
        # Out of date branched standalone branch will not be detected
320
348
        out, err = self.run_bzr('info -v branch')
321
349
        self.assertEqualDiff(
322
 
"""Standalone tree (format: weave)
 
350
"""Standalone tree (format: knit)
323
351
Location:
324
352
  branch root: branch
325
353
 
328
356
  parent branch: standalone
329
357
 
330
358
Format:
331
 
       control: All-in-one format 6
332
 
  working tree: Working tree format 2
333
 
        branch: Branch format 4
334
 
    repository: Weave repository format 6
 
359
       control: Meta directory format 1
 
360
  working tree: Working tree format 3
 
361
        branch: Branch format 5
 
362
    repository: Knit repository format 1
335
363
 
336
364
In the working tree:
337
365
         1 unchanged
381
409
         0 removed
382
410
         0 renamed
383
411
         0 unknown
384
 
         1 ignored
 
412
         0 ignored
385
413
         0 versioned subdirectories
386
414
 
387
415
Branch history:
446
474
 
447
475
Format:
448
476
       control: Meta directory format 1
449
 
  working tree: Working tree format 6
450
 
        branch: Branch format 4
451
 
    repository: Weave repository format 6
 
477
  working tree: Working tree format 3
 
478
        branch: Branch format 5
 
479
    repository: Knit repository format 1
452
480
 
453
481
Working tree is out of date: missing 1 revision.
454
482
 
470
498
 
471
499
Repository:
472
500
         2 revisions
473
 
""" % (self._repo_strings, datestring_first, datestring_last,), out)
 
501
""" % (format_description, datestring_first, datestring_last,), out)
474
502
        self.assertEqual('', err)
475
503
 
476
504
    def test_info_standalone_no_tree(self):
525
553
 
526
554
        # Create branch inside shared repository
527
555
        repo.bzrdir.root_transport.mkdir('branch')
528
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
529
 
            format=format)
 
556
        branch1 = controldir.ControlDir.create_branch_convenience(
 
557
            'repo/branch', format=format)
530
558
        out, err = self.run_bzr('info -v repo/branch')
531
559
        self.assertEqualDiff(
532
560
"""Repository branch (format: dirstate or knit)
567
595
        self.build_tree(['tree/lightcheckout/a'])
568
596
        tree2.add('a')
569
597
        tree2.commit('commit one')
570
 
        rev = repo.get_revision(branch2.revision_history()[0])
 
598
        rev = repo.get_revision(branch2.last_revision())
571
599
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
572
600
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
573
601
        self.assertEqualDiff(
686
714
        tree3.commit('commit two')
687
715
 
688
716
        # Out of date lightweight checkout
689
 
        rev = repo.get_revision(branch1.revision_history()[-1])
 
717
        rev = repo.get_revision(branch1.last_revision())
690
718
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
691
719
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
692
720
        self.assertEqualDiff(
799
827
 
800
828
        # Create two branches
801
829
        repo.bzrdir.root_transport.mkdir('branch1')
802
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
830
        branch1 = controldir.ControlDir.create_branch_convenience('repo/branch1',
803
831
            format=format)
804
832
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
805
833
 
842
870
        tree1 = branch1.bzrdir.open_workingtree()
843
871
        tree1.add('a')
844
872
        tree1.commit('commit one')
845
 
        rev = repo.get_revision(branch1.revision_history()[0])
 
873
        rev = repo.get_revision(branch1.last_revision())
846
874
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
847
875
        out, err = self.run_bzr('info -v repo/branch1')
848
876
        self.assertEqualDiff(
1217
1245
                                    format=bzrdir.BzrDirMetaFormat1())
1218
1246
        repo.set_make_working_trees(False)
1219
1247
        repo.bzrdir.root_transport.mkdir('branch')
1220
 
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1221
 
                                    format=bzrdir.BzrDirMetaFormat1())
 
1248
        repo_branch = controldir.ControlDir.create_branch_convenience(
 
1249
            'repo/branch', format=bzrdir.BzrDirMetaFormat1())
1222
1250
        # Do a heavy checkout
1223
1251
        transport.mkdir('tree')
1224
1252
        transport.mkdir('tree/checkout')
1225
 
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1226
 
            format=bzrdir.BzrDirMetaFormat1())
 
1253
        co_branch = controldir.ControlDir.create_branch_convenience(
 
1254
            'tree/checkout', format=bzrdir.BzrDirMetaFormat1())
1227
1255
        co_branch.bind(repo_branch)
1228
1256
        # Do a light checkout of the heavy one
1229
1257
        transport.mkdir('tree/lightcheckout')
1323
1351
            self.knownFailure('Win32 cannot run "bzr info"'
1324
1352
                              ' when the tree is locked.')
1325
1353
 
1326
 
    def test_info_locking_oslocks(self):
1327
 
        if sys.platform == "win32":
1328
 
            self.skip("don't use oslocks on win32 in unix manner")
1329
 
        # This test tests old (all-in-one, OS lock using) behaviour which
1330
 
        # simply cannot work on windows (and is indeed why we changed our
1331
 
        # design. As such, don't try to remove the thisFailsStrictLockCheck
1332
 
        # call here.
1333
 
        self.thisFailsStrictLockCheck()
1334
 
 
1335
 
        tree = self.make_branch_and_tree('branch',
1336
 
                                         format=bzrdir.BzrDirFormat6())
1337
 
 
1338
 
        # Test all permutations of locking the working tree, branch and repository
1339
 
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1340
 
        # implemented by raising NotImplementedError and get_physical_lock_status()
1341
 
        # always returns false. This makes bzr info hide the lock status.  (Olaf)
1342
 
        # W B R
1343
 
 
1344
 
        # U U U
1345
 
        out, err = self.run_bzr('info -v branch')
1346
 
        self.assertEqualDiff(
1347
 
"""Standalone tree (format: weave)
1348
 
Location:
1349
 
  branch root: %s
1350
 
 
1351
 
Format:
1352
 
       control: All-in-one format 6
1353
 
  working tree: Working tree format 2
1354
 
        branch: Branch format 4
1355
 
    repository: %s
1356
 
 
1357
 
In the working tree:
1358
 
         0 unchanged
1359
 
         0 modified
1360
 
         0 added
1361
 
         0 removed
1362
 
         0 renamed
1363
 
         0 unknown
1364
 
         0 ignored
1365
 
         0 versioned subdirectories
1366
 
 
1367
 
Branch history:
1368
 
         0 revisions
1369
 
 
1370
 
Repository:
1371
 
         0 revisions
1372
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
1373
 
       ), out)
1374
 
        self.assertEqual('', err)
1375
 
        # L L L
1376
 
        tree.lock_write()
1377
 
        out, err = self.run_bzr('info -v branch')
1378
 
        self.assertEqualDiff(
1379
 
"""Standalone tree (format: weave)
1380
 
Location:
1381
 
  branch root: %s
1382
 
 
1383
 
Format:
1384
 
       control: All-in-one format 6
1385
 
  working tree: Working tree format 2
1386
 
        branch: Branch format 4
1387
 
    repository: %s
1388
 
 
1389
 
In the working tree:
1390
 
         0 unchanged
1391
 
         0 modified
1392
 
         0 added
1393
 
         0 removed
1394
 
         0 renamed
1395
 
         0 unknown
1396
 
         0 ignored
1397
 
         0 versioned subdirectories
1398
 
 
1399
 
Branch history:
1400
 
         0 revisions
1401
 
 
1402
 
Repository:
1403
 
         0 revisions
1404
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
1405
 
       ), out)
1406
 
        self.assertEqual('', err)
1407
 
        tree.unlock()
1408
 
 
1409
1354
    def test_info_stacked(self):
1410
1355
        # We have a mainline
1411
1356
        trunk_tree = self.make_branch_and_tree('mainline',
1424
1369
     stacked on: mainline
1425
1370
""", out)
1426
1371
        self.assertEqual("", err)
 
1372
 
 
1373
    def test_info_revinfo_optional(self):
 
1374
        tree = self.make_branch_and_tree('.')
 
1375
        def last_revision_info(self):
 
1376
            raise errors.UnsupportedOperation(last_revision_info, self)
 
1377
        self.overrideAttr(
 
1378
            branch.Branch, "last_revision_info", last_revision_info)
 
1379
        out, err = self.run_bzr('info -v .')
 
1380
        self.assertEqual(
 
1381
"""Standalone tree (format: 2a)
 
1382
Location:
 
1383
  branch root: .
 
1384
 
 
1385
Format:
 
1386
       control: Meta directory format 1
 
1387
  working tree: Working tree format 6
 
1388
        branch: Branch format 7
 
1389
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1390
 
 
1391
In the working tree:
 
1392
         0 unchanged
 
1393
         0 modified
 
1394
         0 added
 
1395
         0 removed
 
1396
         0 renamed
 
1397
         0 unknown
 
1398
         0 ignored
 
1399
         0 versioned subdirectories
 
1400
""", out)
 
1401
        self.assertEqual("", err)
 
1402
 
 
1403
    def test_info_shows_colocated_branches(self):
 
1404
        bzrdir = self.make_branch('.', format='development-colo').bzrdir
 
1405
        bzrdir.create_branch(name="colo1")
 
1406
        bzrdir.create_branch(name="colo2")
 
1407
        bzrdir.create_branch(name="colo3")
 
1408
        out, err = self.run_bzr('info -v .')
 
1409
        self.assertEqualDiff(
 
1410
"""Standalone branch (format: development-colo)
 
1411
Location:
 
1412
  branch root: .
 
1413
 
 
1414
Format:
 
1415
       control: Meta directory format 1 with support for colocated branches
 
1416
        branch: Branch format 7
 
1417
    repository: Repository format 2a - rich roots, group compression and chk inventories
 
1418
 
 
1419
Control directory:
 
1420
         4 branches
 
1421
 
 
1422
Branch history:
 
1423
         0 revisions
 
1424
 
 
1425
Repository:
 
1426
         0 revisions
 
1427
""", out)
 
1428
        self.assertEqual("", err)
 
1429
 
 
1430
 
 
1431
class TestSmartServerInfo(tests.TestCaseWithTransport):
 
1432
 
 
1433
    def test_simple_branch_info(self):
 
1434
        self.setup_smart_server_with_call_log()
 
1435
        t = self.make_branch_and_tree('branch')
 
1436
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1437
        t.add("foo")
 
1438
        t.commit("message")
 
1439
        self.reset_smart_call_log()
 
1440
        out, err = self.run_bzr(['info', self.get_url('branch')])
 
1441
        # This figure represent the amount of work to perform this use case. It
 
1442
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1443
        # being too low. If rpc_count increases, more network roundtrips have
 
1444
        # become necessary for this use case. Please do not adjust this number
 
1445
        # upwards without agreement from bzr's network support maintainers.
 
1446
        self.assertLength(11, self.hpss_calls)
 
1447
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
1448
 
 
1449
    def test_verbose_branch_info(self):
 
1450
        self.setup_smart_server_with_call_log()
 
1451
        t = self.make_branch_and_tree('branch')
 
1452
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
1453
        t.add("foo")
 
1454
        t.commit("message")
 
1455
        self.reset_smart_call_log()
 
1456
        out, err = self.run_bzr(['info', '-v', self.get_url('branch')])
 
1457
        # This figure represent the amount of work to perform this use case. It
 
1458
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
1459
        # being too low. If rpc_count increases, more network roundtrips have
 
1460
        # become necessary for this use case. Please do not adjust this number
 
1461
        # upwards without agreement from bzr's network support maintainers.
 
1462
        self.assertLength(15, self.hpss_calls)
 
1463
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)