~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-04-11 09:38:59 UTC
  • mfrom: (5609.33.1 2.3)
  • mto: This revision was merged to the branch mainline in revision 5783.
  • Revision ID: v.ladeuil+lp@free.fr-20110411093859-0gyunr0tkvnoskrm
Merge 2.3 to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2010 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Tests for the info command of bzr."""
 
19
 
 
20
import sys
 
21
 
 
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"
 
40
 
 
41
    def test_info_non_existing(self):
 
42
        self.vfs_transport_factory = memory.MemoryServer
 
43
        location = self.get_url()
 
44
        out, err = self.run_bzr('info '+location, retcode=3)
 
45
        self.assertEqual(out, '')
 
46
        self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
 
47
 
 
48
    def test_info_standalone(self):
 
49
        transport = self.get_transport()
 
50
 
 
51
        # Create initial standalone branch
 
52
        tree1 = self.make_branch_and_tree('standalone', 'knit')
 
53
        self.build_tree(['standalone/a'])
 
54
        tree1.add('a')
 
55
        branch1 = tree1.branch
 
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)
 
126
        self.assertEqual('', err)
 
127
        tree1.commit('commit one')
 
128
        rev = branch1.repository.get_revision(branch1.revision_history()[0])
 
129
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
130
 
 
131
        # Branch standalone with push location
 
132
        branch2 = branch1.bzrdir.sprout('branch').open_branch()
 
133
        branch2.set_push_location(branch1.bzrdir.root_transport.base)
 
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
 
156
 
 
157
Format:
 
158
       control: Meta directory format 1
 
159
  working tree: Working tree format 3
 
160
        branch: Branch format 5
 
161
    repository: Knit repository format 1
 
162
 
 
163
In the working tree:
 
164
         1 unchanged
 
165
         0 modified
 
166
         0 added
 
167
         0 removed
 
168
         0 renamed
 
169
         0 unknown
 
170
         0 ignored
 
171
         0 versioned subdirectories
 
172
 
 
173
Branch history:
 
174
         1 revision
 
175
         0 days old
 
176
   first revision: %s
 
177
  latest revision: %s
 
178
 
 
179
Repository:
 
180
         1 revision
 
181
""" % (datestring_first, datestring_first,
 
182
       ), out)
 
183
        self.assertEqual('', err)
 
184
 
 
185
        # Branch and bind to standalone, needs upgrade to metadir
 
186
        # (creates backup as unknown)
 
187
        branch1.bzrdir.sprout('bound')
 
188
        knit1_format = bzrdir.format_registry.make_bzrdir('knit')
 
189
        upgrade.upgrade('bound', knit1_format)
 
190
        branch3 = bzrdir.BzrDir.open('bound').open_branch()
 
191
        branch3.bind(branch1)
 
192
        bound_tree = branch3.bzrdir.open_workingtree()
 
193
        out, err = self.run_bzr('info -v bound')
 
194
        self.assertEqualDiff(
 
195
"""Checkout (format: knit)
 
196
Location:
 
197
       checkout root: bound
 
198
  checkout of branch: standalone
 
199
 
 
200
Related branches:
 
201
  parent branch: standalone
 
202
 
 
203
Format:
 
204
       control: Meta directory format 1
 
205
  working tree: %s
 
206
        branch: %s
 
207
    repository: %s
 
208
 
 
209
In the working tree:
 
210
         1 unchanged
 
211
         0 modified
 
212
         0 added
 
213
         0 removed
 
214
         0 renamed
 
215
         0 unknown
 
216
         0 ignored
 
217
         0 versioned subdirectories
 
218
 
 
219
Branch history:
 
220
         1 revision
 
221
         0 days old
 
222
   first revision: %s
 
223
  latest revision: %s
 
224
 
 
225
Repository:
 
226
         1 revision
 
227
""" % (bound_tree._format.get_format_description(),
 
228
       branch3._format.get_format_description(),
 
229
       branch3.repository._format.get_format_description(),
 
230
       datestring_first, datestring_first,
 
231
       ), out)
 
232
        self.assertEqual('', err)
 
233
 
 
234
        # Checkout standalone (same as above, but does not have parent set)
 
235
        branch4 = bzrdir.BzrDir.create_branch_convenience('checkout',
 
236
            format=knit1_format)
 
237
        branch4.bind(branch1)
 
238
        branch4.bzrdir.open_workingtree().update()
 
239
        out, err = self.run_bzr('info checkout --verbose')
 
240
        self.assertEqualDiff(
 
241
"""Checkout (format: knit)
 
242
Location:
 
243
       checkout root: checkout
 
244
  checkout of branch: standalone
 
245
 
 
246
Format:
 
247
       control: Meta directory format 1
 
248
  working tree: Working tree format 3
 
249
        branch: Branch format 5
 
250
    repository: %s
 
251
 
 
252
In the working tree:
 
253
         1 unchanged
 
254
         0 modified
 
255
         0 added
 
256
         0 removed
 
257
         0 renamed
 
258
         0 unknown
 
259
         0 ignored
 
260
         0 versioned subdirectories
 
261
 
 
262
Branch history:
 
263
         1 revision
 
264
         0 days old
 
265
   first revision: %s
 
266
  latest revision: %s
 
267
 
 
268
Repository:
 
269
         1 revision
 
270
""" % (branch4.repository._format.get_format_description(),
 
271
       datestring_first, datestring_first,
 
272
       ), out)
 
