~bzr-pqm/bzr/bzr.dev

2796.2.5 by Aaron Bentley
Implement reconfigure command
1
# Copyright (C) 2007 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2796.2.5 by Aaron Bentley
Implement reconfigure command
16
17
from bzrlib import (
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
18
    bzrdir,
2796.2.5 by Aaron Bentley
Implement reconfigure command
19
    errors,
20
    tests,
21
    workingtree,
22
    )
23
24
2796.2.17 by Aaron Bentley
Update docs from review
25
class TestReconfigure(tests.TestCaseWithTransport):
2796.2.5 by Aaron Bentley
Implement reconfigure command
26
2796.2.15 by Aaron Bentley
More updates from review
27
    def test_no_type(self):
28
        branch = self.make_branch('branch')
29
        self.run_bzr_error(['No target configuration specified'],
30
                           'reconfigure branch')
31
2796.2.5 by Aaron Bentley
Implement reconfigure command
32
    def test_branch_to_tree(self):
33
        branch = self.make_branch('branch')
34
        self.run_bzr('reconfigure --tree branch')
35
        tree = workingtree.WorkingTree.open('branch')
36
37
    def test_tree_to_branch(self):
38
        tree = self.make_branch_and_tree('tree')
39
        self.run_bzr('reconfigure --branch tree')
40
        self.assertRaises(errors.NoWorkingTree,
41
                          workingtree.WorkingTree.open, 'tree')
42
43
    def test_branch_to_specified_checkout(self):
44
        branch = self.make_branch('branch')
45
        parent = self.make_branch('parent')
46
        self.run_bzr('reconfigure branch --checkout --bind-to parent')
47
48
    def test_force(self):
49
        tree = self.make_branch_and_tree('tree')
50
        self.build_tree(['tree/file'])
51
        tree.add('file')
52
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
53
                            'reconfigure --branch tree')
54
        self.run_bzr('reconfigure --force --branch tree')
55
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
56
    def test_lightweight_checkout_to_checkout(self):
57
        branch = self.make_branch('branch')
58
        checkout = branch.create_checkout('checkout', lightweight=True)
59
        self.run_bzr('reconfigure --checkout checkout')
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
60
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
61
    def test_lightweight_checkout_to_tree(self):
62
        branch = self.make_branch('branch')
63
        checkout = branch.create_checkout('checkout', lightweight=True)
64
        self.run_bzr('reconfigure --tree checkout')
65
2846.1.1 by Rob Weir
add blackbox test for 'bzr reconfigure', which now fails.
66
    def test_no_args(self):
67
        branch = self.make_branch('branch')
2846.1.3 by Rob Weir
add check of error text.
68
        self.run_bzr_error(['No target configuration specified'],
69
                           'reconfigure', working_dir='branch')
2796.2.22 by Aaron Bentley
Tweak from review
70
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
71
    def test_checkout_to_lightweight_checkout(self):
72
        branch = self.make_branch('branch')
73
        checkout = branch.create_checkout('checkout')
74
        self.run_bzr('reconfigure --lightweight-checkout checkout')
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
75
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
76
    def test_standalone_to_use_shared(self):
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
77
        self.build_tree(['repo/'])
78
        tree = self.make_branch_and_tree('repo/tree')
79
        repo = self.make_repository('repo', shared=True)
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
80
        self.run_bzr('reconfigure --use-shared', working_dir='repo/tree')
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
81
        tree = workingtree.WorkingTree.open('repo/tree')
82
        self.assertNotEqual(tree.bzrdir.root_transport.base,
83
            tree.branch.repository.bzrdir.root_transport.base)
84
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
85
    def test_use_shared_to_standalone(self):
3311.2.5 by Aaron Bentley
Implement reconfigure --standalone and --sharing
86
        repo = self.make_repository('repo', shared=True)
87
        branch = bzrdir.BzrDir.create_branch_convenience('repo/tree')
88
        self.assertNotEqual(branch.bzrdir.root_transport.base,
89
            branch.repository.bzrdir.root_transport.base)
90
        self.run_bzr('reconfigure --standalone', working_dir='repo/tree')
91
        tree = workingtree.WorkingTree.open('repo/tree')
92
        self.assertEqual(tree.bzrdir.root_transport.base,
93
            tree.branch.repository.bzrdir.root_transport.base)
3921.4.6 by Matthew Fuller
Add blackbox tests for reconfigure {--with-trees,--with-no-trees}.
94
95
    def test_make_with_trees(self):
96
        repo = self.make_repository('repo', shared=True)
97
        repo.set_make_working_trees(False)
98
        self.run_bzr('reconfigure --with-trees', working_dir='repo')
99
        self.assertIs(True, repo.make_working_trees())
100
101
    def test_make_with_trees_already_trees(self):
102
        repo = self.make_repository('repo', shared=True)
103
        repo.set_make_working_trees(True)
104
        self.run_bzr_error([" already creates working trees"],
105
                            'reconfigure --with-trees repo')
106
107
    def test_make_without_trees(self):
