~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2011-09-22 14:12:18 UTC
  • mfrom: (6155.3.1 jam)
  • Revision ID: pqm@pqm.ubuntu.com-20110922141218-86s4uu6nqvourw4f
(jameinel) Cleanup comments bzrlib/smart/__init__.py (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
 
1
# Copyright (C) 2006-2010 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
13
12
#
14
13
# You should have received a copy of the GNU General Public License
15
14
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
16
 
18
17
 
19
18
"""Tests for the info command of bzr."""
20
19
 
21
20
import sys
22
21
 
23
 
import bzrlib
24
 
from bzrlib.osutils import format_date
25
 
from bzrlib.tests import TestSkipped
26
 
from bzrlib.tests.blackbox import ExternalBase
27
 
 
28
 
 
29
 
class TestInfo(ExternalBase):
 
22
from bzrlib import (
 
23
    branch,
 
24
    bzrdir,
 
25
    errors,
 
26
    info,
 
27
    osutils,
 
28
    tests,
 
29
    upgrade,
 
30
    urlutils,
 
31
    )
 
32
from bzrlib.transport import memory
 
33
 
 
34
 
 
35
class TestInfo(tests.TestCaseWithTransport):
 
36
 
 
37
    def setUp(self):
 
38
        super(TestInfo, self).setUp()
 
39
        self._repo_strings = "2a"
30
40
 
31
41
    def test_info_non_existing(self):
32
 
        if sys.platform == "win32":
33
 
            location = "C:/i/do/not/exist/"
34
 
        else:
35
 
            location = "/i/do/not/exist/"
36
 
        out, err = self.runbzr('info '+location, retcode=3)
 
42
        self.vfs_transport_factory = memory.MemoryServer
 
43
        location = self.get_url()
 
44
        out, err = self.run_bzr('info '+location, retcode=3)
37
45
        self.assertEqual(out, '')
38
 
        self.assertEqual(err, 'bzr: ERROR: Not a branch: %s\n' % location)
 
46
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
39
47
 
40
48
    def test_info_standalone(self):
41
49
        transport = self.get_transport()
42
50
 
43
51
        # Create initial standalone branch
44
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
45
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirFormat6())
46
 
        tree1 = self.make_branch_and_tree('standalone')
47
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
 
52
        tree1 = self.make_branch_and_tree('standalone', 'knit')
48
53
        self.build_tree(['standalone/a'])
49
54
        tree1.add('a')
50
55
        branch1 = tree1.branch
51
 
        out, err = self.runbzr('info standalone')
52
 
        self.assertEqualDiff(
53
 
"""Location:
54
 
  branch root: %s
55
 
 
56
 
Format:
57
 
       control: All-in-one format 6
58
 
  working tree: Working tree format 2
59
 
        branch: Branch format 4
60
 
    repository: Weave repository format 6
61
 
 
62
 
In the working tree:
63
 
         0 unchanged
64
 
         0 modified
65
 
         1 added
66
 
         0 removed
67
 
         0 renamed
68
 
         0 unknown
69
 
         0 ignored
70
 
         0 versioned subdirectories
71
 
 
72
 
Branch history:
73
 
         0 revisions
74
 
 
75
 
Revision store:
76
 
         0 revisions
77
 
         0 KiB
78
 
""" % branch1.bzrdir.root_transport.base, out)
 
56
 
 
57
        out, err = self.run_bzr('info standalone')
 
58
        self.assertEqualDiff(
 
59
"""Standalone tree (format: knit)
 
60
Location:
 
61
  branch root: standalone
 
62
""", out)
 
63
        self.assertEqual('', err)
 
64
 
 
65
        # Standalone branch - verbose mode
 
66
        out, err = self.run_bzr('info standalone -v')
 
67
        self.assertEqualDiff(
 
68
"""Standalone tree (format: knit)
 
69
Location:
 
70
  branch root: standalone
 
71
 
 
72
Format:
 
73
       control: Meta directory format 1
 
74
  working tree: Working tree format 3
 
75
        branch: Branch format 5
 
76
    repository: Knit repository format 1
 
77
 
 
78
In the working tree:
 
79
         0 unchanged
 
80
         0 modified
 
81
         1 added
 
82
         0 removed
 
83
         0 renamed
 
84
         0 unknown
 
85
         0 ignored
 
86
         0 versioned subdirectories
 
87
 
 
88
Branch history:
 
89
         0 revisions
 
90
 
 
91
Repository:
 
92
         0 revisions
 
93
""", out)
 
94
        self.assertEqual('', err)
 
95
 
 
96
        # Standalone branch - really verbose mode
 
97
        out, err = self.run_bzr('info standalone -vv')
 
98
        self.assertEqualDiff(
 
99
"""Standalone tree (format: knit)
 
100
Location:
 
101
  branch root: standalone
 
102
 
 
103
Format:
 
104
       control: Meta directory format 1
 
105
  working tree: Working tree format 3
 
106
        branch: Branch format 5
 
107
    repository: Knit repository format 1
 
108
 
 
109
In the working tree:
 
110
         0 unchanged
 
111
         0 modified
 
112
         1 added
 
113
         0 removed
 
114
         0 renamed
 
115
         0 unknown
 
116
         0 ignored
 
117
         0 versioned subdirectories
 
118
 
 
119
Branch history:
 
120
         0 revisions
 
121
         0 committers
 
122
 
 
123
Repository:
 
124
         0 revisions
 
125
""", out)
79
126
        self.assertEqual('', err)
80
127
        tree1.commit('commit one')
81
128
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
82
 
        datestring_first = format_date(rev.timestamp, rev.timezone)
 
129
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
83
130
 
84
131
        # Branch standalone with push location
85
132
        branch2 = branch1.bzrdir.sprout('branch').open_branch()
86
133
        branch2.set_push_location(branch1.bzrdir.root_transport.base)
87
 
        out, err = self.runbzr('info branch --verbose')
88
 
        self.assertEqualDiff(
89
 
"""Location:
90
 
  branch root: %s
91
 
 
92
 
Related branches:
93
 
      parent branch: %s
94
 
  publish to branch: %s
 
134
 
 
135
        out, err = self.run_bzr('info branch')
 
136
        self.assertEqualDiff(
 
137
"""Standalone tree (format: knit)
 
138
Location:
 
139
  branch root: branch
 
140
 
 
141
Related branches:
 
142
    push branch: standalone
 
143
  parent branch: standalone
 
144
""", out)
 
145
        self.assertEqual('', err)
 
146
 
 
147
        out, err = self.run_bzr('info branch --verbose')
 
148
        self.assertEqualDiff(
 
149
"""Standalone tree (format: knit)
 
150
Location:
 
151
  branch root: branch
 
152
 
 
153
Related branches:
 
154
    push branch: standalone
 
155
  parent branch: standalone
95
156
 
96
157
Format:
97
 
       control: All-in-one format 6
98
 
  working tree: Working tree format 2
99
 
        branch: Branch format 4
100
 
    repository: Weave repository format 6
 
158
       control: Meta directory format 1
 
159
  working tree: Working tree format 3
 
160
        branch: Branch format 5
 
161
    repository: Knit repository format 1
101
162
 
102
163
In the working tree:
103
164
         1 unchanged
111
172
 
112
173
Branch history:
113
174
         1 revision
114
 
         1 committer
115
175
         0 days old
116
176
   first revision: %s
117
177
  latest revision: %s
118
178
 
119
 
Revision store:
 
179
Repository:
120
180
         1 revision
121
 
         %d KiB
122
 
""" % (branch2.bzrdir.root_transport.base,
123
 
       branch1.bzrdir.root_transport.base,
124
 
       branch1.bzrdir.root_transport.base,
125
 
       datestring_first, datestring_first,
126
 
       # poking at _revision_store isn't all that clean, but neither is
127
 
       # having the ui test dependent on the exact overhead of a given store.
128
 
       branch2.repository._revision_store.total_size(
129
 
        branch2.repository.get_transaction())[1] / 1024,
 
181
""" % (datestring_first, datestring_first,
130
182
       ), out)