273
        self.assertEqual('', err)
 
274
 
 
275
        # Lightweight checkout (same as above, different branch and repository)
 
276
        tree5 = branch1.create_checkout('lightcheckout', lightweight=True)
 
277
        branch5 = tree5.branch
 
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"
 
283
        self.assertEqualDiff(
 
284
"""Lightweight checkout (format: %s)
 
285
Location:
 
286
  light checkout root: lightcheckout
 
287
   checkout of branch: standalone
 
288
 
 
289
Format:
 
290
       control: Meta directory format 1
 
291
  working tree: Working tree format 3
 
292
        branch: Branch format 5
 
293
    repository: Knit repository format 1
 
294
 
 
295
In the working tree:
 
296
         1 unchanged
 
297
         0 modified
 
298
         0 added
 
299
         0 removed
 
300
         0 renamed
 
301
         0 unknown
 
302
         0 ignored
 
303
         0 versioned subdirectories
 
304
 
 
305
Branch history:
 
306
         1 revision
 
307
         0 days old
 
308
   first revision: %s
 
309
  latest revision: %s
 
310
 
 
311
Repository:
 
312
         1 revision
 
313
""" % (format_description, datestring_first, datestring_first,), out)
 
314
        self.assertEqual('', err)
 
315
 
 
316
        # Update initial standalone branch
 
317
        self.build_tree(['standalone/b'])
 
318
        tree1.add('b')
 
319
        tree1.commit('commit two')
 
320
        rev = branch1.repository.get_revision(branch1.revision_history()[-1])
 
321
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
322
 
 
323
        # Out of date branched standalone branch will not be detected
 
324
        out, err = self.run_bzr('info -v branch')
 
325
        self.assertEqualDiff(
 
326
"""Standalone tree (format: knit)
 
327
Location:
 
328
  branch root: branch
 
329
 
 
330
Related branches:
 
331
    push branch: standalone
 
332
  parent branch: standalone
 
333
 
 
334
Format:
 
335
       control: Meta directory format 1
 
336
  working tree: Working tree format 3
 
337
        branch: Branch format 5
 
338
    repository: Knit repository format 1
 
339
 
 
340
In the working tree:
 
341
         1 unchanged
 
342
         0 modified
 
343
         0 added
 
344
         0 removed
 
345
         0 renamed
 
346
         0 unknown
 
347
         0 ignored
 
348
         0 versioned subdirectories
 
349
 
 
350
Branch history:
 
351
         1 revision
 
352
         0 days old
 
353
   first revision: %s
 
354
  latest revision: %s
 
355
 
 
356
Repository:
 
357
         1 revision
 
358
""" % (datestring_first, datestring_first,
 
359
       ), out)
 
360
        self.assertEqual('', err)
 
361
 
 
362
        # Out of date bound branch
 
363
        out, err = self.run_bzr('info -v bound')
 
364
        self.assertEqualDiff(
 
365
"""Checkout (format: knit)
 
366
Location:
 
367
       checkout root: bound
 
368
  checkout of branch: standalone
 
369
 
 
370
Related branches:
 
371
  parent branch: standalone
 
372
 
 
373
Format:
 
374
       control: Meta directory format 1
 
375
  working tree: Working tree format 3
 
376
        branch: Branch format 5
 
377
    repository: %s
 
378
 
 
379
Branch is out of date: missing 1 revision.
 
380
 
 
381
In the working tree:
 
382
         1 unchanged
 
383
         0 modified
 
384
         0 added
 
385
         0 removed
 
386
         0 renamed
 
387
         0 unknown
 
388
         0 ignored
 
389
         0 versioned subdirectories
 
390
 
 
391
Branch history:
 
392
         1 revision
 
393
         0 days old
 
394
   first revision: %s
 
395
  latest revision: %s
 
396
 
 
397
Repository:
 
398
         1 revision
 
399
""" % (branch3.repository._format.get_format_description(),
 
400
       datestring_first, datestring_first,
 
401
       ), out)
 
402
        self.assertEqual('', err)
 
403
 
 
404
        # Out of date checkout
 
405
        out, err = self.run_bzr('info -v checkout')
 