108
        repo = self.make_repository('repo', shared=True)
109
        repo.set_make_working_trees(True)
110
        self.run_bzr('reconfigure --with-no-trees', working_dir='repo')
111
        self.assertIs(False, repo.make_working_trees())
112
113
    def test_make_without_trees_already_no_trees(self):
114
        repo = self.make_repository('repo', shared=True)
115
        repo.set_make_working_trees(False)
116
        self.run_bzr_error([" already doesn't create working trees"],
117
                            'reconfigure --with-no-trees repo')
3921.4.7 by Matthew Fuller
Add a blackbox test for the expected failure trying to change --trees
118
119
    def test_make_with_trees_nonshared_repo(self):
120
        branch = self.make_branch('branch')
121
        self.run_bzr_error(
122
            ["Requested reconfiguration of '.*' is not supported"],
123
            'reconfigure --with-trees branch')
3921.4.11 by Matthew Fuller
Add a test that --with-no-trees doesn't touch a branch's existing WT.
124
125
    def test_make_without_trees_leaves_tree_alone(self):
126
        repo = self.make_repository('repo', shared=True)
3983.3.3 by Marius Kruger
refactor test_make_without_trees_leaves_tree_alone a little
127
        branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
128
        tree = workingtree.WorkingTree.open('repo/branch')
3921.4.11 by Matthew Fuller
Add a test that --with-no-trees doesn't touch a branch's existing WT.
129
        self.build_tree(['repo/branch/foo'])
130
        tree.add('foo')
3983.3.3 by Marius Kruger
refactor test_make_without_trees_leaves_tree_alone a little
131
        self.run_bzr('reconfigure --with-no-trees --force',
3921.4.11 by Matthew Fuller
Add a test that --with-no-trees doesn't touch a branch's existing WT.
132
            working_dir='repo/branch')
133
        self.failUnlessExists('repo/branch/foo')
3983.3.3 by Marius Kruger
refactor test_make_without_trees_leaves_tree_alone a little
134
        tree = workingtree.WorkingTree.open('repo/branch')
4297.4.1 by Martin von Gagern
Added blackbox tests to expose LP bug #248932.
135
136
    def test_shared_format_to_standalone(self, format=None):
137
        repo = self.make_repository('repo', shared=True, format=format)
138
        branch = bzrdir.BzrDir.create_branch_convenience('repo/tree')
139
        self.assertNotEqual(branch.bzrdir.root_transport.base,
140
            branch.repository.bzrdir.root_transport.base)
141
        tree = workingtree.WorkingTree.open('repo/tree')
142
        self.build_tree_contents([('repo/tree/file', 'foo\n')]);
143
        tree.add(['file'])
144
        tree.commit('added file')
145
        self.run_bzr('reconfigure --standalone', working_dir='repo/tree')
146
        tree = workingtree.WorkingTree.open('repo/tree')
147
        self.build_tree_contents([('repo/tree/file', 'bar\n')]);
148
        self.check_file_contents('repo/tree/file', 'bar\n')
149
        self.run_bzr('revert', working_dir='repo/tree')
150
        self.check_file_contents('repo/tree/file', 'foo\n')
151
        self.assertEqual(tree.bzrdir.root_transport.base,
152
            tree.branch.repository.bzrdir.root_transport.base)
153
154
    def test_shared_knit_to_standalone(self):
155
        self.test_shared_format_to_standalone('knit')
156
157
    def test_shared_pack092_to_standalone(self):
158
        self.test_shared_format_to_standalone('pack-0.92')
159
160
    def test_shared_rich_root_pack_to_standalone(self):
161
        self.test_shared_format_to_standalone('rich-root-pack')
4297.4.4 by Martin von Gagern
Testcase exposing bug when creating a repository for a lightweight branch.
162
163
    def test_lightweight_format_checkout_to_tree(self, format=None):
164
        branch = self.make_branch('branch', format=format)
165
        checkout = branch.create_checkout('checkout', lightweight=True)
166
        tree = workingtree.WorkingTree.open('checkout')
167
        self.build_tree_contents([('checkout/file', 'foo\n')]);
168
        tree.add(['file'])
169
        tree.commit('added file')
170
        self.run_bzr('reconfigure --tree', working_dir='checkout')
171
        tree = workingtree.WorkingTree.open('checkout')
172
        self.build_tree_contents([('checkout/file', 'bar\n')]);
173
        self.check_file_contents('checkout/file', 'bar\n')
174
        self.run_bzr('revert', working_dir='checkout')
175
        self.check_file_contents('checkout/file', 'foo\n')
176
177
    def test_lightweight_knit_checkout_to_tree(self, format=None):
178
        self.test_lightweight_format_checkout_to_tree('knit')
179
180
    def test_lightweight_pack092_checkout_to_tree(self, format=None):
181
        self.test_lightweight_format_checkout_to_tree('pack-0.92')
182
183
    def test_lightweight_rich_root_pack_checkout_to_tree(self, format=None):
184
        self.test_lightweight_format_checkout_to_tree('rich-root-pack')