131
183
        self.assertEqual('', err)
132
184
 
133
185
        # Branch and bind to standalone, needs upgrade to metadir
134
186
        # (creates backup as unknown)
135
187
        branch1.bzrdir.sprout('bound')
136
 
        bzrlib.upgrade.upgrade('bound', bzrlib.bzrdir.BzrDirMetaFormat1())
137
 
        branch3 = bzrlib.bzrdir.BzrDir.open('bound').open_branch()
 
188
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
 
189
        upgrade.upgrade('bound', knit1_format)
 
190
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
138
191
        branch3.bind(branch1)
139
192
        bound_tree = branch3.bzrdir.open_workingtree()
140
 
        out, err = self.runbzr('info bound')
 
193
        out, err = self.run_bzr('info -v bound')
141
194
        self.assertEqualDiff(
142
 
"""Location:
143
 
       checkout root: %s
144
 
  checkout of branch: %s
 
195
"""Checkout (format: knit)
 
196
Location:
 
197
       checkout root: bound
 
198
  checkout of branch: standalone
145
199
 
146
200
Related branches:
147
 
  parent branch: %s
 
201
  parent branch: standalone
148
202
 
149
203
Format:
150
204
       control: Meta directory format 1
151
205
  working tree: %s
152
 
        branch: Branch format 5
 
206
        branch: %s
153
207
    repository: %s
154
208
 
155
209
In the working tree:
158
212
         0 added
159
213
         0 removed
160
214
         0 renamed
161
 
         1 unknown
 
215
         0 unknown
162
216
         0 ignored
163
217
         0 versioned subdirectories
164
218
 
168
222
   first revision: %s
169
223
  latest revision: %s
170
224
 
171
 
Revision store:
 
225
Repository:
172
226
         1 revision
173
 
         %d KiB
174
 
""" % (branch3.bzrdir.root_transport.base,
175
 
       branch1.bzrdir.root_transport.base,
176
 
       branch1.bzrdir.root_transport.base,
177
 
       bound_tree._format.get_format_description(),      
 
227
""" % (bound_tree._format.get_format_description(),
 
228
       branch3._format.get_format_description(),
178
229
       branch3.repository._format.get_format_description(),
179
230
       datestring_first, datestring_first,
180
 
       # poking at _revision_store isn't all that clean, but neither is
181
 
       # having the ui test dependent on the exact overhead of a given store.
182
 
       branch3.repository._revision_store.total_size(
183
 
        branch3.repository.get_transaction())[1] / 1024,
184
231
       ), out)
185
232
        self.assertEqual('', err)
186
233
 
187
234
        # Checkout standalone (same as above, but does not have parent set)
188
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
189
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
190
 
        branch4 = bzrlib.bzrdir.BzrDir.create_branch_convenience('checkout')
191
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
 
235
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
236
            format=knit1_format)
192
237
        branch4.bind(branch1)
193
238
        branch4.bzrdir.open_workingtree().update()
194
 
        out, err = self.runbzr('info checkout --verbose')
 
239
        out, err = self.run_bzr('info checkout --verbose')
195
240
        self.assertEqualDiff(
196
 
"""Location:
197
 
       checkout root: %s
198
 
  checkout of branch: %s
 
241
"""Checkout (format: knit)
 
242
Location:
 
243
       checkout root: checkout
 
244
  checkout of branch: standalone
199
245
 
200
246
Format:
201
247
       control: Meta directory format 1
215
261
 
216
262
Branch history:
217
263
         1 revision
218
 
         1 committer
219
264
         0 days old
220
265
   first revision: %s
221
266
  latest revision: %s
222
267
 
223
 
Revision store:
 
268
Repository:
224
269
         1 revision
225
 
         %d KiB
226
 
""" % (branch4.bzrdir.root_transport.base,
227
 
       branch1.bzrdir.root_transport.base,
228
 
       branch4.repository._format.get_format_description(),
 
270
""" % (branch4.repository._format.get_format_description(),
229
271
       datestring_first, datestring_first,
230
 
       # poking at _revision_store isn't all that clean, but neither is
231
 
       # having the ui test dependent on the exact overhead of a given store.
232
 
       branch4.repository._revision_store.total_size(
233
 
        branch4.repository.get_transaction())[1] / 1024,
234
272
       ), out)
235
273
        self.assertEqual('', err)
236
274
 
237
275
        # Lightweight checkout (same as above, different branch and repository)
238
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
239
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
240
 
        transport.mkdir('lightcheckout')
241
 
        dir5 = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('lightcheckout')
242
 
        bzrlib.branch.BranchReferenceFormat().initialize(dir5, branch1)
243
 
        dir5.create_workingtree()
244
 
        tree5 = dir5.open_workingtree()
245
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
 
276
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
246
277
        branch5 = tree5.branch
247
 
        out, err = self.runbzr('info lightcheckout')
 
278
        out, err = self.run_bzr('info -v lightcheckout')
 
279
        if "metaweave" in bzrdir.format_registry:
 
280
            format_description = "knit or metaweave"
 
281
        else:
 
282
            format_description = "knit"
248
283
        self.assertEqualDiff(
249
 
"""Location:
250
 
 light checkout root: %s
251
 
  checkout of branch: %s
 
284
"""Lightweight checkout (format: %s)
 
285
Location:
 
286
  light checkout root: lightcheckout
 
287
   checkout of branch: standalone
252
288
 
253
289
Format:
254
290
       control: Meta directory format 1
255
291
  working tree: Working tree format 3
256
 
        branch: Branch format 4
257
 
    repository: Weave repository format 6
 
292
        branch: Branch format 5
 
293
    repository: Knit repository format 1
258
294
 
259
295
In the working tree:
260
296
         1 unchanged
272
308
   first revision: %s
273
309
  latest revision: %s
274
310
 
275
 
Revision store:
 
311
Repository:
276
312
         1 revision
277
 
         0 KiB
278
 
""" % (tree5.bzrdir.root_transport.base,
279
 
       branch1.bzrdir.root_transport.base,
280
 
       datestring_first, datestring_first,
281
 
       ), out)
 
313
""" % (format_description, datestring_first, datestring_first,), out)
282
314
        self.assertEqual('', err)
283
315
 
284
316
        # Update initial standalone branch
286
318
        tree1.add('b')
287
319
        tree1.commit('commit two')
288
320
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
289
 
        datestring_last = format_date(rev.timestamp, rev.timezone)
 
321
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
290
322
 
291
323
        # Out of date branched standalone branch will not be detected
292
 
        out, err = self.runbzr('info branch')
 
324
        out, err = self.run_bzr('info -v branch')
293
325
        self.assertEqualDiff(
294
 
"""Location:
295
 
  branch root: %s
 
326
"""Standalone tree (format: knit)
 
327
Location:
 
328
  branch root: branch
296
329
 
297
330
Related branches:
298
 
      parent branch: %s
299
 
  publish to branch: %s
 
331
    push branch: standalone
 
332
  parent branch: standalone
300
333
 
301
334
Format:
302
 
       control: All-in-one format 6
303
 
  working tree: Working tree format 2
304
 
        branch: Branch format 4
305
 
    repository: Weave repository format 6
 
335
       control: Meta directory format 1
 
336
  working tree: Working tree format 3
 
337
        branch: Branch format 5
 
338
    repository: Knit repository format 1
306
339
 
307
340
In the working tree:
308
341
         1 unchanged
320
353
   first revision: %s
321
354
  latest revision: %s
322
355
 
323
 
Revision store:
 
356
Repository:
324
357
         1 revision
325
 
         0 KiB
326
 
""" % (branch2.bzrdir.root_transport.base,
327
 
       branch1.bzrdir.root_transport.base,
328
 
       branch1.bzrdir.root_transport.base,
329
 
       datestring_first, datestring_first,
 
358
""" % (datestring_first, datestring_first,
330
359
       ), out)