406
        self.assertEqualDiff(
 
407
"""Checkout (format: knit)
 
408
Location:
 
409
       checkout root: checkout
 
410
  checkout of branch: standalone
 
411
 
 
412
Format:
 
413
       control: Meta directory format 1
 
414
  working tree: Working tree format 3
 
415
        branch: Branch format 5
 
416
    repository: %s
 
417
 
 
418
Branch is out of date: missing 1 revision.
 
419
 
 
420
In the working tree:
 
421
         1 unchanged
 
422
         0 modified
 
423
         0 added
 
424
         0 removed
 
425
         0 renamed
 
426
         0 unknown
 
427
         0 ignored
 
428
         0 versioned subdirectories
 
429
 
 
430
Branch history:
 
431
         1 revision
 
432
         0 days old
 
433
   first revision: %s
 
434
  latest revision: %s
 
435
 
 
436
Repository:
 
437
         1 revision
 
438
""" % (branch4.repository._format.get_format_description(),
 
439
       datestring_first, datestring_first,
 
440
       ), out)
 
441
        self.assertEqual('', err)
 
442
 
 
443
        # Out of date lightweight checkout
 
444
        out, err = self.run_bzr('info lightcheckout --verbose')
 
445
        self.assertEqualDiff(
 
446
"""Lightweight checkout (format: %s)
 
447
Location:
 
448
  light checkout root: lightcheckout
 
449
   checkout of branch: standalone
 
450
 
 
451
Format:
 
452
       control: Meta directory format 1
 
453
  working tree: Working tree format 3
 
454
        branch: Branch format 5
 
455
    repository: Knit repository format 1
 
456
 
 
457
Working tree is out of date: missing 1 revision.
 
458
 
 
459
In the working tree:
 
460
         1 unchanged
 
461
         0 modified
 
462
         0 added
 
463
         0 removed
 
464
         0 renamed
 
465
         0 unknown
 
466
         0 ignored
 
467
         0 versioned subdirectories
 
468
 
 
469
Branch history:
 
470
         2 revisions
 
471
         0 days old
 
472
   first revision: %s
 
473
  latest revision: %s
 
474
 
 
475
Repository:
 
476
         2 revisions
 
477
""" % (format_description, datestring_first, datestring_last,), out)
 
478
        self.assertEqual('', err)
 
479
 
 
480
    def test_info_standalone_no_tree(self):
 
481
        # create standalone branch without a working tree
 
482
        format = bzrdir.format_registry.make_bzrdir('default')
 
483
        branch = self.make_branch('branch')
 
484
        repo = branch.repository
 
485
        out, err = self.run_bzr('info branch -v')
 
486
        self.assertEqualDiff(
 
487
"""Standalone branch (format: %s)
 
488
Location:
 
489
  branch root: branch
 
490
 
 
491
Format:
 
492
       control: Meta directory format 1
 
493
        branch: %s
 
494
    repository: %s
 
495
 
 
496
Branch history:
 
497
         0 revisions
 
498
 
 
499
Repository:
 
500
         0 revisions
 
501
""" % (info.describe_format(repo.bzrdir, repo, branch, None),
 
502
       format.get_branch_format().get_format_description(),
 
503
       format.repository_format.get_format_description(),
 
504
       ), out)
 
505
        self.assertEqual('', err)
 
506
 
 
507
    def test_info_shared_repository(self):
 
508
        format = bzrdir.format_registry.make_bzrdir('knit')
 
509
        transport = self.get_transport()
 
510
 
 
511
        # Create shared repository
 
512
        repo = self.make_repository('repo', shared=True, format=format)
 
513
        repo.set_make_working_trees(False)
 
514
        out, err = self.run_bzr('info -v repo')
 
515
        self.assertEqualDiff(
 
516
"""Shared repository (format: dirstate or dirstate-tags or knit)
 
517
Location:
 
518
  shared repository: %s
 
519
 
 
520
Format:
 
521
       control: Meta directory format 1
 
522
    repository: %s
 
523
 
 
524
Repository:
 
525
         0 revisions
 
526
""" % ('repo', format.repository_format.get_format_description(),
 
527
       ), out)
 
528
        self.assertEqual('', err)
 
529
 
 
530
        # Create branch inside shared repository
 
531
        repo.bzrdir.root_transport.mkdir('branch')
 
532
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch',
 
533
            format=format)
 
534
        out, err = self.run_bzr('info -v repo/branch')
 
535
        self.assertEqualDiff(
 
536
"""Repository branch (format: dirstate or knit)
 
537
Location:
 
538
  shared repository: repo
 
539
  repository branch: repo/branch
 
540
 
 
541
Format:
 
542
       control: Meta directory format 1
 
543
        branch: %s
 
544
    repository: %s
 
545
 
 
546
Branch history:
 
547
         0 revisions
 
548
 
 
549
Repository:
 
550
         0 revisions
 
551
""" % (format.get_branch_format().get_format_description(),
 
552
       format.repository_format.get_format_description(),
 
553
       ), out)
 
554
        self.assertEqual('', err)
 
555
 
 
556
        # Create lightweight checkout
 
557
        transport.mkdir('tree')
 
558
        transport.mkdir('tree/lightcheckout')
 
559
        tree2 = branch1.create_checkout('tree/lightcheckout',
 
560
            lightweight=True)
 
561
        branch2 = tree2.branch
 
562
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', tree2,
 
