~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/test_bzrdir.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011, 2012, 2016 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
 
"""Tests for the weave-era BzrDir formats.
18
 
 
19
 
For interface contract tests, see tests/per_bzr_dir.
20
 
"""
21
 
 
22
 
from __future__ import absolute_import
23
 
 
24
 
import os
25
 
import sys
26
 
 
27
 
from bzrlib import (
28
 
    branch,
29
 
    bzrdir,
30
 
    controldir,
31
 
    errors,
32
 
    repository,
33
 
    upgrade,
34
 
    urlutils,
35
 
    workingtree,
36
 
    )
37
 
from bzrlib.osutils import (
38
 
    getcwd,
39
 
    )
40
 
from bzrlib.tests.test_bundle import V4BundleTester
41
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
42
 
from bzrlib.tests import (
43
 
    TestCaseWithTransport,
44
 
    )
45
 
 
46
 
from bzrlib.plugins.weave_fmt.branch import (
47
 
    BzrBranchFormat4,
48
 
    )
49
 
from bzrlib.plugins.weave_fmt.bzrdir import (
50
 
    BzrDirFormat5,
51
 
    BzrDirFormat6,
52
 
    )
53
 
 
54
 
 
55
 
class TestFormat5(TestCaseWithTransport):
56
 
    """Tests specific to the version 5 bzrdir format."""
57
 
 
58
 
    def test_same_lockfiles_between_tree_repo_branch(self):
59
 
        # this checks that only a single lockfiles instance is created
60
 
        # for format 5 objects
61
 
        dir = BzrDirFormat5().initialize(self.get_url())
62
 
        def check_dir_components_use_same_lock(dir):
63
 
            ctrl_1 = dir.open_repository().control_files
64
 
            ctrl_2 = dir.open_branch().control_files
65
 
            ctrl_3 = dir.open_workingtree()._control_files
66
 
            self.assertTrue(ctrl_1 is ctrl_2)
67
 
            self.assertTrue(ctrl_2 is ctrl_3)
68
 
        check_dir_components_use_same_lock(dir)
69
 
        # and if we open it normally.
70
 
        dir = controldir.ControlDir.open(self.get_url())
71
 
        check_dir_components_use_same_lock(dir)
72
 
 
73
 
    def test_can_convert(self):
74
 
        # format 5 dirs are convertable
75
 
        dir = BzrDirFormat5().initialize(self.get_url())
76
 
        self.assertTrue(dir.can_convert_format())
77
 
 
78
 
    def test_needs_conversion(self):
79
 
        # format 5 dirs need a conversion if they are not the default,
80
 
        # and they aren't
81
 
        dir = BzrDirFormat5().initialize(self.get_url())
82
 
        # don't need to convert it to itself
83
 
        self.assertFalse(dir.needs_format_conversion(BzrDirFormat5()))
84
 
        # do need to convert it to the current default
85
 
        self.assertTrue(dir.needs_format_conversion(
86
 
            bzrdir.BzrDirFormat.get_default_format()))
87
 
 
88
 
 
89
 
class TestFormat6(TestCaseWithTransport):
90
 
    """Tests specific to the version 6 bzrdir format."""
91
 
 
92
 
    def test_same_lockfiles_between_tree_repo_branch(self):
93
 
        # this checks that only a single lockfiles instance is created
94
 
        # for format 6 objects
95
 
        dir = BzrDirFormat6().initialize(self.get_url())
96
 
        def check_dir_components_use_same_lock(dir):
97
 
            ctrl_1 = dir.open_repository().control_files
98
 
            ctrl_2 = dir.open_branch().control_files
99
 
            ctrl_3 = dir.open_workingtree()._control_files
100
 
            self.assertTrue(ctrl_1 is ctrl_2)
101
 
            self.assertTrue(ctrl_2 is ctrl_3)
102
 
        check_dir_components_use_same_lock(dir)
103
 
        # and if we open it normally.
104
 
        dir = controldir.ControlDir.open(self.get_url())
105
 
        check_dir_components_use_same_lock(dir)
106
 
 
107
 
    def test_can_convert(self):
108
 
        # format 6 dirs are convertable
109
 
        dir = BzrDirFormat6().initialize(self.get_url())
110
 
        self.assertTrue(dir.can_convert_format())
111
 
 
112
 
    def test_needs_conversion(self):
113
 
        # format 6 dirs need an conversion if they are not the default.
114
 
        dir = BzrDirFormat6().initialize(self.get_url())
115
 
        self.assertTrue(dir.needs_format_conversion(
116
 
            bzrdir.BzrDirFormat.get_default_format()))
117
 
 
118
 
 
119
 
class TestBreakLockOldBranch(TestCaseWithTransport):
120
 
 
121
 
    def test_break_lock_format_5_bzrdir(self):
122
 
        # break lock on a format 5 bzrdir should just return
123
 
        self.make_branch_and_tree('foo', format=BzrDirFormat5())