331
360
        self.assertEqual('', err)
332
361
 
333
362
        # Out of date bound branch
334
 
        out, err = self.runbzr('info bound')
 
363
        out, err = self.run_bzr('info -v bound')
335
364
        self.assertEqualDiff(
336
 
"""Location:
337
 
       checkout root: %s
338
 
  checkout of branch: %s
 
365
"""Checkout (format: knit)
 
366
Location:
 
367
       checkout root: bound
 
368
  checkout of branch: standalone
339
369
 
340
370
Related branches:
341
 
  parent branch: %s
 
371
  parent branch: standalone
342
372
 
343
373
Format:
344
374
       control: Meta directory format 1
354
384
         0 added
355
385
         0 removed
356
386
         0 renamed
357
 
         1 unknown
 
387
         0 unknown
358
388
         0 ignored
359
389
         0 versioned subdirectories
360
390
 
364
394
   first revision: %s
365
395
  latest revision: %s
366
396
 
367
 
Revision store:
 
397
Repository:
368
398
         1 revision
369
 
         %d KiB
370
 
""" % (branch3.bzrdir.root_transport.base,
371
 
       branch1.bzrdir.root_transport.base,
372
 
       branch1.bzrdir.root_transport.base,
373
 
       branch3.repository._format.get_format_description(),
 
399
""" % (branch3.repository._format.get_format_description(),
374
400
       datestring_first, datestring_first,
375
 
       # poking at _revision_store isn't all that clean, but neither is
376
 
       # having the ui test dependent on the exact overhead of a given store.
377
 
       branch3.repository._revision_store.total_size(
378
 
        branch3.repository.get_transaction())[1] / 1024,
379
401
       ), out)
380
402
        self.assertEqual('', err)
381
403
 
382
404
        # Out of date checkout
383
 
        out, err = self.runbzr('info checkout')
 
405
        out, err = self.run_bzr('info -v checkout')
384
406
        self.assertEqualDiff(
385
 
"""Location:
386
 
       checkout root: %s
387
 
  checkout of branch: %s
 
407
"""Checkout (format: knit)
 
408
Location:
 
409
       checkout root: checkout
 
410
  checkout of branch: standalone
388
411
 
389
412
Format:
390
413
       control: Meta directory format 1
410
433
   first revision: %s
411
434
  latest revision: %s
412
435
 
413
 
Revision store:
 
436
Repository:
414
437
         1 revision
415
 
         %d KiB
416
 
""" % (branch4.bzrdir.root_transport.base,
417
 
       branch1.bzrdir.root_transport.base,
418
 
       branch4.repository._format.get_format_description(),
 
438
""" % (branch4.repository._format.get_format_description(),
419
439
       datestring_first, datestring_first,
420
 
       # poking at _revision_store isn't all that clean, but neither is
421
 
       # having the ui test dependent on the exact overhead of a given store.
422
 
       branch4.repository._revision_store.total_size(
423
 
        branch4.repository.get_transaction())[1] / 1024,
424
440
       ), out)
425
441
        self.assertEqual('', err)
426
442
 
427
443
        # Out of date lightweight checkout
428
 
        out, err = self.runbzr('info lightcheckout --verbose')
 
444
        out, err = self.run_bzr('info lightcheckout --verbose')
429
445
        self.assertEqualDiff(
430
 
"""Location:
431
 
 light checkout root: %s
432
 
  checkout of branch: %s
 
446
"""Lightweight checkout (format: %s)
 
447
Location:
 
448
  light checkout root: lightcheckout
 
449
   checkout of branch: standalone
433
450
 
434
451
Format:
435
452
       control: Meta directory format 1
436
453
  working tree: Working tree format 3
437
 
        branch: Branch format 4
438
 
    repository: Weave repository format 6
 
454
        branch: Branch format 5
 
455
    repository: Knit repository format 1
439
456
 
440
457
Working tree is out of date: missing 1 revision.
441
458
 
451
468
 
452
469
Branch history:
453
470
         2 revisions
454
 
         1 committer
455
471
         0 days old
456
472
   first revision: %s
457
473
  latest revision: %s
458
474
 
459
 
Revision store:
 
475
Repository:
460
476
         2 revisions
461
 
         0 KiB
462
 
""" % (tree5.bzrdir.root_transport.base,
463
 
       branch1.bzrdir.root_transport.base,
464
 
       datestring_first, datestring_last,
465
 
       ), out)
 
477
""" % (format_description, datestring_first, datestring_last,), out)
466
478
        self.assertEqual('', err)
467
479
 
468
480
    def test_info_standalone_no_tree(self):
469
481
        # create standalone branch without a working tree
 
482
        format = bzrdir.format_registry.make_bzrdir('default')
470
483
        branch = self.make_branch('branch')
471
484
        repo = branch.repository
472
 
        out, err = self.runbzr('info branch')
 
485
        out, err = self.run_bzr('info branch -v')
473
486
        self.assertEqualDiff(
474
 
"""Location:
475
 
  branch root: %s
 
487
"""Standalone branch (format: %s)
 
488
Location:
 
489
  branch root: branch
476
490
 
477
491
Format:
478
492
       control: Meta directory format 1
479
 
        branch: Branch format 5
 
493
        branch: %s
480
494
    repository: %s
481
495
 
482
496
Branch history:
483
497
         0 revisions
484
498
 
485
 
Revision store:
 
499
Repository:
486
500
         0 revisions
487
 
         0 KiB
488
 
""" % (branch.bzrdir.root_transport.base,
489
 
       repo._format.get_format_description(),
 
501
""" % (info.describe_format(repo.bzrdir, repo, branch, None),
 
502
       format.get_branch_format().get_format_description(),
 
503
       format.repository_format.get_format_description(),
490
504
       ), out)
491
505
        self.assertEqual('', err)
492
506
 
493
507
    def test_info_shared_repository(self):
494
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
495
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
 
508
        format = bzrdir.format_registry.make_bzrdir('knit')
496
509
        transport = self.get_transport()
497
510
 
498
511
        # Create shared repository
499
 
        repo = self.make_repository('repo', shared=True)
 
512
        repo = self.make_repository('repo', shared=True, format=format)
500
513
        repo.set_make_working_trees(False)
501
 
        out, err = self.runbzr('info repo')
 
514
        out, err = self.run_bzr('info -v repo')
502
515
        self.assertEqualDiff(
503
 
"""Location:
 
516
"""Shared repository (format: dirstate or dirstate-tags or knit)
 
517
Location:
504
518
  shared repository: %s
505
519
 
506
520
Format:
507
521
       control: Meta directory format 1
508
522
    repository: %s
509
523
 
510
 
Revision store:
 
524
Repository:
511
525
         0 revisions
512
 
         0 KiB
513
 
""" % (repo.bzrdir.root_transport.base,
514
 
       repo._format.get_format_description(),
 
526
""" % ('repo', format.repository_format.get_format_description(),
515
527
       ), out)
516
528
        self.assertEqual('', err)
517
529
 
518
530
        # Create branch inside shared repository
519
531
        repo.bzrdir.root_transport.mkdir('branch')
520
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch')
521
 
        out, err = self.runbzr('info repo/branch')
 
532
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
 
533
            format=format)
 
534
        out, err = self.run_bzr('info -v repo/branch')