563
                   shared_repo=repo, repo_branch=branch1, verbose=True)
 
564
 
 
565
        # Create normal checkout
 
566
        tree3 = branch1.create_checkout('tree/checkout')
 
567
        self.assertCheckoutStatusOutput('tree/checkout --verbose', tree3,
 
568
            verbose=True,
 
569
            light_checkout=False, repo_branch=branch1)
 
570
        # Update lightweight checkout
 
571
        self.build_tree(['tree/lightcheckout/a'])
 
572
        tree2.add('a')
 
573
        tree2.commit('commit one')
 
574
        rev = repo.get_revision(branch2.revision_history()[0])
 
575
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
576
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
 
577
        self.assertEqualDiff(
 
578
"""Lightweight checkout (format: %s)
 
579
Location:
 
580
  light checkout root: tree/lightcheckout
 
581
   checkout of branch: repo/branch
 
582
    shared repository: repo
 
583
 
 
584
Format:
 
585
       control: Meta directory format 1
 
586
  working tree: Working tree format 6
 
587
        branch: %s
 
588
    repository: %s
 
589
 
 
590
In the working tree:
 
591
         1 unchanged
 
592
         0 modified
 
593
         0 added
 
594
         0 removed
 
595
         0 renamed
 
596
         0 unknown
 
597
         0 ignored
 
598
         0 versioned subdirectories
 
599
 
 
600
Branch history:
 
601
         1 revision
 
602
         0 days old
 
603
   first revision: %s
 
604
  latest revision: %s
 
605
 
 
606
Repository:
 
607
         1 revision
 
608
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
609
       format.repository_format.get_format_description(),
 
610
       datestring_first, datestring_first,
 
611
       ), out)
 
612
        self.assertEqual('', err)
 
613
 
 
614
        # Out of date checkout
 
615
        out, err = self.run_bzr('info -v tree/checkout')
 
616
        self.assertEqualDiff(
 
617
"""Checkout (format: unnamed)
 
618
Location:
 
619
       checkout root: tree/checkout
 
620
  checkout of branch: repo/branch
 
621
 
 
622
Format:
 
623
       control: Meta directory format 1
 
624
  working tree: Working tree format 6
 
625
        branch: %s
 
626
    repository: %s
 
627
 
 
628
Branch is out of date: missing 1 revision.
 
629
 
 
630
In the working tree:
 
631
         0 unchanged
 
632
         0 modified
 
633
         0 added
 
634
         0 removed
 
635
         0 renamed
 
636
         0 unknown
 
637
         0 ignored
 
638
         0 versioned subdirectories
 
639
 
 
640
Branch history:
 
641
         0 revisions
 
642
 
 
643
Repository:
 
644
         0 revisions
 
645
""" % (format.get_branch_format().get_format_description(),
 
646
       format.repository_format.get_format_description(),
 
647
       ), out)
 
648
        self.assertEqual('', err)
 
649
 
 
650
        # Update checkout
 
651
        tree3.update()
 
652
        self.build_tree(['tree/checkout/b'])
 
653
        tree3.add('b')
 
654
        out, err = self.run_bzr('info tree/checkout --verbose')
 
655
        self.assertEqualDiff(
 
656
"""Checkout (format: unnamed)
 
657
Location:
 
658
       checkout root: tree/checkout
 
659
  checkout of branch: repo/branch
 
660
 
 
661
Format:
 
662
       control: Meta directory format 1
 
663
  working tree: Working tree format 6
 
664
        branch: %s
 
665
    repository: %s
 
666
 
 
667
In the working tree:
 
668
         1 unchanged
 
669
         0 modified
 
670
         1 added
 
671
         0 removed
 
672
         0 renamed
 
673
         0 unknown
 
674
         0 ignored
 
675
         0 versioned subdirectories
 
676
 
 
677
Branch history:
 
678
         1 revision
 
679
         0 days old
 
680
   first revision: %s
 
681
  latest revision: %s
 
682
 
 
683
Repository:
 
684
         1 revision
 
685
""" % (format.get_branch_format().get_format_description(),
 
686
       format.repository_format.get_format_description(),
 
687
       datestring_first, datestring_first,
 
688
       ), out)
 
689
        self.assertEqual('', err)
 
690
        tree3.commit('commit two')
 
691
 
 
692
        # Out of date lightweight checkout
 
693
        rev = repo.get_revision(branch1.revision_history()[-1])
 
694
        datestring_last = osutils.format_date(rev.timestamp, rev.timezone)
 
695
        out, err = self.run_bzr('info tree/lightcheckout --verbose')
 
696
        self.assertEqualDiff(
 
697
"""Lightweight checkout (format: %s)
 
698
Location:
 
699
  light checkout root: tree/lightcheckout
 
700
   checkout of branch: repo/branch
 
701
    shared repository: repo
 
702
 
 
703
Format:
 
704
       control: Meta directory format 1
 
705
  working tree: Working tree format 6
 
706
        branch: %s
 
707
    repository: %s
 
708
 
 
709
Working tree is out of date: missing 1 revision.
 
710
 
 
711
In the working tree:
 
712
         1 unchanged
 
713
         0 modified
 
714
         0 added
 
715
         0 removed
 
716
         0 renamed
 
717
         0 unknown
 
718
         0 ignored
 
719
         0 versioned subdirectories
 
720
 
 
721
Branch history:
 
722
         2 revisions
 
723
         0 days old
 
724
   first revision: %s
 
725
  latest revision: %s
 
726
 
 
727
Repository:
 
728
         2 revisions
 
729
""" % (self._repo_strings, format.get_branch_format().get_format_description(),
 
730
       format.repository_format.get_format_description(),
 
731
       datestring_first, datestring_last,
 
732
       ), out)
 
733
        self.assertEqual('', err)
 
734
 
 
735
        # Show info about shared branch
 
736
        out, err = self.run_bzr('info repo/branch --verbose')
 
737
        self.assertEqualDiff(
 
738
"""Repository branch (format: dirstate or knit)
 
739
Location:
 
740
  shared repository: repo
 
741
  repository branch: repo/branch
 
742
 
 
743
Format:
 
744
       control: Meta directory format 1
 
745
        branch: %s
 
746
    repository: %s
 
747
 
 
748
Branch history:
 
749
         2 revisions
 
750
         0 days old
 
751
   first revision: %s
 
752
  latest revision: %s
 
753
 
 
754
Repository:
 
755
         2 revisions
 
756
""" % (format.get_branch_format().get_format_description(),
 
757
       format.repository_format.get_format_description(),
 
758
       datestring_first, datestring_last,
 
759
       ), out)
 
760
        self.assertEqual('', err)
 
761
 
 
762
        # Show info about repository with revisions
 
763
        out, err = self.run_bzr('info -v repo')
 
764
        self.assertEqualDiff(
 
765
"""Shared repository (format: dirstate or dirstate-tags or knit)
 
766
Location:
 
767
  shared repository: repo
 
768
 
 
769
Format:
 
770
       control: Meta directory format 1
 
771
    repository: %s
 
772
 
 
773
Repository:
 
774
         2 revisions
 
775
""" % (format.repository_format.get_format_description(),
 
776
       ), out)
 
777
        self.assertEqual('', err)
 
778
 
 
779
    def test_info_shared_repository_with_trees(self):
 
780
        format = bzrdir.format_registry.make_bzrdir('knit')
 
781
        transport = self.get_transport()
 
782
 
 
783
        # Create shared repository with working trees
 
784
        repo = self.make_repository('repo', shared=True, format=format)
 
785
        repo.set_make_working_trees(True)
 
786
        out, err = self.run_bzr('info -v repo')
 
787
        self.assertEqualDiff(
 
788
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
789
Location:
 
790
  shared repository: repo
 
791
 
 
792
Format:
 
793
       control: Meta directory format 1
 
794
    repository: %s
 
795
 
 
796
Create working tree for new branches inside the repository.
 
797
 
 
798
Repository:
 
799
         0 revisions
 
800
""" % (format.repository_format.get_format_description(),
 
801
       ), out)
 
