~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# Copyright (C) 2007 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import sys
from urllib import quote

from bzrlib import (
    branch as _mod_branch,
    bzrdir,
    info,
    tests,
    workingtree,
    repository as _mod_repository,
    )


class TestInfo(tests.TestCaseWithTransport):

    def test_describe_standalone_layout(self):
        tree = self.make_branch_and_tree('tree')
        self.assertEqual('Empty control directory', info.describe_layout())
        self.assertEqual('Unshared repository with trees',
            info.describe_layout(tree.branch.repository))
        tree.branch.repository.set_make_working_trees(False)
        self.assertEqual('Unshared repository',
            info.describe_layout(tree.branch.repository))
        self.assertEqual('Standalone branch',
            info.describe_layout(tree.branch.repository, tree.branch))
        self.assertEqual('Standalone branchless tree',
            info.describe_layout(tree.branch.repository, None, tree))
        self.assertEqual('Standalone tree',
            info.describe_layout(tree.branch.repository, tree.branch, tree))
        tree.branch.bind(tree.branch)
        self.assertEqual('Bound branch',
            info.describe_layout(tree.branch.repository, tree.branch))
        self.assertEqual('Checkout',
            info.describe_layout(tree.branch.repository, tree.branch, tree))
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
        self.assertEqual('Lightweight checkout',
            info.describe_layout(checkout.branch.repository, checkout.branch,
                                 checkout))

    def test_describe_repository_layout(self):
        repository = self.make_repository('.', shared=True)
        tree = bzrdir.BzrDir.create_branch_convenience('tree',
            force_new_tree=True).bzrdir.open_workingtree()
        self.assertEqual('Shared repository with trees',
            info.describe_layout(tree.branch.repository))
        repository.set_make_working_trees(False)
        self.assertEqual('Shared repository',
            info.describe_layout(tree.branch.repository))
        self.assertEqual('Repository branch',
            info.describe_layout(tree.branch.repository, tree.branch))
        self.assertEqual('Repository branchless tree',
            info.describe_layout(tree.branch.repository, None, tree))
        self.assertEqual('Repository tree',
            info.describe_layout(tree.branch.repository, tree.branch, tree))
        tree.branch.bind(tree.branch)
        self.assertEqual('Repository checkout',
            info.describe_layout(tree.branch.repository, tree.branch, tree))
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
        self.assertEqual('Lightweight checkout',
            info.describe_layout(checkout.branch.repository, checkout.branch,
                                 checkout))

    def assertTreeDescription(self, format):
        """Assert a tree's format description matches expectations"""
        self.make_branch_and_tree('%s_tree' % format, format=format)
        tree = workingtree.WorkingTree.open('%s_tree' % format)
        self.assertEqual(format, info.describe_format(tree.bzrdir,
            tree.branch.repository, tree.branch, tree))

    def assertCheckoutDescription(self, format, expected=None):
        """Assert a checkout's format description matches expectations"""
        if expected is None:
            expected = format
        branch = self.make_branch('%s_cobranch' % format, format=format)
        # this ought to be easier...
        branch.create_checkout('%s_co' % format,
            lightweight=True).bzrdir.destroy_workingtree()
        control = bzrdir.BzrDir.open('%s_co' % format)
        old_format = control._format.workingtree_format
        try:
            control._format.workingtree_format = \
                bzrdir.format_registry.make_bzrdir(format).workingtree_format
            control.create_workingtree()
            tree = workingtree.WorkingTree.open('%s_co' % format)
            format_description = info.describe_format(tree.bzrdir,
                    tree.branch.repository, tree.branch, tree)
            self.assertEqual(expected, format_description,
                "checkout of format called %r was described as %r" %
                (expected, format_description))
        finally:
            control._format.workingtree_format = old_format

    def assertBranchDescription(self, format, expected=None):
        """Assert branch's format description matches expectations"""
        if expected is None:
            expected = format
        self.make_branch('%s_branch' % format, format=format)
        branch = _mod_branch.Branch.open('%s_branch' % format)
        self.assertEqual(expected, info.describe_format(branch.bzrdir,
            branch.repository, branch, None))

    def assertRepoDescription(self, format, expected=None):
        """Assert repository's format description matches expectations"""
        if expected is None:
            expected = format
        self.make_repository('%s_repo' % format, format=format)
        repo = _mod_repository.Repository.open('%s_repo' % format)
        self.assertEqual(expected, info.describe_format(repo.bzrdir,
            repo, None, None))

    def test_describe_tree_format(self):
        for key in bzrdir.format_registry.keys():
            if key in bzrdir.format_registry.aliases():
                continue
            self.assertTreeDescription(key)

    def test_describe_checkout_format(self):
        for key in bzrdir.format_registry.keys():
            if key in bzrdir.format_registry.aliases():
                # Aliases will not describe correctly in the UI because the
                # real format is found.
                continue
            # legacy: weave does not support checkouts
            if key == 'weave':
                continue
            if bzrdir.format_registry.get_info(key).experimental:
                # We don't require that experimental formats support checkouts
                # or describe correctly in the UI.
                continue
            expected = None
            if key in ('dirstate', 'dirstate-tags', 'dirstate-with-subtree',
                'pack-0.92', 'pack-0.92-subtree', 'rich-root',
                'rich-root-pack', '1.6', '1.6.1-rich-root',
                '1.9', '1.9-rich-root'):
                expected = '1.6 or 1.6.1-rich-root or ' \
                    '1.9 or 1.9-rich-root or ' \
                    'dirstate or dirstate-tags or pack-0.92 or'\
                    ' rich-root or rich-root-pack'
            elif key in ('knit', 'metaweave'):
                expected = 'knit or metaweave'
            elif key in ('development-wt5', 'development-wt5-rich-root'):
                expected = 'development-wt5 or development-wt5-rich-root'
            self.assertCheckoutDescription(key, expected)

    def test_describe_branch_format(self):
        for key in bzrdir.format_registry.keys():
            if key in bzrdir.format_registry.aliases():
                continue
            expected = None
            if key in ('dirstate', 'knit'):
                expected = 'dirstate or knit'
            elif key in ('1.9', 'development-wt5'):
                expected = '1.9 or development-wt5'
            elif key in ('1.9-rich-root', 'development-wt5-rich-root'):
                expected = '1.9-rich-root or development-wt5-rich-root'
            self.assertBranchDescription(key, expected)

    def test_describe_repo_format(self):
        for key in bzrdir.format_registry.keys():
            if key in bzrdir.format_registry.aliases():
                continue
            expected = None
            if key in ('dirstate', 'knit', 'dirstate-tags'):
                expected = 'dirstate or dirstate-tags or knit'
            elif key in ('1.9', 'development-wt5'):
                expected = '1.9 or development-wt5'
            elif key in ('1.9-rich-root', 'development-wt5-rich-root'):
                expected = '1.9-rich-root or development-wt5-rich-root'
            self.assertRepoDescription(key, expected)

        format = bzrdir.format_registry.make_bzrdir('metaweave')
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
        tree = self.make_branch_and_tree('unknown', format=format)
        self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
            tree.branch.repository, tree.branch, tree))

    def test_gather_location_standalone(self):
        tree = self.make_branch_and_tree('tree')
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
            info.gather_location_info(tree.branch.repository, tree.branch,
                                      tree))
        self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
            info.gather_location_info(tree.branch.repository, tree.branch))
        return tree

    def test_gather_location_repo(self):
        srepo = self.make_repository('shared', shared=True)
        self.assertEqual([('shared repository',
                          srepo.bzrdir.root_transport.base)],
                          info.gather_location_info(srepo))
        urepo = self.make_repository('unshared')
        self.assertEqual([('repository',
                          urepo.bzrdir.root_transport.base)],
                          info.gather_location_info(urepo))

    def test_gather_location_repo_branch(self):
        srepo = self.make_repository('shared', shared=True)
        self.assertEqual([('shared repository',
                          srepo.bzrdir.root_transport.base)],
                          info.gather_location_info(srepo))
        tree = self.make_branch_and_tree('shared/tree')
        self.assertEqual([('shared repository',
                          srepo.bzrdir.root_transport.base),
                          ('repository branch', tree.branch.base)],
                          info.gather_location_info(srepo, tree.branch, tree))

    def test_gather_location_light_checkout(self):
        tree = self.make_branch_and_tree('tree')
        lcheckout = tree.branch.create_checkout('lcheckout', lightweight=True)
        self.assertEqual(
            [('light checkout root', lcheckout.bzrdir.root_transport.base),
             ('checkout of branch', tree.bzrdir.root_transport.base)],
            self.gather_tree_location_info(lcheckout))

    def test_gather_location_heavy_checkout(self):
        tree = self.make_branch_and_tree('tree')
        checkout = tree.branch.create_checkout('checkout')
        self.assertEqual(
            [('checkout root', checkout.bzrdir.root_transport.base),
             ('checkout of branch', tree.bzrdir.root_transport.base)],
            self.gather_tree_location_info(checkout))
        light_checkout = checkout.branch.create_checkout('light_checkout',
                                                         lightweight=True)
        self.assertEqual(
            [('light checkout root',
              light_checkout.bzrdir.root_transport.base),
             ('checkout root', checkout.bzrdir.root_transport.base),
             ('checkout of branch', tree.bzrdir.root_transport.base)],
             self.gather_tree_location_info(light_checkout)
             )

    def test_gather_location_shared_repo_checkout(self):
        tree = self.make_branch_and_tree('tree')
        srepo = self.make_repository('shared', shared=True)
        shared_checkout = tree.branch.create_checkout('shared/checkout')
        self.assertEqual(
            [('repository checkout root',
              shared_checkout.bzrdir.root_transport.base),
             ('checkout of branch', tree.bzrdir.root_transport.base),
             ('shared repository', srepo.bzrdir.root_transport.base)],
             self.gather_tree_location_info(shared_checkout))

    def gather_tree_location_info(self, tree):
        return info.gather_location_info(tree.branch.repository, tree.branch,
                                         tree)

    def test_gather_location_bound(self):
        branch = self.make_branch('branch')
        bound_branch = self.make_branch('bound_branch')
        bound_branch.bind(branch)
        self.assertEqual(
            [('branch root', bound_branch.bzrdir.root_transport.base),
             ('bound to branch', branch.bzrdir.root_transport.base)],
            info.gather_location_info(bound_branch.repository, bound_branch)
        )

    def test_location_list(self):
        if sys.platform == 'win32':
            raise tests.TestSkipped('Windows-unfriendly test')
        locs = info.LocationList('/home/foo')
        locs.add_url('a', 'file:///home/foo/')
        locs.add_url('b', 'file:///home/foo/bar/')
        locs.add_url('c', 'file:///home/bar/bar')
        locs.add_url('d', 'http://example.com/example/')
        locs.add_url('e', None)
        self.assertEqual(locs.locs, [('a', '.'),
                                     ('b', 'bar'),
                                     ('c', '/home/bar/bar'),
                                     ('d', 'http://example.com/example/')])
        self.assertEqualDiff('  a: .\n  b: bar\n  c: /home/bar/bar\n'
                             '  d: http://example.com/example/\n',
                             ''.join(locs.get_lines()))

    def test_gather_related_braches(self):
        branch = self.make_branch('.')
        branch.set_public_branch('baz')
        branch.set_push_location('bar')
        branch.set_parent('foo')
        branch.set_submit_branch('qux')
        self.assertEqual(
            [('public branch', 'baz'), ('push branch', 'bar'),
             ('parent branch', 'foo'), ('submit branch', 'qux')],
            info._gather_related_branches(branch).locs)