522
535
        self.assertEqualDiff(
523
 
"""Location:
524
 
  shared repository: %s
525
 
  repository branch: branch
 
536
"""Repository branch (format: dirstate or knit)
 
537
Location:
 
538
  shared repository: repo
 
539
  repository branch: repo/branch
526
540
 
527
541
Format:
528
542
       control: Meta directory format 1
529
 
        branch: Branch format 5
 
543
        branch: %s
530
544
    repository: %s
531
545
 
532
546
Branch history:
533
547
         0 revisions
534
548
 
535
 
Revision store:
 
549
Repository:
536
550
         0 revisions
537
 
         0 KiB
538
 
""" % (repo.bzrdir.root_transport.base,
539
 
       repo._format.get_format_description(),
 
551
""" % (format.get_branch_format().get_format_description(),
 
552
       format.repository_format.get_format_description(),
540
553
       ), out)
541
554
        self.assertEqual('', err)
542
555
 
543
556
        # Create lightweight checkout
544
557
        transport.mkdir('tree')
545
558
        transport.mkdir('tree/lightcheckout')
546
 
        dir2 = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
547
 
        bzrlib.branch.BranchReferenceFormat().initialize(dir2, branch1)
548
 
        dir2.create_workingtree()
549
 
        tree2 = dir2.open_workingtree()
 
559
        tree2 = branch1.create_checkout('tree/lightcheckout',
 
560
            lightweight=True)
550
561
        branch2 = tree2.branch
551
 
        self.assertCheckoutStatusOutput('tree/lightcheckout', tree2, shared_repo=repo)
 
562
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
 
563
                   shared_repo=repo, repo_branch=branch1, verbose=True)
552
564
 
553
565
        # Create normal checkout
554
 
        branch3 = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout')
555
 
        branch3.bind(branch1)
556
 
        tree3 = branch3.bzrdir.open_workingtree()
557
 
        tree3.update()
 
566
        tree3 = branch1.create_checkout('tree/checkout')
558
567
        self.assertCheckoutStatusOutput('tree/checkout --verbose', tree3,
559
568
            verbose=True,
560
569
            light_checkout=False, repo_branch=branch1)
563
572
        tree2.add('a')
564
573
        tree2.commit('commit one')
565
574
        rev = repo.get_revision(branch2.revision_history()[0])
566
 
        datestring_first = format_date(rev.timestamp, rev.timezone)
567
 
        out, err = self.runbzr('info tree/lightcheckout --verbose')
 