802
        self.assertEqual('', err)
 
803
 
 
804
        # Create two branches
 
805
        repo.bzrdir.root_transport.mkdir('branch1')
 
806
        branch1 = repo.bzrdir.create_branch_convenience('repo/branch1',
 
807
            format=format)
 
808
        branch2 = branch1.bzrdir.sprout('repo/branch2').open_branch()
 
809
 
 
810
        # Empty first branch
 
811
        out, err = self.run_bzr('info repo/branch1 --verbose')
 
812
        self.assertEqualDiff(
 
813
"""Repository tree (format: knit)
 
814
Location:
 
815
  shared repository: repo
 
816
  repository branch: repo/branch1
 
817
 
 
818
Format:
 
819
       control: Meta directory format 1
 
820
  working tree: Working tree format 3
 
821
        branch: %s
 
822
    repository: %s
 
823
 
 
824
In the working tree:
 
825
         0 unchanged
 
826
         0 modified
 
827
         0 added
 
828
         0 removed
 
829
         0 renamed
 
830
         0 unknown
 
831
         0 ignored
 
832
         0 versioned subdirectories
 
833
 
 
834
Branch history:
 
835
         0 revisions
 
836
 
 
837
Repository:
 
838
         0 revisions
 
839
""" % (format.get_branch_format().get_format_description(),
 
840
       format.repository_format.get_format_description(),
 
841
       ), out)
 
842
        self.assertEqual('', err)
 
843
 
 
844
        # Update first branch
 
845
        self.build_tree(['repo/branch1/a'])
 
846
        tree1 = branch1.bzrdir.open_workingtree()
 
847
        tree1.add('a')
 
848
        tree1.commit('commit one')
 
849
        rev = repo.get_revision(branch1.revision_history()[0])
 
850
        datestring_first = osutils.format_date(rev.timestamp, rev.timezone)
 