124
 
        out, err = self.run_bzr('break-lock foo')
125
 
        self.assertEqual('', out)
126
 
        self.assertEqual('', err)
127
 
 
128
 
 
129
 
_upgrade1_template = \
130
 
     [
131
 
     ('foo', 'new contents\n'),
132
 
     ('.bzr/',),
133
 
     ('.bzr/README',
134
 
      'This is a Bazaar control directory.\n'
135
 
      'Do not change any files in this directory.\n'
136
 
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'),
137
 
     ('.bzr/branch-format', 'Bazaar-NG branch, format 0.0.4\n'),
138
 
     ('.bzr/revision-history',
139
 
      'mbp@sourcefrog.net-20051004035611-176b16534b086b3c\n'
140
 
      'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd\n'),
141
 
     ('.bzr/merged-patches', ''),
142
 
     ('.bzr/pending-merged-patches', ''),
143
 
     ('.bzr/branch-name', ''),
144
 
     ('.bzr/branch-lock', ''),
145
 
     ('.bzr/pending-merges', ''),
146
 
     ('.bzr/inventory',
147
 
      '<inventory>\n'
148
 
      '<entry file_id="foo-20051004035605-91e788d1875603ae" kind="file" name="foo" />\n'
149
 
      '</inventory>\n'),
150
 
     ('.bzr/stat-cache',
151
 
      '### bzr hashcache v5\n'
152
 
      'foo// be9f309239729f69a6309e970ef24941d31e042c 13 1128398176 1128398176 303464 770\n'),
153
 
     ('.bzr/text-store/',),
154
 
     ('.bzr/text-store/foo-20051004035611-1591048e9dc7c2d4.gz',
155
 
      '\x1f\x8b\x08\x00[\xfdAC\x02\xff\xcb\xcc\xcb,\xc9L\xccQH\xce\xcf+I\xcd+)\xe6\x02\x00\xdd\xcc\xf90\x11\x00\x00\x00'),
156
 
     ('.bzr/text-store/foo-20051004035756-4081373d897c3453.gz',
157
 
      '\x1f\x8b\x08\x00\xc4\xfdAC\x02\xff\xcbK-WH\xce\xcf+I\xcd+)\xe6\x02\x00g\xc3\xdf\xc9\r\x00\x00\x00'),
158
 
     ('.bzr/inventory-store/',),
159
 
     ('.bzr/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz',
160
 
      '\x1f\x8b\x08\x00[\xfdAC\x02\xffm\x8f\xcd\n\xc20\x10\x84\xef>E\xc8\xbdt7?M\x02\xad\xaf"\xa1\x99`P[\xa8E\xacOo\x14\x05\x0f\xdef\xe1\xfbv\x98\xbeL7L\xeb\xbcl\xfb]_\xc3\xb2\x89\\\xce8\x944\xc8<\xcf\x8d"\xb2LdH\xdb\x8el\x13\x18\xce\xfb\xc4\xde\xd5SGHq*\xd3\x0b\xad\x8e\x14S\xbc\xe0\xadI\xb1\xe2\xbe\xfe}\xc2\xdc\xb0\rL\xc6#\xa4\xd1\x8d*\x99\x0f}=F\x1e$8G\x9d\xa0\x02\xa1rP9\x01c`FV\xda1qg\x98"\x02}\xa5\xf2\xa8\x95\xec\xa4h\xeb\x80\xf6g\xcd\x13\xb3\x01\xcc\x98\xda\x00\x00\x00'),
161
 
     ('.bzr/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz',
162
 
      '\x1f\x8b\x08\x00\xc4\xfdAC\x02\xffm\x8f\xc1\n\xc20\x10D\xef~E\xc8\xbd\xb8\x9bM\x9a,\xb4\xfe\x8a\xc4f\x83Am\xa1\x16\xb1~\xbdQ\x14<x\x9b\x81y3LW\xc6\x9b\x8c\xcb4\xaf\xbbMW\xc5\xbc\xaa\\\xce\xb2/\xa9\xd7y\x9a\x1a\x03\xe0\x10\xc0\x02\xb9\x16\\\xc3(>\x84\x84\xc1WKQ\xb4:\x95\xf1\x15\xad\x8cVc\xbc\xc8\x1b\xd3j\x91\xfb\xf2\xaf\xa4r\x8d\x85\x80\xe4)\x05\xf6\x03YG\x9f\xf4\xf5\x18\xb1\xd7\x07\xe1L\xc0\x86\xd8\x1b\xce-\xc7\xb6:a\x0f\x92\x8de\x8b\x89P\xc0\x9a\xe1\x0b\x95G\x9d\xc4\xda\xb1\xad\x07\xb6?o\x9e\xb5\xff\xf0\xf9\xda\x00\x00\x00'),
163
 
     ('.bzr/revision-store/',),
164
 
     ('.bzr/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz',
165
 
      '\x1f\x8b\x08\x00[\xfdAC\x02\xff\x9d\x8eKj\xc30\x14E\xe7^\x85\xd0 \xb3$\xefI\xd1\x8f\xd8\xa6\x1b(t\x07E?\xbb\x82H\n\xb2\x1ahW\xdfB1\x14:\xeb\xf4r\xee\xbdgl\xf1\x91\xb6T\x0b\xf15\xe7\xd4{l\x13}\xb6\xad\xa7B^j\xbd\x91\xc3\xad_\xb3\xbb?m\xf5\xbd\xf9\xb8\xb4\xba\x9eJ\xec\x87\xb5_)I\xe5\x11K\xaf\xed\xe35\x85\x89\xfe\xa5\x8e\x0c@ \xc0\x05\xb8\x90\x88GT\xd2\xa1\x14\xfc\xe2@K\xc7\xfd\xef\x85\xed\xcd\xe2D\x95\x8d\x1a\xa47<\x02c2\xb0 \xbc\xd0\x8ay\xa3\xbcp\x8a\x83\x12A3\xb7XJv\xef\x7f_\xf7\x94\xe3\xd6m\xbeO\x14\x91in4*<\x812\x88\xc60\xfc\x01>k\x89\x13\xe5\x12\x00\xe8<\x8c\xdf\x8d\xcd\xaeq\xb6!\x90\xa5\xd6\xf1\xbc\x07\xc3x\xde\x85\xe6\xe1\x0b\xc8\x8a\x98\x03T\x01\x00\x00'),
166
 
     ('.bzr/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz',
167
 
      '\x1f\x8b\x08\x00\xc4\xfdAC\x02\xff\x9d\x90Kj\x031\x0c\x86\xf79\xc5\xe0Ev\xe9\xc8o\x9b\xcc\x84^\xa0\xd0\x1b\x14\xbf&5d\xec`\xbb\x81\xf6\xf45\x84\xa4\x81\xaeZ\xa1\x85\x84^\xdf\xaf\xa9\x84K\xac1\xa7\xc1\xe5u\x8d\xad\x852\xa3\x17SZL\xc3k\xce\xa7a{j\xfb\xd5\x9e\x9fk\xfe(.,%\x1f\x9fRh\xdbc\xdb\xa3!\xa6KH-\x97\xcf\xb7\xe8g\xf4\xbbkG\x008\x06`@\xb9\xe4bG(_\x88\x95\xde\xf9n\xca\xfb\xc7\r\xf5\xdd\xe0\x19\xa9\x85)\x81\xf5"\xbd\x04j\xb8\x02b\xa8W\\\x0b\xc9\x14\xf4\xbc\xbb\xd7\xd6H4\xdc\xb8\xff}\xba\xc55\xd4f\xd6\xf3\x8c0&\x8ajE\xa4x\xe2@\xa5\xa6\x9a\xf3k\xc3WNaFT\x00\x00:l\xa6>Q\xcd1\x1cjp9\xf9;\xc34\xde\n\x9b\xe9lJWT{t\',a\xf9\x0b\xae\xc0x\x87\xa5\xb0Xp\xca,(a\xa9{\xd0{}\xd4\x12\x04(\xc5\xbb$\xc5$V\xceaI\x19\x01\xa2\x1dh\xed\x82d\x8c.\xccr@\xc3\xd8Q\xc6\x1f\xaa\xf1\xb6\xe8\xb0\xf9\x06QR\r\xf9\xfc\x01\x00\x00')]
168
 
 
169
 
 
170
 
_ghost_template = [
171
 
    ( './foo',
172
 
        'hello\n'
173
 
    ),
174
 
    ( './.bzr/', ),
175
 
    ( './.bzr/README',
176
 
      'This is a Bazaar control directory.\n'
177
 
      'Do not change any files in this directory.\n'
178
 
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'
179
 
    ),
180
 
    ( './.bzr/branch-format',
181
 
        'Bazaar-NG branch, format 0.0.4\n'
182
 
    ),
183
 
    ( './.bzr/branch-lock',
184
 
        ''
185
 
    ),
186
 
    ( './.bzr/branch-name',
187
 
        ''
188
 
    ),
189
 
    ( './.bzr/inventory',
190
 
        '<inventory>\n'
191
 
        '<entry file_id="foo-20051004104918-0379cb7c76354cde" kind="file" name="foo" />\n'
192
 
        '</inventory>\n'
193
 
    ),
194
 
    ( './.bzr/merged-patches',
195
 
        ''
196
 
    ),
197
 
    ( './.bzr/pending-merged-patches',
198
 
        ''
199
 
    ),
200
 
    ( './.bzr/pending-merges',
201
 
        ''
202
 
    ),
203
 
    ( './.bzr/revision-history',
204
 
        'mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\n'
205
 
        'mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\n'
206
 
    ),
207
 
    ( './.bzr/stat-cache',
208
 
        '### bzr hashcache v5\n'
209
 
        'foo// f572d396fae9206628714fb2ce00f72e94f2258f 6 1128422956 1128422956 306900 770\n'
210
 
    ),
211
 
    ( './.bzr/text-store/', ),
212
 
    ( './.bzr/text-store/foo-20051004104921-8de8118a71be45ba.gz',
213
 
        '\x1f\x8b\x08\x081^BC\x00\x03foo-20051004104921-8de8118a71be45ba\x00\xcbH\xcd\xc9\xc9\xe7\x02\x00 0:6\x06\x00\x00\x00'
214
 
    ),
215
 
    ( './.bzr/inventory-store/', ),
216
 
    ( './.bzr/inventory-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b.gz',
217
 
        '\x1f\x8b\x08\x081^BC\x00\x03mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\x00m\x8f\xcb\n'
218
 
        '\xc20\x10E\xf7~E\xc8\xbe83\xcd\x13\xaa\xbf"yL0\xa8-\xd4"\xd6\xaf7\x8a\x82\x0bw\xb38\xe7\xde;C\x1do<.\xd3\xbc\xee7C;\xe6U\x94z\xe6C\xcd;Y\xa6\xa9#\x00\x8d\x00\n'
219
 
        'Ayt\x1d\xf4\xd6\xa7h\x935\xbdV)\xb3\x14\xa7:\xbe\xd0\xe6H1\x86\x0b\xbf5)\x16\xbe/\x7fC\x08;\x97\xd9!\xba`1\xb2\xd21|\xe8\xeb1`\xe3\xb5\xa5\xdc{S\x02{\x02c\xc8YT%Rb\x80b\x89\xbd*D\xda\x95\xafT\x1f\xad\xd2H\xb1m\xfb\xb7?\xcf<\x01W}\xb5\x8b\xd9\x00\x00\x00'
220
 
    ),
221
 
    ( './.bzr/inventory-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d.gz',
222
 
        '\x1f\x8b\x08\x08A^BC\x00\x03mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\x00m\x8f\xcb\n'
223
 
        '\xc20\x10E\xf7~E\xc8\xbe83\xcd\x13\xaa\xbf"yL0\xa8-\xd4"\xd6\xaf7\x8a\x82\x0bw\xb38\xe7\xde;C\x1do<.\xd3\xbc\xee7C;\xe6U\x94z\xe6C\xcd;Y\xa6\xa9#\x00\x8d\x00\n'
224
 
        'Ayt\x1d\xf4\xd6\xa7h\x935\xbdV)\xb3\x14\xa7:\xbe\xd0\xe6H1\x86\x0b\xbf5)\x16\xbe/\x7fC\x08;\x97\xd9!\xba`1\xb2\xd21|\xe8\xeb1`\xe3\xb5\xa5\xdc{S\x02{\x02c\xc8YT%Rb\x80b\x89\xbd*D\xda\x95\xafT\x1f\xad\xd2H\xb1m\xfb\xb7?\xcf<\x01W}\xb5\x8b\xd9\x00\x00\x00'
225
 
    ),
226
 
    ( './.bzr/revision-store/', ),
227
 
    ( './.bzr/revision-store/mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b.gz',
228
 
        '\x1f\x8b\x08\x081^BC\x00\x03mbp@sourcefrog.net-20051004104921-a98be2278dd30b7b\x00\x9d\x8eMj\xc30\x14\x84\xf7>\x85\xd0"\xbb$\xef\xc9\xb6,\x11\xdb\xf4\x02\x85\xde\xa0\xe8\xe7\xd9\x11\xc4R\x90\xd4@{\xfa\x06\x8a\xa1\xd0]\x97\x03\xdf\xcc|c\xa6G(!E\xe6\xd2\xb6\x85Z)O\xfc\xd5\xe4\x1a"{K\xe9\xc6\x0e\xb7z\xd9\xec\xfd\xa5\xa4\x8f\xech\xc9i=E\xaa\x87\xb5^8\x0b\xf1A\xb1\xa6\xfc\xf9\x1e\xfc\xc4\xffRG\x01\xd0#@\x87\xd0i\x81G\xa3\x95%!\x06\xe5}\x0bv\xb0\xbf\x17\xca\xd5\xe0\xc4-\xa0\xb1\x8b\xb6`\xc0I\xa4\xc5\xf4\x9el\xef\x95v [\x94\xcf\x8e\xd5\xcay\xe4l\xf7\xfe\xf7u\r'
229
 
        '\x1b\x95j\xb6\xfb\xc4\x11\x85\xea\x84\xd0\x12O\x03t\x83D\xad\xc4\x0f\xf0\x95"M\xbc\x95\x00\xc0\xe7f|6\x8aYi^B.u<\xef\xb1\x19\xcf\xbb\xce\xdc|\x038=\xc7\xe6R\x01\x00\x00'
230
 
    ),
231
 
    ( './.bzr/revision-store/mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d.gz',
232
 
        '\x1f\x8b\x08\x08A^BC\x00\x03mbp@sourcefrog.net-20051004104937-c9b7a7bfcc0bb22d\x00\x9d\x90\xc1j\xc30\x0c\x86\xef}\n'
233
 
        "\xe3Coie'\xb1c\x9a\x94\xbe\xc0`o0,[N\x03M\\\x1c\xafe{\xfae\x94n\x85\xc1`;Y\x88O\xd2\xff\xb9Mt\x19\xe6!N\xcc\xc5q\x1cr\xa6\xd4\xf1'\x9b\xf20\xb1\xe7\x18Ol}\xca\xbb\x11\xcf\x879\xbe&G!\xc5~3Q^\xf7y\xc7\xd90]h\xca1\xbd\xbd\x0c\xbe\xe3?\xa9B\x02\xd4\x02\xa0\x12P\x99R\x17\xce\xa0\xb6\x1a\x83s\x80(\xa5\x7f\xdc0\x1f\xad\xe88\x82\xb0\x18\x0c\x82\x05\xa7\x04\x05[{\xc2\xda7\xc6\x81*\x85B\x8dh\x1a\xe7\x05g\xf7\xdc\xff>\x9d\x87\x91\xe6l\xc7s\xc7\x85\x90M%\xa5\xd1z#\x85\xa8\x9b\x1a\xaa\xfa\x06\xbc\xc7\x89:^*\x00\xe0\xfbU\xbbL\xcc\xb6\xa7\xfdH\xa9'\x16\x03\xeb\x8fq\xce\xed\xf6\xde_\xb5g\x9b\x16\xa1y\xa9\xbe\x02&\n"
234
 
        '\x7fJ+EaM\x83$\xa5n\xbc/a\x91~\xd0\xbd\xfd\x135\n'
235
 
        '\xd0\x9a`\x0c*W\x1aR\xc1\x94du\x08(\t\xb0\x91\xdeZ\xa3\x9cU\x9cm\x7f\x8dr\x1d\x10Ot\xb8\xc6\xcf\xa7\x907|\xfb-\xb1\xbd\xd3\xfb\xd5\x07\xeeD\xee\x08*\x02\x00\x00'
236
 
    ),
237
 
]
238
 
 
239
 
_upgrade_dir_template = [
240
 
    ( './.bzr/', ),
241
 
    ( './.bzr/README',
242
 
      'This is a Bazaar control directory.\n'
243
 
      'Do not change any files in this directory.\n'
244
 
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'
245
 
    ),
246
 
    ( './.bzr/branch-format',
247
 
        'Bazaar-NG branch, format 0.0.4\n'
248
 
    ),
249
 
    ( './.bzr/branch-lock',
250
 
        ''
251
 
    ),
252
 
    ( './.bzr/branch-name',
253
 
        ''
254
 
    ),
255
 
    ( './.bzr/inventory',
256
 
        '<inventory>\n'
257
 
        '<entry file_id="dir-20051005095101-da1441ea3fa6917a" kind="directory" name="dir" />\n'
258
 
        '</inventory>\n'
259
 
    ),
260
 
    ( './.bzr/merged-patches',
261
 
        ''
262
 
    ),
263
 
    ( './.bzr/pending-merged-patches',
264
 
        ''
265
 
    ),
266
 
    ( './.bzr/pending-merges',
267
 
        ''
268
 
    ),
269
 
    ( './.bzr/revision-history',
270
 
        'robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e\n'
271
 
    ),
272
 
    ( './.bzr/stat-cache',
273
 
        '### bzr hashcache v5\n'
274
 
    ),
275
 
    ( './.bzr/text-store/', ),
276
 
    ( './.bzr/inventory-store/', ),
277
 
    ( './.bzr/inventory-store/robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e.gz',
278
 
        '\x1f\x8b\x08\x00\x0c\xa2CC\x02\xff\xb3\xc9\xcc+K\xcd+\xc9/\xaa\xb4\xe3\xb2\x012\x8a*\x15\xd22sR\xe33Sl\x95R2\x8bt\x8d\x0c\x0cL\r'
279
 
        "\x81\xd8\xc0\x12H\x19\xea\xa6$\x1a\x9a\x98\x18\xa6&\x1a\xa7%\x9aY\x1a\x9a'*)dg\xe6A\x94\xa6&\x83LQR\xc8K\xccM\x05\x0b()\xe8\x03\xcd\xd4G\xb2\x00\x00\xc2<\x94\xb1m\x00\x00\x00"
280
 
    ),
281
 
    ( './.bzr/revision-store/', ),
282
 
    ( './.bzr/revision-store/robertc@robertcollins.net-20051005095108-6065fbd8e7d8617e.gz',
283
 
        '\x1f\x8b\x08\x00\x0c\xa2CC\x02\xff\xa5OKj\xc30\x14\xdc\xfb\x14B\x8b\xec\x92<I\xd6\xc7\xc42\x85\xde\xa0\x17(\xb6\xf4\x9c\n'
284
 
        'l\xa9H"\x90\x9c\xbe\xa6\xa9\xa1\x9b\xae\xbax\x0c\xcc\xe71\xd3g\xbc\x85\x12R$.\xadk\xa8\x15\xb3\xa5oi\xc2\\\xc9kZ\x96\x10\x0b9,\xf5\x92\xbf)\xf7\xf2\x83O\xe5\x14\xb1\x1e\xae\xf5BI\x887\x8c5\xe5\xfb{\xf0\x96\xfei>r\x00\xc9\xb6\x83n\x03sT\xa0\xe4<y\x83\xda\x1b\xc54\xfe~T>Ff\xe9\xcc:\xdd\x8e\xa6E\xc7@\xa2\x82I\xaaNL\xbas\\313)\x00\xb9\xe6\xe0(\xd9\x87\xfc\xb7A\r'
285
 
        "+\x96:\xae\x9f\x962\xc6\x8d\x04i\x949\x01\x97R\xb7\x1d\x17O\xc3#E\xb4T(\x00\xa0C\xd3o\x892^q\x18\xbd'>\xe4\xfe\xbc\x13M\x7f\xde{\r"
286
 
        '\xcd\x17\x85\xea\xba\x03l\x01\x00\x00'
287
 
    ),
288
 
    ( './dir/', ),
289
 
]
290
 
 
291
 
 
292
 
class TestUpgrade(TestCaseWithTransport):
293
 
 
294
 
    def test_upgrade_v6_to_meta_no_workingtree(self):
295
 
        # Some format6 branches do not have checkout files. Upgrading
296
 
        # such a branch to metadir must not setup a working tree.
297
 
        self.build_tree_contents(_upgrade1_template)
298
 
        upgrade.upgrade('.', BzrDirFormat6())
299
 
        t = self.get_transport('.')
300
 
        t.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
301
 
        self.assertFalse(t.has('.bzr/stat-cache'))
302
 
        t.delete_tree('backup.bzr.~1~')
303
 
        # At this point, we have a format6 branch without checkout files.
304
 
        upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
305
 
        # The upgrade should not have set up a working tree.
306
 
        control = controldir.ControlDir.open('.')
307
 
        self.assertFalse(control.has_workingtree())
308
 
        # We have covered the scope of this test, we may as well check that
309
 
        # upgrade has not eaten our data, even if it's a bit redundant with
310
 
        # other tests.
311
 
        self.assertIsInstance(control._format, bzrdir.BzrDirMetaFormat1)
312
 
        b = control.open_branch()
313
 
        self.addCleanup(b.lock_read().unlock)
314
 
        self.assertEqual(b._revision_history(),
315
 
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
316
 
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
317
 
 
318
 
    def test_upgrade_simple(self):
319
 
        """Upgrade simple v0.0.4 format to latest format"""
320
 
        eq = self.assertEqual
321
 
        self.build_tree_contents(_upgrade1_template)
322
 
        upgrade.upgrade(u'.')
323
 
        control = controldir.ControlDir.open('.')
324
 
        b = control.open_branch()
325
 
        # tsk, peeking under the covers.
326
 
        self.assertIsInstance(
327
 
            control._format,
328
 
            bzrdir.BzrDirFormat.get_default_format().__class__)
329
 
        self.addCleanup(b.lock_read().unlock)
330
 
        rh = b._revision_history()
331
 
        eq(rh,
332
 
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
333
 
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
334
 
        rt = b.repository.revision_tree(rh[0])
335
 
        foo_id = 'foo-20051004035605-91e788d1875603ae'
336
 
        rt.lock_read()
337
 
        try:
338
 
            eq(rt.get_file_text(foo_id), 'initial contents\n')
339
 
        finally:
340
 
            rt.unlock()
341
 
        rt = b.repository.revision_tree(rh[1])
342
 
        rt.lock_read()
343
 
        try:
344
 
            eq(rt.get_file_text(foo_id), 'new contents\n')
345
 
        finally:
346
 
            rt.unlock()
347
 
        # check a backup was made:
348
 
        backup_dir = 'backup.bzr.~1~'
349
 
        t = self.get_transport('.')
350
 
        t.stat(backup_dir)
351
 
        t.stat(backup_dir + '/README')
352
 
        t.stat(backup_dir + '/branch-format')
353
 
        t.stat(backup_dir + '/revision-history')
354
 
        t.stat(backup_dir + '/merged-patches')
355
 
        t.stat(backup_dir + '/pending-merged-patches')
356
 
        t.stat(backup_dir + '/pending-merges')
357
 
        t.stat(backup_dir + '/branch-name')
358
 
        t.stat(backup_dir + '/branch-lock')
359
 
        t.stat(backup_dir + '/inventory')
360
 
        t.stat(backup_dir + '/stat-cache')
361
 
        t.stat(backup_dir + '/text-store')
362
 
        t.stat(backup_dir + '/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
363
 
        t.stat(backup_dir + '/text-store/foo-20051004035756-4081373d897c3453.gz')
364
 
        t.stat(backup_dir + '/inventory-store/')
365
 
        t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
366
 
        t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
367
 
        t.stat(backup_dir + '/revision-store/')
368
 
        t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
369
 
        t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
370
 
 
371
 
    def test_upgrade_with_ghosts(self):
372
 
        """Upgrade v0.0.4 tree containing ghost references.
373
 
 
374
 
        That is, some of the parents of revisions mentioned in the branch
375
 
        aren't present in the branch's storage.
376
 
 
377
 
        This shouldn't normally happen in branches created entirely in
378
 
        bzr, but can happen in branches imported from baz and arch, or from
379
 
        other systems, where the importer knows about a revision but not
380
 
        its contents."""
381
 
        eq = self.assertEqual
382
 
        self.build_tree_contents(_ghost_template)
383
 
        upgrade.upgrade(u'.')
384
 
        b = branch.Branch.open(u'.')
385
 
        self.addCleanup(b.lock_read().unlock)
386
 
        revision_id = b._revision_history()[1]
387
 
        rev = b.repository.get_revision(revision_id)
388
 
        eq(len(rev.parent_ids), 2)
389
 
        eq(rev.parent_ids[1], 'wibble@wobble-2')
390
 
 
391
 
    def test_upgrade_makes_dir_weaves(self):
392
 
        self.build_tree_contents(_upgrade_dir_template)
393
 
        old_repodir = controldir.ControlDir.open_unsupported('.')
394
 
        old_repo_format = old_repodir.open_repository()._format
395
 
        upgrade.upgrade('.')
396
 
        # this is the path to the literal file. As format changes
397
 
        # occur it needs to be updated. FIXME: ask the store for the
398
 
        # path.
399
 
        repo = repository.Repository.open('.')
400
 
        # it should have changed the format
401
 
        self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
402
 
        # and we should be able to read the names for the file id
403
 
        # 'dir-20051005095101-da1441ea3fa6917a'
404
 
        repo.lock_read()
405
 
        self.addCleanup(repo.unlock)
406
 
        text_keys = repo.texts.keys()
407
 
        dir_keys = [key for key in text_keys if key[0] ==
408
 
                'dir-20051005095101-da1441ea3fa6917a']
409
 
        self.assertNotEqual([], dir_keys)
410
 
 
411
 
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
412
 
        self.build_tree_contents(_upgrade_dir_template)
413
 
        upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
414
 
        tree = workingtree.WorkingTree.open('.')
415
 
        self.addCleanup(tree.lock_read().unlock)
416
 
        self.assertEqual([tree.branch._revision_history()[-1]],
417
 
            tree.get_parent_ids())
418
 
 
419
 
 
420
 
class SFTPBranchTest(TestCaseWithSFTPServer):
421
 
    """Test some stuff when accessing a bzr Branch over sftp"""
422
 
 
423
 
    def test_lock_file(self):
424
 
        # old format branches use a special lock file on sftp.
425
 
        b = self.make_branch('', format=BzrDirFormat6())
426
 
        b = branch.Branch.open(self.get_url())
427
 
        self.assertPathExists('.bzr/')
428
 
        self.assertPathExists('.bzr/branch-format')
429
 
        self.assertPathExists('.bzr/branch-lock')
430
 
 
431
 
        self.assertPathDoesNotExist('.bzr/branch-lock.write-lock')
432
 
        b.lock_write()
433
 
        self.assertPathExists('.bzr/branch-lock.write-lock')
434
 
        b.unlock()
435
 
        self.assertPathDoesNotExist('.bzr/branch-lock.write-lock')
436
 
 
437
 
 
438
 
class TestInfo(TestCaseWithTransport):
439
 
 
440
 
    def test_info_locking_oslocks(self):
441
 
        if sys.platform == "win32":
442
 
            self.skip("don't use oslocks on win32 in unix manner")
443
 
        # This test tests old (all-in-one, OS lock using) behaviour which
444
 
        # simply cannot work on windows (and is indeed why we changed our
445
 
        # design. As such, don't try to remove the thisFailsStrictLockCheck
446
 
        # call here.
447
 
        self.thisFailsStrictLockCheck()
448
 
 
449
 
        tree = self.make_branch_and_tree('branch',
450
 
                                         format=BzrDirFormat6())
451
 
 
452
 
        # Test all permutations of locking the working tree, branch and repository
453
 
        # XXX: Well not yet, as we can't query oslocks yet. Currently, it's
454
 
        # implemented by raising NotImplementedError and get_physical_lock_status()
455
 
        # always returns false. This makes bzr info hide the lock status.  (Olaf)
456
 
        # W B R
457
 
 
458
 
        # U U U
459
 
        out, err = self.run_bzr('info -v branch')
460
 
        self.assertEqualDiff(
461
 
"""Standalone tree (format: weave)
462
 
Location:
463
 
  branch root: %s
464
 
 
465
 
Format:
466
 
       control: All-in-one format 6
467
 
  working tree: Working tree format 2
468
 
        branch: Branch format 4
469
 
    repository: %s
470
 
 
471
 
In the working tree:
472
 
         0 unchanged
473
 
         0 modified
474
 
         0 added
475
 
         0 removed
476
 
         0 renamed
477
 
         0 unknown
478
 
         0 ignored
479
 
         0 versioned subdirectories
480
 
 
481
 
Branch history:
482
 
         0 revisions
483
 
 
484
 
Repository:
485
 
         0 revisions
486
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
487
 
       ), out)
488
 
        self.assertEqual('', err)
489
 
        # L L L
490
 
        tree.lock_write()
491
 
        out, err = self.run_bzr('info -v branch')
492
 
        self.assertEqualDiff(
493
 
"""Standalone tree (format: weave)
494
 
Location:
495
 
  branch root: %s
496
 
 
497
 
Format:
498
 
       control: All-in-one format 6
499
 
  working tree: Working tree format 2
500
 
        branch: Branch format 4
501
 
    repository: %s
502
 
 
503
 
In the working tree:
504
 
         0 unchanged
505
 
         0 modified
506
 
         0 added
507
 
         0 removed
508
 
         0 renamed
509
 
         0 unknown
510
 
         0 ignored
511
 
         0 versioned subdirectories
512
 
 
513
 
Branch history:
514
 
         0 revisions
515
 
 
516
 
Repository:
517
 
         0 revisions
518
 
""" % ('branch', tree.branch.repository._format.get_format_description(),
519
 
       ), out)
520
 
        self.assertEqual('', err)
521
 
        tree.unlock()
522
 
 
523
 
 
524
 
class TestBranchFormat4(TestCaseWithTransport):
525
 
    """Tests specific to branch format 4"""
526
 
 
527
 
    def test_no_metadir_support(self):
528
 
        url = self.get_url()
529
 
        bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
530
 
        bdir.create_repository()
531
 
        self.assertRaises(errors.IncompatibleFormat,
532
 
            BzrBranchFormat4().initialize, bdir)
533
 
 
534
 
    def test_supports_bzrdir_6(self):
535
 
        url = self.get_url()
536
 
        bdir = BzrDirFormat6().initialize(url)
537
 
        bdir.create_repository()
538
 
        BzrBranchFormat4().initialize(bdir)
539
 
 
540
 
 
541
 
class TestBoundBranch(TestCaseWithTransport):
542
 
 
543
 
    def setUp(self):
544
 
        super(TestBoundBranch, self).setUp()
545
 
        self.build_tree(['master/', 'child/'])
546
 
        self.make_branch_and_tree('master')
547
 
        self.make_branch_and_tree('child',
548
 
                        format=controldir.format_registry.make_bzrdir('weave'))
549
 
        os.chdir('child')
550
 
 
551
 
    def test_bind_format_6_bzrdir(self):
552
 
        # bind on a format 6 bzrdir should error
553
 
        out,err = self.run_bzr('bind ../master', retcode=3)
554
 
        self.assertEqual('', out)
555
 
        # TODO: jam 20060427 Probably something like this really should
556
 
        #       print out the actual path, rather than the URL
557
 
        cwd = urlutils.local_path_to_url(getcwd())
558
 
        self.assertEqual('bzr: ERROR: To use this feature you must '
559
 
                         'upgrade your branch at %s/.\n' % cwd, err)
560
 
 
561
 
    def test_unbind_format_6_bzrdir(self):
562
 
        # bind on a format 6 bzrdir should error
563
 
        out,err = self.run_bzr('unbind', retcode=3)
564
 
        self.assertEqual('', out)
565
 
        cwd = urlutils.local_path_to_url(getcwd())
566
 
        self.assertEqual('bzr: ERROR: To use this feature you must '
567
 
                         'upgrade your branch at %s/.\n' % cwd, err)
568
 
 
569
 
 
570
 
class TestInit(TestCaseWithTransport):
571
 
 
572
 
    def test_init_weave(self):
573
 
        # --format=weave should be accepted to allow interoperation with
574
 
        # old releases when desired.
575
 
        out, err = self.run_bzr('init --format=weave')
576
 
        self.assertEqual("""Created a standalone tree (format: weave)\n""",
577
 
            out)
578
 
        self.assertEqual('', err)
579
 
 
580
 
 
581
 
class V4WeaveBundleTester(V4BundleTester):
582
 
 
583
 
    def bzrdir_format(self):
584
 
        return 'metaweave'