575
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
576
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
568
577
        self.assertEqualDiff(
569
 
"""Location:
570
 
 light checkout root: %s
571
 
   shared repository: %s
572
 
   repository branch: branch
 
578
"""Lightweight checkout (format: %s)
 
579
Location:
 
580
  light checkout root: tree/lightcheckout
 
581
   checkout of branch: repo/branch
 
582
    shared repository: repo
573
583
 
574
584
Format:
575
585
       control: Meta directory format 1
576
 
  working tree: Working tree format 3
577
 
        branch: Branch format 5
 
586
  working tree: Working tree format 6
 
587
        branch: %s
578
588
    repository: %s
579
589
 
580
590
In the working tree:
589
599
 
590
600
Branch history:
591
601
         1 revision
592
 
         1 committer
593
602
         0 days old
594
603
   first revision: %s
595
604
  latest revision: %s
596
605
 
597
 
Revision store:
 
606
Repository:
598
607
         1 revision
599
 
         %d KiB
600
 
""" % (tree2.bzrdir.root_transport.base,
601
 
       repo.bzrdir.root_transport.base,
602
 
       repo._format.get_format_description(),
 
608
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
609
       format.repository_format.get_format_description(),
603
610
       datestring_first, datestring_first,
604
 
       # poking at _revision_store isn't all that clean, but neither is
605
 
       # having the ui test dependent on the exact overhead of a given store.
606
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
607
611
       ), out)
608
612
        self.assertEqual('', err)
609
613
 
610
614
        # Out of date checkout
611
 
        out, err = self.runbzr('info tree/checkout')
 
615
        out, err = self.run_bzr('info -v tree/checkout')
612
616
        self.assertEqualDiff(
613
 
"""Location:
614
 
       checkout root: %s
615
 
  checkout of branch: %s
 
617
"""Checkout (format: unnamed)
 
618
Location:
 
619
       checkout root: tree/checkout
 
620
  checkout of branch: repo/branch
616
621
 
617
622
Format:
618
623
       control: Meta directory format 1
619
 
  working tree: Working tree format 3
620
 
        branch: Branch format 5
 
624
  working tree: Working tree format 6
 
625
        branch: %s
621
626
    repository: %s
622
627
 
623
628
Branch is out of date: missing 1 revision.
635
640
Branch history:
636
641
         0 revisions
637
642
 
638
 
Revision store:
 
643
Repository:
639
644
         0 revisions
640
 
         0 KiB
641
 
""" % (tree3.bzrdir.root_transport.base,
642
 
       branch1.bzrdir.root_transport.base,
643
 
       repo._format.get_format_description(),
 
645
""" % (format.get_branch_format().get_format_description(),
 
646
       format.repository_format.get_format_description(),
644
647
       ), out)
645
648
        self.assertEqual('', err)
646
649
 
648
651
        tree3.update()
649
652
        self.build_tree(['tree/checkout/b'])
650
653
        tree3.add('b')
651
 
        out, err = self.runbzr('info tree/checkout --verbose')
 
654
        out, err = self.run_bzr('info tree/checkout --verbose')
652
655
        self.assertEqualDiff(
653
 
"""Location:
654
 
       checkout root: %s
655
 
  checkout of branch: %s
 
656
"""Checkout (format: unnamed)
 
657
Location:
 
658
       checkout root: tree/checkout
 
659
  checkout of branch: repo/branch
656
660
 
657
661
Format:
658
662
       control: Meta directory format 1
659
 
  working tree: Working tree format 3
660
 
        branch: Branch format 5
 
663
  working tree: Working tree format 6
 
664
        branch: %s
661
665
    repository: %s
662
666
 
663
667
In the working tree:
672
676
 
673
677
Branch history:
674
678
         1 revision
675
 
         1 committer
676
679
         0 days old
677
680
   first revision: %s
678
681
  latest revision: %s
679
682
 
680
 
Revision store:
 
683
Repository:
681
684
         1 revision
682
 
         %d KiB
683
 
""" % (tree3.bzrdir.root_transport.base, branch1.bzrdir.root_transport.base,
684
 
       repo._format.get_format_description(),
 
685
""" % (format.get_branch_format().get_format_description(),
 
686
       format.repository_format.get_format_description(),
685
687
       datestring_first, datestring_first,
686
 
       # poking at _revision_store isn't all that clean, but neither is
687
 
       # having the ui test dependent on the exact overhead of a given store.
688
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
689
688
       ), out)
690
689
        self.assertEqual('', err)
691
690
        tree3.commit('commit two')
692
691
 
693
692
        # Out of date lightweight checkout
694
693
        rev = repo.get_revision(branch1.revision_history()[-1])
695
 
        datestring_last = format_date(rev.timestamp, rev.timezone)
696
 
        out, err = self.runbzr('info tree/lightcheckout --verbose')
 
694
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
695
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
697
696
        self.assertEqualDiff(
698
 
"""Location:
699
 
 light checkout root: %s
700
 
   shared repository: %s
701
 
   repository branch: branch
 
697
"""Lightweight checkout (format: %s)
 
698
Location:
 
699
  light checkout root: tree/lightcheckout
 
700
   checkout of branch: repo/branch
 
701
    shared repository: repo
702
702
 
703
703
Format:
704
704
       control: Meta directory format 1
705
 
  working tree: Working tree format 3
706
 
        branch: Branch format 5
 
705
  working tree: Working tree format 6
 
706
        branch: %s
707
707
    repository: %s
708
708
 
709
709
Working tree is out of date: missing 1 revision.
720
720
 
721
721
Branch history:
722
722
         2 revisions
723
 
         1 committer
724
723
         0 days old
725
724
   first revision: %s
726
725
  latest revision: %s
727
726
 
728
 
Revision store:
 
727
Repository:
729
728
         2 revisions
730
 
         %d KiB
731
 
""" % (tree2.bzrdir.root_transport.base,
732
 
       repo.bzrdir.root_transport.base,
733
 
       repo._format.get_format_description(),
 
729
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
730
       format.repository_format.get_format_description(),
734
731
       datestring_first, datestring_last,
735
 
       # poking at _revision_store isn't all that clean, but neither is
736
 
       # having the ui test dependent on the exact overhead of a given store.
737
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
738
732
       ), out)
739
733
        self.assertEqual('', err)
740
734
 
741
735
        # Show info about shared branch
742
 
        out, err = self.runbzr('info repo/branch --verbose')
 
736
        out, err = self.run_bzr('info repo/branch --verbose')
743
737
        self.assertEqualDiff(
744
 
"""Location:
745
 
  shared repository: %s
746
 
  repository branch: branch
 
738
"""Repository branch (format: dirstate or knit)
 
739
Location:
 
740
  shared repository: repo
 
741
  repository branch: repo/branch
747
742
 
748
743
Format:
749
744
       control: Meta directory format 1
750
 
        branch: Branch format 5
 
745
        branch: %s
751
746
    repository: %s
752
747
 
753
748
Branch history:
754
749
         2 revisions
755
 
         1 committer
756
750
         0 days old
757
751
   first revision: %s
758
752
  latest revision: %s
759
753
 
760
 
Revision store:
 
754
Repository:
761
755
         2 revisions
762
 
         %d KiB
763
 
""" % (repo.bzrdir.root_transport.base,
764
 
       repo._format.get_format_description(),
 
756
""" % (format.get_branch_format().get_format_description(),
 
757
       format.repository_format.get_format_description(),
765
758
       datestring_first, datestring_last,
766
 
       # poking at _revision_store isn't all that clean, but neither is
767
 
       # having the ui test dependent on the exact overhead of a given store.
768
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
769
759
       ), out)
770
760
        self.assertEqual('', err)
771
761
 
772
762
        # Show info about repository with revisions
773
 
        out, err = self.runbzr('info repo')
 
763
        out, err = self.run_bzr('info -v repo')
774
764
        self.assertEqualDiff(
775
 
"""Location:
776
 
  shared repository: %s
 
765
"""Shared repository (format: dirstate or dirstate-tags or knit)
 
766
Location:
 
767
  shared repository: repo
777
768
 
778
769
Format:
779
770
       control: Meta directory format 1
780
771
    repository: %s
781
772
 
782
 
Revision store:
 
773
Repository:
783
774
         2 revisions
784
 
         %d KiB
785
 
""" % (repo.bzrdir.root_transport.base,
786
 
       repo._format.get_format_description(),
787
 
       # poking at _revision_store isn't all that clean, but neither is
788
 
       # having the ui test dependent on the exact overhead of a given store.
789
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
 
775
""" % (format.repository_format.get_format_description(),
790
776
       ), out)
791
777
        self.assertEqual('', err)
792
778
 
793
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
794
 
 
795
779
    def test_info_shared_repository_with_trees(self):
796
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
797
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
 
780
        format = bzrdir.format_registry.make_bzrdir('knit')
798
781
        transport = self.get_transport()
799
782
 
800
783
        # Create shared repository with working trees
801
 
        repo = self.make_repository('repo', shared=True)
 
784
        repo = self.make_repository('repo', shared=True, format=format)
802
785
        repo.set_make_working_trees(True)
803
 
        out, err = self.runbzr('info repo')
 
786
        out, err = self.run_bzr('info -v repo')
804
787
        self.assertEqualDiff(
805
 
"""Location:
806
 
  shared repository: %s
 
788
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
789
Location:
 
790
  shared repository: repo
807
791
 
808
792
Format:
809
793
       control: Meta directory format 1
811
795
 
812
796
Create working tree for new branches inside the repository.
813
797
 
814
 
Revision store:
 
798
Repository:
815
799
         0 revisions
816
 
         0 KiB
817
 
""" % (repo.bzrdir.root_transport.base,
818
 
       repo._format.get_format_description(),
 
800
""" % (format.repository_format.get_format_description(),
819
801
       ), out)
820
802
        self.assertEqual('', err)
821
803
 
822
804
        # Create two branches
823
805
        repo.bzrdir.root_transport.mkdir('branch1')
824
 
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1')
 
806
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
807
            format=format)
825
808
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
826
809
 
827
810
        # Empty first branch
828
 
        out, err = self.runbzr('info repo/branch1 --verbose')
 
811
        out, err = self.run_bzr('info repo/branch1 --verbose')
829
812
        self.assertEqualDiff(
830
 
"""Location:
831
 
    shared repository: %s
832
 
  repository checkout: branch1
 
813
"""Repository tree (format: knit)
 
814
Location:
 
815
  shared repository: repo
 
816
  repository branch: repo/branch1
833
817
 
834
818
Format:
835
819
       control: Meta directory format 1
836
820
  working tree: Working tree format 3
837
 
        branch: Branch format 5
 
821
        branch: %s
838
822
    repository: %s
839
823
 
840
824
In the working tree:
849
833
 
850
834
Branch history:
851
835
         0 revisions
852
 
         0 committers
853
836
 
854
 
Revision store:
 
837
Repository:
855
838
         0 revisions
856
 
         0 KiB
857
 
""" % (repo.bzrdir.root_transport.base,
858
 
       repo._format.get_format_description(),
 
839
""" % (format.get_branch_format().get_format_description(),
 
840
       format.repository_format.get_format_description(),
859
841
       ), out)
860
842
        self.assertEqual('', err)
861
843
 
865
847
        tree1.add('a')
866
848
        tree1.commit('commit one')
867
849
        rev = repo.get_revision(branch1.revision_history()[0])
868
 
        datestring_first = format_date(rev.timestamp, rev.timezone)
869
 
        out, err = self.runbzr('info repo/branch1')
 
850
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
851
        out, err = self.run_bzr('info -v repo/branch1')
870
852
        self.assertEqualDiff(
871
 
"""Location:
872
 
    shared repository: %s
873
 
  repository checkout: branch1
 
853
"""Repository tree (format: knit)
 
854
Location:
 
855
  shared repository: repo
 
856
  repository branch: repo/branch1
874
857
 
875
858
Format:
876
859
       control: Meta directory format 1
877
860
  working tree: Working tree format 3
878
 
        branch: Branch format 5
 
861
        branch: %s
879
862
    repository: %s
880
863
 
881
864
In the working tree:
894
877
   first revision: %s
895
878
  latest revision: %s
896
879
 
897
 
Revision store:
 
880
Repository:
898
881
         1 revision
899
 
         %d KiB
900
 
""" % (repo.bzrdir.root_transport.base,
901
 
       repo._format.get_format_description(),
 
882
""" % (format.get_branch_format().get_format_description(),
 
883
       format.repository_format.get_format_description(),
902
884
       datestring_first, datestring_first,
903
 
       # poking at _revision_store isn't all that clean, but neither is
904
 
       # having the ui test dependent on the exact overhead of a given store.
905
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
906
885
       ), out)
907
886
        self.assertEqual('', err)
908
887
 
909
888
        # Out of date second branch
910
 
        out, err = self.runbzr('info repo/branch2 --verbose')
 
889
        out, err = self.run_bzr('info repo/branch2 --verbose')
911
890
        self.assertEqualDiff(
912
 
"""Location:
913
 
    shared repository: %s
914
 
  repository checkout: branch2
 
891
"""Repository tree (format: knit)
 
892
Location:
 
893
  shared repository: repo
 
894
  repository branch: repo/branch2
915
895
 
916
896
Related branches:
917
 
  parent branch: %s
 
897
  parent branch: repo/branch1
918
898
 
919
899
Format:
920
900
       control: Meta directory format 1
921
901
  working tree: Working tree format 3
922
 
        branch: Branch format 5
 
902
        branch: %s
923
903
    repository: %s
924
904
 
925
905
In the working tree:
934
914
 
935
915
Branch history:
936
916
         0 revisions
937
 
         0 committers
938
917
 
939
 
Revision store:
 
918
Repository:
940
919
         1 revision
941
 
         %d KiB
942
 
""" % (repo.bzrdir.root_transport.base,
943
 
       branch1.bzrdir.root_transport.base,
944
 
       repo._format.get_format_description(),
945
 
       # poking at _revision_store isn't all that clean, but neither is
946
 
       # having the ui test dependent on the exact overhead of a given store.
947
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
 
920
""" % (format.get_branch_format().get_format_description(),
 
921
       format.repository_format.get_format_description(),
948
922
       ), out)
949
923
        self.assertEqual('', err)
950
924
 
951
925
        # Update second branch
952
926
        tree2 = branch2.bzrdir.open_workingtree()
953
927
        tree2.pull(branch1)
954
 
        out, err = self.runbzr('info repo/branch2')
 
928
        out, err = self.run_bzr('info -v repo/branch2')
955
929
        self.assertEqualDiff(
956
 
"""Location:
957
 
    shared repository: %s
958
 
  repository checkout: branch2
 
930
"""Repository tree (format: knit)
 
931
Location:
 
932
  shared repository: repo
 
933
  repository branch: repo/branch2
959
934
 
960
935
Related branches:
961
 
  parent branch: %s
 
936
  parent branch: repo/branch1
962
937
 
963
938
Format:
964
939
       control: Meta directory format 1
965
940
  working tree: Working tree format 3
966
 
        branch: Branch format 5
 
941
        branch: %s
967
942
    repository: %s
968
943
 
969
944
In the working tree:
982
957
   first revision: %s
983
958
  latest revision: %s
984
959
 
985
 
Revision store:
 
960
Repository:
986
961
         1 revision
987
 
         %d KiB
988
 
""" % (repo.bzrdir.root_transport.base,
989
 
       branch1.bzrdir.root_transport.base,
990
 
       repo._format.get_format_description(),
 
962
""" % (format.get_branch_format().get_format_description(),
 
963
       format.repository_format.get_format_description(),
991
964
       datestring_first, datestring_first,
992
 
       # poking at _revision_store isn't all that clean, but neither is
993
 
       # having the ui test dependent on the exact overhead of a given store.
994
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
995
965
       ), out)
996
966
        self.assertEqual('', err)
997
967
 
998
968
        # Show info about repository with revisions
999
 
        out, err = self.runbzr('info repo')
 
969
        out, err = self.run_bzr('info -v repo')
1000
970
        self.assertEqualDiff(
1001
 
"""Location:
1002
 
  shared repository: %s
 
971
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
972
Location:
 
973
  shared repository: repo
1003
974
 
1004
975
Format:
1005
976
       control: Meta directory format 1
1007
978
 
1008
979
Create working tree for new branches inside the repository.
1009
980
 
1010
 
Revision store:
 
981
Repository:
1011
982
         1 revision
1012
 
         %d KiB
1013
 
""" % (repo.bzrdir.root_transport.base,
1014
 
       repo._format.get_format_description(),
1015
 
       # poking at _revision_store isn't all that clean, but neither is
1016
 
       # having the ui test dependent on the exact overhead of a given store.
1017
 
       repo._revision_store.total_size(repo.get_transaction())[1] / 1024,
 
983
""" % (format.repository_format.get_format_description(),
1018
984
       ),
1019
985
       out)
1020
986
        self.assertEqual('', err)
1021
987
 
1022
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
1023
 
    
1024
988
    def test_info_shared_repository_with_tree_in_root(self):
1025
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
1026
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrlib.bzrdir.BzrDirMetaFormat1())
 
989
        format = bzrdir.format_registry.make_bzrdir('knit')
1027
990
        transport = self.get_transport()
1028
991
 
1029
992
        # Create shared repository with working trees
1030
 
        repo = self.make_repository('repo', shared=True)
 
993
        repo = self.make_repository('repo', shared=True, format=format)
1031
994
        repo.set_make_working_trees(True)
1032
 
        out, err = self.runbzr('info repo')
 
995
        out, err = self.run_bzr('info -v repo')
1033
996
        self.assertEqualDiff(
1034
 
"""Location:
1035
 
  shared repository: %s
 
997
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
998
Location:
 
999
  shared repository: repo
1036
1000
 
1037
1001
Format:
1038
1002
       control: Meta directory format 1
1040
1004
 
1041
1005
Create working tree for new branches inside the repository.
1042
1006
 
1043
 
Revision store:
 
1007
Repository:
1044
1008
         0 revisions
1045
 
         0 KiB
1046
 
""" % (repo.bzrdir.root_transport.base,
1047
 
       repo._format.get_format_description(),
 
1009
""" % (format.repository_format.get_format_description(),
1048
1010
       ), out)
1049
1011
        self.assertEqual('', err)
1050
1012
 
1052
1014
        control = repo.bzrdir
1053
1015
        branch = control.create_branch()
1054
1016
        control.create_workingtree()
1055
 
        out, err = self.runbzr('info repo')
 
1017
        out, err = self.run_bzr('info -v repo')
1056
1018
        self.assertEqualDiff(
1057
 
"""Location:
1058
 
    shared repository: %s
1059
 
  repository checkout: .
 
1019
"""Repository tree (format: knit)
 
1020
Location:
 
1021
  shared repository: repo
 
1022
  repository branch: repo
1060
1023
 
1061
1024
Format:
1062
1025
       control: Meta directory format 1
1063
1026
  working tree: Working tree format 3
1064
 
        branch: Branch format 5
 
1027
        branch: %s
1065
1028
    repository: %s
1066
1029
 
1067
1030
In the working tree:
1077
1040
Branch history:
1078
1041
         0 revisions
1079
1042
 
1080
 
Revision store:
1081
 
         0 revisions
1082
 
         0 KiB
1083
 
""" % (repo.bzrdir.root_transport.base,
1084
 
       repo._format.get_format_description(),
1085
 
       ), out)
1086
 
        self.assertEqual('', err)
1087
 
 
1088
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
1089
 
 
1090
 
    def assertCheckoutStatusOutput(self, 
 
1043
Repository:
 
1044
         0 revisions
 
1045
""" % (format.get_branch_format().get_format_description(),
 
1046
       format.repository_format.get_format_description(),
 
1047
       ), out)
 
1048
        self.assertEqual('', err)
 
1049
 
 
1050
    def test_info_repository_hook(self):
 
1051
        format = bzrdir.format_registry.make_bzrdir('knit')
 
1052
        def repo_info(repo, stats, outf):
 
1053
            outf.write("more info\n")
 
1054
        info.hooks.install_named_hook('repository', repo_info, None)
 
1055
        # Create shared repository with working trees
 
1056
        repo = self.make_repository('repo', shared=True, format=format)
 
1057
        out, err = self.run_bzr('info -v repo')
 
1058
        self.assertEqualDiff(
 
1059
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
1060
Location:
 
1061
  shared repository: repo
 
1062
 
 
1063
Format:
 
1064
       control: Meta directory format 1
 
1065
    repository: %s
 
1066
 
 
1067
Create working tree for new branches inside the repository.
 
1068
 
 
1069
Repository:
 
1070
         0 revisions
 
1071
more info
 
1072
""" % (format.repository_format.get_format_description(),
 
1073
       ), out)
 
1074
        self.assertEqual('', err)
 
1075
 
 
1076
    def assertCheckoutStatusOutput(self,
1091
1077
        command_string, lco_tree, shared_repo=None,
1092
1078
        repo_branch=None,
1093
1079
        tree_locked=False,
1094
1080
        branch_locked=False, repo_locked=False,
1095
1081
        verbose=False,
1096
 
        light_checkout=True):
1097
 
        """Check the output of info in a light checkout tree.
 
1082
        light_checkout=True,
 
1083
        checkout_root=None):
 
1084
        """Check the output of info in a checkout.
1098
1085
 
1099
1086
        This is not quite a mirror of the info code: rather than using the
1100
1087
        tree being examined to predict output, it uses a bunch of flags which
1101
1088
        allow us, the test writers, to document what *should* be present in
1102
1089
        the output. Removing this separation would remove the value of the
1103
1090
        tests.
1104
 
        
 
1091
 
1105
1092
        :param path: the path to the light checkout.
1106
1093
        :param lco_tree: the tree object for the light checkout.
1107
1094
        :param shared_repo: A shared repository is in use, expect that in
1111
1098
        :param tree_locked: If true, expect the tree to be locked.
1112
1099
        :param branch_locked: If true, expect the branch to be locked.
1113
1100
        :param repo_locked: If true, expect the repository to be locked.
1114
 
        :param verbose: If true, expect verbose output
 
1101
            Note that the lco_tree.branch.repository is inspected, and if is not
 
1102
            actually locked then this parameter is overridden. This is because
 
1103
            pack repositories do not have any public API for obtaining an
 
1104
            exclusive repository wide lock.
 
1105
        :param verbose: verbosity level: 2 or higher to show committers
1115
1106
        """
1116
 
        out, err = self.runbzr('info %s' % command_string)
 
1107
        def friendly_location(url):
 
1108
            path = urlutils.unescape_for_display(url, 'ascii')
 
1109
            try:
 
1110
                return osutils.relpath(osutils.getcwd(), path)
 
1111
            except errors.PathNotChild:
 
1112
                return path
 
1113
 
 
1114
        if tree_locked:
 
1115
            # We expect this to fail because of locking errors.
 
1116
            # (A write-locked file cannot be read-locked
 
1117
            # in the different process -- either on win32 or on linux).
 
1118
            # This should be removed when the locking errors are fixed.
 
1119
            self.expectFailure('OS locks are exclusive '
 
1120
                'for different processes (Bug #174055)',
 
1121
                self.run_bzr_subprocess,
 
1122
                'info ' + command_string)
 
1123
        out, err = self.run_bzr('info %s' % command_string)
 
1124
        description = {
 
1125
            (True, True): 'Lightweight checkout',
 
1126
            (True, False): 'Repository checkout',
 
1127
            (False, True): 'Lightweight checkout',
 
1128
            (False, False): 'Checkout',
 
1129
            }[(shared_repo is not None, light_checkout)]
 
1130
        format = {True: self._repo_strings,
 
1131
                  False: 'unnamed'}[light_checkout]
 
1132
        if repo_locked:
 
1133
            repo_locked = lco_tree.branch.repository.get_physical_lock_status()
1117
1134
        if repo_locked or branch_locked or tree_locked:
1118
1135
            def locked_message(a_bool):
1119
1136
                if a_bool:
1131
1148
                    locked_message(repo_locked)))
1132
1149
        else:
1133
1150
            expected_lock_output = ''
 
1151
        tree_data = ''
 
1152
        extra_space = ''
1134
1153
        if light_checkout:
1135
 
            tree_data = (" light checkout root: %s" %
1136
 
                lco_tree.bzrdir.root_transport.base)
1137
 
        else:
1138
 
            tree_data = ("       checkout root: %s" %
1139
 
                lco_tree.bzrdir.root_transport.base)
 
1154
            tree_data = ("  light checkout root: %s\n" %
 
1155
                friendly_location(lco_tree.bzrdir.root_transport.base))
 
1156
            extra_space = ' '
 
1157
        if lco_tree.branch.get_bound_location() is not None:
 
1158
            tree_data += ("%s       checkout root: %s\n" % (extra_space,
 
1159
                friendly_location(lco_tree.branch.bzrdir.root_transport.base)))
1140
1160
        if shared_repo is not None:
1141
1161
            branch_data = (
1142
 
                "   shared repository: %s\n"
1143
 
                "   repository branch: branch\n" %
1144
 
                shared_repo.bzrdir.root_transport.base)
 
1162
                "   checkout of branch: %s\n"
 
1163
                "    shared repository: %s\n" %
 
1164
                (friendly_location(repo_branch.bzrdir.root_transport.base),
 
1165
                 friendly_location(shared_repo.bzrdir.root_transport.base)))
1145
1166
        elif repo_branch is not None:
1146
1167
            branch_data = (
1147
 
                "  checkout of branch: %s\n" % 
1148
 
                repo_branch.bzrdir.root_transport.base)
 
1168
                "%s  checkout of branch: %s\n" %
 
1169
                (extra_space,
 
1170
                 friendly_location(repo_branch.bzrdir.root_transport.base)))
1149
1171
        else:
1150
 
            branch_data = ("  checkout of branch: %s\n" % 
 
1172
            branch_data = ("   checkout of branch: %s\n" %
1151
1173
                lco_tree.branch.bzrdir.root_transport.base)
1152
 
        
1153
 
        if verbose:
 
1174
 
 
1175
        if verbose >= 2:
1154
1176
            verbose_info = '         0 committers\n'
1155
1177
        else:
1156
1178
            verbose_info = ''
1157
 
            
 
1179
 
1158
1180
        self.assertEqualDiff(
1159
 
"""Location:
1160
 
%s
1161
 
%s
 
1181
"""%s (format: %s)
 
1182
Location:
 
1183
%s%s
1162
1184
Format:
1163
1185
       control: Meta directory format 1
1164
1186
  working tree: %s
1165
 
        branch: Branch format 5
 
1187
        branch: %s
1166
1188
    repository: %s
1167
1189
%s
1168
1190
In the working tree:
1178
1200
Branch history:
1179
1201
         0 revisions
1180
1202
%s
1181
 
Revision store:
 
1203
Repository:
1182
1204
         0 revisions
1183
 
         0 KiB
1184
 
""" %  (tree_data,
 
1205
""" %  (description,
 
1206
        format,
 
1207
        tree_data,
1185
1208
        branch_data,
1186
1209
        lco_tree._format.get_format_description(),
 
1210
        lco_tree.branch._format.get_format_description(),
1187
1211
        lco_tree.branch.repository._format.get_format_description(),
1188
1212
        expected_lock_output,
1189
1213
        verbose_info,
1194
1218
        transport = self.get_transport()
1195
1219
        # Create shared repository with a branch
1196
1220
        repo = self.make_repository('repo', shared=True,
1197
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1221
                                    format=bzrdir.BzrDirMetaFormat1())
1198
1222
        repo.set_make_working_trees(False)
1199
1223
        repo.bzrdir.root_transport.mkdir('branch')
1200
1224
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
1201
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1225
                                    format=bzrdir.BzrDirMetaFormat1())
1202
1226
        # Do a heavy checkout
1203
1227
        transport.mkdir('tree')
1204
1228
        transport.mkdir('tree/checkout')
1205
 
        co_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience('tree/checkout',
1206
 
                                    format=bzrlib.bzrdir.BzrDirMetaFormat1())
 
1229
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
 
1230
            format=bzrdir.BzrDirMetaFormat1())
1207
1231
        co_branch.bind(repo_branch)
1208
1232
        # Do a light checkout of the heavy one
1209
1233
        transport.mkdir('tree/lightcheckout')
1210
 
        lco_dir = bzrlib.bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
1211
 
        bzrlib.branch.BranchReferenceFormat().initialize(lco_dir, co_branch)
 
1234
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
 
1235
        branch.BranchReferenceFormat().initialize(lco_dir,
 
1236
            target_branch=co_branch)
1212
1237
        lco_dir.create_workingtree()
1213
1238
        lco_tree = lco_dir.open_workingtree()
1214
1239
 
1216
1241
        # W B R
1217
1242
 
1218
1243
        # U U U
1219
 
        self.assertCheckoutStatusOutput('tree/lightcheckout', lco_tree)
 
1244
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree,
 
1245
                                        repo_branch=repo_branch,
 
1246
                                        verbose=True, light_checkout=True)
1220
1247
        # U U L
1221
1248
        lco_tree.branch.repository.lock_write()
1222
1249
        try:
1223
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
1224
 
            lco_tree,
1225
 
            repo_locked=True)
 
1250
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1251
            lco_tree, repo_branch=repo_branch,
 
1252
            repo_locked=True, verbose=True, light_checkout=True)
1226
1253
        finally:
1227
1254
            lco_tree.branch.repository.unlock()
1228
1255
        # U L L
1229
1256
        lco_tree.branch.lock_write()
1230
1257
        try:
1231
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
 
1258
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
1232
1259
            lco_tree,
1233
1260
            branch_locked=True,
1234
 
            repo_locked=True)
 
1261
            repo_locked=True,
 
1262
            repo_branch=repo_branch,
 
1263
            verbose=True)
1235
1264
        finally:
1236
1265
            lco_tree.branch.unlock()
1237
1266
        # L L L
1238
1267
        lco_tree.lock_write()
1239
1268
        try:
1240
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
1241
 
            lco_tree,
 
1269
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1270
            lco_tree, repo_branch=repo_branch,
1242
1271
            tree_locked=True,
1243
1272
            branch_locked=True,
1244
 
            repo_locked=True)
 
1273
            repo_locked=True,
 
1274
            verbose=True)
1245
1275
        finally:
1246
1276
            lco_tree.unlock()
1247
1277
        # L L U
1248
1278
        lco_tree.lock_write()
1249
1279
        lco_tree.branch.repository.unlock()
1250
1280
        try:
1251
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
1252
 
            lco_tree,
 
1281
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1282
            lco_tree, repo_branch=repo_branch,
1253
1283
            tree_locked=True,
1254
 
            branch_locked=True)
 
1284
            branch_locked=True,
 
1285
            verbose=True)
1255
1286
        finally:
1256
1287
            lco_tree.branch.repository.lock_write()
1257
1288
            lco_tree.unlock()
1259
1290
        lco_tree.lock_write()
1260
1291
        lco_tree.branch.unlock()
1261
1292
        try:
1262
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
1263
 
            lco_tree,
1264
 
            tree_locked=True)
 
1293
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1294
            lco_tree, repo_branch=repo_branch,
 
1295
            tree_locked=True,
 
1296
            verbose=True)
1265
1297
        finally:
1266
1298
            lco_tree.branch.lock_write()
1267
1299
            lco_tree.unlock()
1270
1302
        lco_tree.branch.unlock()
1271
1303
        lco_tree.branch.repository.lock_write()
1272
1304
        try:
1273
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
1274
 
            lco_tree,
 
1305
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1306
            lco_tree, repo_branch=repo_branch,
1275
1307
            tree_locked=True,
1276
 
            repo_locked=True)
 
1308
            repo_locked=True,
 
1309
            verbose=True)
1277
1310
        finally:
1278
1311
            lco_tree.branch.repository.unlock()
1279
1312
            lco_tree.branch.lock_write()
1282
1315
        lco_tree.branch.lock_write()
1283
1316
        lco_tree.branch.repository.unlock()
1284
1317
        try:
1285
 
            self.assertCheckoutStatusOutput('tree/lightcheckout',
1286
 
            lco_tree,
1287
 
            branch_locked=True)
 
1318
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1319
            lco_tree, repo_branch=repo_branch,
 
1320
            branch_locked=True,
 
1321
            verbose=True)
1288
1322
        finally:
1289
1323
            lco_tree.branch.repository.lock_write()
1290
1324
            lco_tree.branch.unlock()
1291
1325
 
1292
 
    def test_info_locking_oslocks(self):
1293
 
        if sys.platform == "win32":
1294
 
            raise TestSkipped("don't use oslocks on win32 in unix manner")
1295
 
 
1296
 
        tree = self.make_branch_and_tree('branch',
1297
 
                                         format=bzrlib.bzrdir.BzrDirFormat6())
1298
 
 
1299
 
        # Test all permutations of locking the working tree, branch and repository
1300
 
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
1301
 
        # implemented by raising NotImplementedError and get_physical_lock_status()
1302
 
        # always returns false. This makes bzr info hide the lock status.  (Olaf)
1303
 
        # W B R
1304
 
 
1305
 
        # U U U
1306
 
        out, err = self.runbzr('info branch')
1307
 
        self.assertEqualDiff(
1308
 
"""Location:
1309
 
  branch root: %s
1310
 
 
1311
 
Format:
1312
 
       control: All-in-one format 6
1313
 
  working tree: Working tree format 2
1314
 
        branch: Branch format 4
1315
 
    repository: %s
1316
 
 
1317
 
In the working tree:
1318
 
         0 unchanged
1319
 
         0 modified
1320
 
         0 added
1321
 
         0 removed
1322
 
         0 renamed
1323
 
         0 unknown
1324
 
         0 ignored
1325
 
         0 versioned subdirectories
1326
 
 
1327
 
Branch history:
1328
 
         0 revisions
1329
 
 
1330
 
Revision store:
1331
 
         0 revisions
1332
 
         0 KiB
1333
 
""" % (tree.bzrdir.root_transport.base,
1334
 
       tree.branch.repository._format.get_format_description(),
1335
 
       ), out)
1336
 
        self.assertEqual('', err)
1337
 
        # L L L
1338
 
        tree.lock_write()
1339
 
        out, err = self.runbzr('info branch')
1340
 
        self.assertEqualDiff(
1341
 
"""Location:
1342
 
  branch root: %s
1343
 
 
1344
 
Format:
1345
 
       control: All-in-one format 6
1346
 
  working tree: Working tree format 2
1347
 
        branch: Branch format 4
1348
 
    repository: %s
1349
 
 
1350
 
In the working tree:
1351
 
         0 unchanged
1352
 
         0 modified
1353
 
         0 added
1354
 
         0 removed
1355
 
         0 renamed
1356
 
         0 unknown
1357
 
         0 ignored
1358
 
         0 versioned subdirectories
1359
 
 
1360
 
Branch history:
1361
 
         0 revisions
1362
 
 
1363
 
Revision store:
1364
 
         0 revisions
1365
 
         0 KiB
1366
 
""" % (tree.bzrdir.root_transport.base,
1367
 
       tree.branch.repository._format.get_format_description(),
1368
 
       ), out)
1369
 
        self.assertEqual('', err)
1370
 
        tree.unlock()
 
1326
        if sys.platform == 'win32':
 
1327
            self.knownFailure('Win32 cannot run "bzr info"'
 
1328
                              ' when the tree is locked.')
 
1329
 
 
1330
    def test_info_stacked(self):
 
1331
        # We have a mainline
 
1332
        trunk_tree = self.make_branch_and_tree('mainline',
 
1333
            format='1.6')
 
1334
        trunk_tree.commit('mainline')
 
1335
        # and a branch from it which is stacked
 
1336
        new_dir = trunk_tree.bzrdir.sprout('newbranch', stacked=True)
 
1337
        out, err = self.run_bzr('info newbranch')
 
1338
        self.assertEqual(
 
1339
"""Standalone tree (format: 1.6)
 
1340
Location:
 
1341
  branch root: newbranch
 
1342
 
 
1343
Related branches:
 
1344
  parent branch: mainline
 
1345
     stacked on: mainline
 
1346
""", out)
 
1347
        self.assertEqual("", err)