851
        out, err = self.run_bzr('info -v repo/branch1')
 
852
        self.assertEqualDiff(
 
853
"""Repository tree (format: knit)
 
854
Location:
 
855
  shared repository: repo
 
856
  repository branch: repo/branch1
 
857
 
 
858
Format:
 
859
       control: Meta directory format 1
 
860
  working tree: Working tree format 3
 
861
        branch: %s
 
862
    repository: %s
 
863
 
 
864
In the working tree:
 
865
         1 unchanged
 
866
         0 modified
 
867
         0 added
 
868
         0 removed
 
869
         0 renamed
 
870
         0 unknown
 
871
         0 ignored
 
872
         0 versioned subdirectories
 
873
 
 
874
Branch history:
 
875
         1 revision
 
876
         0 days old
 
877
   first revision: %s
 
878
  latest revision: %s
 
879
 
 
880
Repository:
 
881
         1 revision
 
882
""" % (format.get_branch_format().get_format_description(),
 
883
       format.repository_format.get_format_description(),
 
884
       datestring_first, datestring_first,
 
885
       ), out)
 
886
        self.assertEqual('', err)
 
887
 
 
888
        # Out of date second branch
 
889
        out, err = self.run_bzr('info repo/branch2 --verbose')
 
890
        self.assertEqualDiff(
 
891
"""Repository tree (format: knit)
 
892
Location:
 
893
  shared repository: repo
 
894
  repository branch: repo/branch2
 
895
 
 
896
Related branches:
 
897
  parent branch: repo/branch1
 
898
 
 
899
Format:
 
900
       control: Meta directory format 1
 
901
  working tree: Working tree format 3
 
902
        branch: %s
 
903
    repository: %s
 
904
 
 
905
In the working tree:
 
906
         0 unchanged
 
907
         0 modified
 
908
         0 added
 
909
         0 removed
 
910
         0 renamed
 
911
         0 unknown
 
912
         0 ignored
 
913
         0 versioned subdirectories
 
914
 
 
915
Branch history:
 
916
         0 revisions
 
917
 
 
918
Repository:
 
919
         1 revision
 
920
""" % (format.get_branch_format().get_format_description(),
 
921
       format.repository_format.get_format_description(),
 
922
       ), out)
 
923
        self.assertEqual('', err)
 
924
 
 
925
        # Update second branch
 
926
        tree2 = branch2.bzrdir.open_workingtree()
 
927
        tree2.pull(branch1)
 
928
        out, err = self.run_bzr('info -v repo/branch2')
 
929
        self.assertEqualDiff(
 
930
"""Repository tree (format: knit)
 
931
Location:
 
932
  shared repository: repo
 
933
  repository branch: repo/branch2
 
934
 
 
935
Related branches:
 
936
  parent branch: repo/branch1
 
937
 
 
938
Format:
 
939
       control: Meta directory format 1
 
940
  working tree: Working tree format 3
 
941
        branch: %s
 
942
    repository: %s
 
943
 
 
944
In the working tree:
 
945
         1 unchanged
 
946
         0 modified
 
947
         0 added
 
948
         0 removed
 
949
         0 renamed
 
950
         0 unknown
 
951
         0 ignored
 
952
         0 versioned subdirectories
 
953
 
 
954
Branch history:
 
955
         1 revision
 
956
         0 days old
 
957
   first revision: %s
 
958
  latest revision: %s
 
959
 
 
960
Repository:
 
961
         1 revision
 
962
""" % (format.get_branch_format().get_format_description(),
 
963
       format.repository_format.get_format_description(),
 
964
       datestring_first, datestring_first,
 
965
       ), out)
 
966
        self.assertEqual('', err)
 
967
 
 
968
        # Show info about repository with revisions
 
969
        out, err = self.run_bzr('info -v repo')
 
970
        self.assertEqualDiff(
 
971
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
972
Location:
 
973
  shared repository: repo
 
974
 
 
975
Format:
 
976
       control: Meta directory format 1
 
977
    repository: %s
 
978
 
 
979
Create working tree for new branches inside the repository.
 
980
 
 
981
Repository:
 
982
         1 revision
 
983
""" % (format.repository_format.get_format_description(),
 
984
       ),
 
985
       out)
 
986
        self.assertEqual('', err)
 
987
 
 
988
    def test_info_shared_repository_with_tree_in_root(self):
 
989
        format = bzrdir.format_registry.make_bzrdir('knit')
 
990
        transport = self.get_transport()
 
991
 
 
992
        # Create shared repository with working trees
 
993
        repo = self.make_repository('repo', shared=True, format=format)
 
994
        repo.set_make_working_trees(True)
 
995
        out, err = self.run_bzr('info -v repo')
 
996
        self.assertEqualDiff(
 
997
"""Shared repository with trees (format: dirstate or dirstate-tags or knit)
 
998
Location:
 
999
  shared repository: repo
 
1000
 
 
1001
Format:
 
1002
       control: Meta directory format 1
 
1003
    repository: %s
 
1004
 
 
1005
Create working tree for new branches inside the repository.
 
1006
 
 
1007
Repository:
 
1008
         0 revisions
 
1009
""" % (format.repository_format.get_format_description(),
 
1010
       ), out)
 
1011
        self.assertEqual('', err)
 
1012
 
 
1013
        # Create branch in root of repository
 
1014
        control = repo.bzrdir
 
1015
        branch = control.create_branch()
 
1016
        control.create_workingtree()
 
1017
        out, err = self.run_bzr('info -v repo')
 
1018
        self.assertEqualDiff(
 
1019
"""Repository tree (format: knit)
 
1020
Location:
 
1021
  shared repository: repo
 
1022
  repository branch: repo
 
1023
 
 
1024
Format:
 
1025
       control: Meta directory format 1
 
1026
  working tree: Working tree format 3
 
1027
        branch: %s
 
1028
    repository: %s
 
1029
 
 
1030
In the working tree:
 
1031
         0 unchanged
 
1032
         0 modified
 
1033
         0 added
 
1034
         0 removed
 
1035
         0 renamed
 
1036
         0 unknown
 
1037
         0 ignored
 
1038
         0 versioned subdirectories
 
1039
 
 
1040
Branch history:
 
1041
         0 revisions
 
1042
 
 
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,
 
1077
        command_string, lco_tree, shared_repo=None,
 
1078
        repo_branch=None,
 
1079
        tree_locked=False,
 
1080
        branch_locked=False, repo_locked=False,
 
1081
        verbose=False,
 
1082
        light_checkout=True,
 
1083
        checkout_root=None):
 
1084
        """Check the output of info in a checkout.
 
1085
 
 
1086
        This is not quite a mirror of the info code: rather than using the
 
1087
        tree being examined to predict output, it uses a bunch of flags which
 
1088
        allow us, the test writers, to document what *should* be present in
 
1089
        the output. Removing this separation would remove the value of the
 
1090
        tests.
 
1091
 
 
1092
        :param path: the path to the light checkout.
 
1093
        :param lco_tree: the tree object for the light checkout.
 
1094
        :param shared_repo: A shared repository is in use, expect that in
 
1095
            the output.
 
1096
        :param repo_branch: A branch in a shared repository for non light
 
1097
            checkouts.
 
1098
        :param tree_locked: If true, expect the tree to be locked.
 
1099
        :param branch_locked: If true, expect the branch to be locked.
 
1100
        :param repo_locked: If true, expect the repository to be locked.
 
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
 
1106
        """
 
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()
 
1134
        if repo_locked or branch_locked or tree_locked:
 
1135
            def locked_message(a_bool):
 
1136
                if a_bool:
 
1137
                    return 'locked'
 
1138
                else:
 
1139
                    return 'unlocked'
 
1140
            expected_lock_output = (
 
1141
                "\n"
 
1142
                "Lock status:\n"
 
1143
                "  working tree: %s\n"
 
1144
                "        branch: %s\n"
 
1145
                "    repository: %s\n" % (
 
1146
                    locked_message(tree_locked),
 
1147
                    locked_message(branch_locked),
 
1148
                    locked_message(repo_locked)))
 
1149
        else:
 
1150
            expected_lock_output = ''
 
1151
        tree_data = ''
 
1152
        extra_space = ''
 
1153
        if light_checkout:
 
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)))
 
1160
        if shared_repo is not None:
 
1161
            branch_data = (
 
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)))
 
1166
        elif repo_branch is not None:
 
1167
            branch_data = (
 
1168
                "%s  checkout of branch: %s\n" %
 
1169
                (extra_space,
 
1170
                 friendly_location(repo_branch.bzrdir.root_transport.base)))
 
1171
        else:
 
1172
            branch_data = ("   checkout of branch: %s\n" %
 
1173
                lco_tree.branch.bzrdir.root_transport.base)
 
1174
 
 
1175
        if verbose >= 2:
 
1176
            verbose_info = '         0 committers\n'
 
1177
        else:
 
1178
            verbose_info = ''
 
1179
 
 
1180
        self.assertEqualDiff(
 
1181
"""%s (format: %s)
 
1182
Location:
 
1183
%s%s
 
1184
Format:
 
1185
       control: Meta directory format 1
 
1186
  working tree: %s
 
1187
        branch: %s
 
1188
    repository: %s
 
1189
%s
 
1190
In the working tree:
 
1191
         0 unchanged
 
1192
         0 modified
 
1193
         0 added
 
1194
         0 removed
 
1195
         0 renamed
 
1196
         0 unknown
 
1197
         0 ignored
 
1198
         0 versioned subdirectories
 
1199
 
 
1200
Branch history:
 
1201
         0 revisions
 
1202
%s
 
1203
Repository:
 
1204
         0 revisions
 
1205
""" %  (description,
 
1206
        format,
 
1207
        tree_data,
 
1208
        branch_data,
 
1209
        lco_tree._format.get_format_description(),
 
1210
        lco_tree.branch._format.get_format_description(),
 
1211
        lco_tree.branch.repository._format.get_format_description(),
 
1212
        expected_lock_output,
 
1213
        verbose_info,
 
1214
        ), out)
 
1215
        self.assertEqual('', err)
 
1216
 
 
1217
    def test_info_locking(self):
 
1218
        transport = self.get_transport()
 
1219
        # Create shared repository with a branch
 
1220
        repo = self.make_repository('repo', shared=True,
 
1221
                                    format=bzrdir.BzrDirMetaFormat1())
 
1222
        repo.set_make_working_trees(False)
 
1223
        repo.bzrdir.root_transport.mkdir('branch')
 
1224
        repo_branch = repo.bzrdir.create_branch_convenience('repo/branch',
 
1225
                                    format=bzrdir.BzrDirMetaFormat1())
 
1226
        # Do a heavy checkout
 
1227
        transport.mkdir('tree')
 
1228
        transport.mkdir('tree/checkout')
 
1229
        co_branch = bzrdir.BzrDir.create_branch_convenience('tree/checkout',
 
1230
            format=bzrdir.BzrDirMetaFormat1())
 
1231
        co_branch.bind(repo_branch)
 
1232
        # Do a light checkout of the heavy one
 
1233
        transport.mkdir('tree/lightcheckout')
 
1234
        lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
 
1235
        branch.BranchReferenceFormat().initialize(lco_dir,
 
1236
            target_branch=co_branch)
 
1237
        lco_dir.create_workingtree()
 
1238
        lco_tree = lco_dir.open_workingtree()
 
1239
 
 
1240
        # Test all permutations of locking the working tree, branch and repository
 
1241
        # W B R
 
1242
 
 
1243
        # U U U
 
1244
        self.assertCheckoutStatusOutput('-v tree/lightcheckout', lco_tree,
 
1245
                                        repo_branch=repo_branch,
 
1246
                                        verbose=True, light_checkout=True)
 
1247
        # U U L
 
1248
        lco_tree.branch.repository.lock_write()
 
1249
        try:
 
1250
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1251
            lco_tree, repo_branch=repo_branch,
 
1252
            repo_locked=True, verbose=True, light_checkout=True)
 
1253
        finally:
 
1254
            lco_tree.branch.repository.unlock()
 
1255
        # U L L
 
1256
        lco_tree.branch.lock_write()
 
1257
        try:
 
1258
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1259
            lco_tree,
 
1260
            branch_locked=True,
 
1261
            repo_locked=True,
 
1262
            repo_branch=repo_branch,
 
1263
            verbose=True)
 
1264
        finally:
 
1265
            lco_tree.branch.unlock()
 
1266
        # L L L
 
1267
        lco_tree.lock_write()
 
1268
        try:
 
1269
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1270
            lco_tree, repo_branch=repo_branch,
 
1271
            tree_locked=True,
 
1272
            branch_locked=True,
 
1273
            repo_locked=True,
 
1274
            verbose=True)
 
1275
        finally:
 
1276
            lco_tree.unlock()
 
1277
        # L L U
 
1278
        lco_tree.lock_write()
 
1279
        lco_tree.branch.repository.unlock()
 
1280
        try:
 
1281
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1282
            lco_tree, repo_branch=repo_branch,
 
1283
            tree_locked=True,
 
1284
            branch_locked=True,
 
1285
            verbose=True)
 
1286
        finally:
 
1287
            lco_tree.branch.repository.lock_write()
 
1288
            lco_tree.unlock()
 
1289
        # L U U
 
1290
        lco_tree.lock_write()
 
1291
        lco_tree.branch.unlock()
 
1292
        try:
 
1293
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1294
            lco_tree, repo_branch=repo_branch,
 
1295
            tree_locked=True,
 
1296
            verbose=True)
 
1297
        finally:
 
1298
            lco_tree.branch.lock_write()
 
1299
            lco_tree.unlock()
 
1300
        # L U L
 
1301
        lco_tree.lock_write()
 
1302
        lco_tree.branch.unlock()
 
1303
        lco_tree.branch.repository.lock_write()
 
1304
        try:
 
1305
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1306
            lco_tree, repo_branch=repo_branch,
 
1307
            tree_locked=True,
 
1308
            repo_locked=True,
 
1309
            verbose=True)
 
1310
        finally:
 
1311
            lco_tree.branch.repository.unlock()
 
1312
            lco_tree.branch.lock_write()
 
1313
            lco_tree.unlock()
 
1314
        # U L U
 
1315
        lco_tree.branch.lock_write()
 
1316
        lco_tree.branch.repository.unlock()
 
1317
        try:
 
1318
            self.assertCheckoutStatusOutput('-v tree/lightcheckout',
 
1319
            lco_tree, repo_branch=repo_branch,
 
1320
            branch_locked=True,
 
1321
            verbose=True)
 
1322
        finally:
 
1323
            lco_tree.branch.repository.lock_write()
 
1324
            lco_tree.branch.unlock()
 
1325
 
 
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)