/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3549.1.1 by Martin Pool
rename push --reference to --stacked-on
1
# Copyright (C) 2005, 2007, 2008 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
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
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
16
17
1692.3.1 by Robert Collins
Fix push to work with just a branch, no need for a working tree.
18
"""Black-box tests for bzr push."""
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
19
3066.3.2 by jml at canonical
Add tests to check the handling of TooManyRedirections.
20
import re
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
21
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
22
from bzrlib import (
4420.1.1 by Vincent Ladeuil
Cleanup imports.
23
    branch,
24
    bzrdir,
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
25
    errors,
4420.1.1 by Vincent Ladeuil
Cleanup imports.
26
    osutils,
27
    tests,
3878.4.4 by Vincent Ladeuil
Cleanup.
28
    transport,
4420.1.1 by Vincent Ladeuil
Cleanup imports.
29
    uncommit,
2220.2.9 by Martin Pool
Add specific tests for push -d and pull -d
30
    urlutils,
4420.1.1 by Vincent Ladeuil
Cleanup imports.
31
    workingtree
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
32
    )
4420.1.1 by Vincent Ladeuil
Cleanup imports.
33
from bzrlib.repofmt import knitrepo
34
from bzrlib.tests import http_server
35
from bzrlib.transport import memory
36
37
38
class TestPush(tests.TestCaseWithTransport):
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
39
4017.2.3 by Robert Collins
Review feedback.
40
    def test_push_error_on_vfs_http(self):
41
        """ pushing a branch to a HTTP server fails cleanly. """
42
        # the trunk is published on a web server
4420.1.1 by Vincent Ladeuil
Cleanup imports.
43
        self.transport_readonly_server = http_server.HttpServer
4017.2.3 by Robert Collins
Review feedback.
44
        self.make_branch('source')
45
        public_url = self.get_readonly_url('target')
46
        self.run_bzr_error(['http does not support mkdir'],
47
                           ['push', public_url],
48
                           working_dir='source')
49
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
50
    def test_push_remember(self):
51
        """Push changes from one branch to another and test push location."""
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
52
        transport = self.get_transport()
53
        tree_a = self.make_branch_and_tree('branch_a')
54
        branch_a = tree_a.branch
55
        self.build_tree(['branch_a/a'])
56
        tree_a.add('a')
57
        tree_a.commit('commit a')
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
58
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
59
        branch_b = tree_b.branch
60
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
61
        branch_c = tree_c.branch
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
62
        self.build_tree(['branch_a/b'])
63
        tree_a.add('b')
64
        tree_a.commit('commit b')
65
        self.build_tree(['branch_b/c'])
66
        tree_b.add('c')
67
        tree_b.commit('commit c')
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
68
        # initial push location must be empty
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
69
        self.assertEqual(None, branch_b.get_push_location())
1785.1.2 by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed)
70
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
71
        # test push for failure without push location set
4420.1.1 by Vincent Ladeuil
Cleanup imports.
72
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
73
        self.assertEquals(out,
74
                ('','bzr: ERROR: No push location known or specified.\n'))
1785.1.2 by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed)
75
76
        # test not remembered if cannot actually push
4420.1.1 by Vincent Ladeuil
Cleanup imports.
77
        self.run_bzr('push path/which/doesnt/exist',
78
                     working_dir='branch_a', retcode=3)
79
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
1785.1.2 by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed)
80
        self.assertEquals(
81
                ('', 'bzr: ERROR: No push location known or specified.\n'),
82
                out)
83
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
84
        # test implicit --remember when no push location set, push fails
4420.1.1 by Vincent Ladeuil
Cleanup imports.
85
        out = self.run_bzr('push ../branch_b',
86
                           working_dir='branch_a', retcode=3)
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
87
        self.assertEquals(out,
88
                ('','bzr: ERROR: These branches have diverged.  '
4441.1.1 by Aaron Bentley
Merge nmb's diverged-branch docs.
89
                 'See "bzr help diverged-branches" for more information.\n'))
4420.1.1 by Vincent Ladeuil
Cleanup imports.
90
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
91
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
1785.1.2 by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed)
92
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
93
        # test implicit --remember after resolving previous failure
4420.1.1 by Vincent Ladeuil
Cleanup imports.
94
        uncommit.uncommit(branch=branch_b, tree=tree_b)
1614.2.16 by Olaf Conradi
Modified blackbox test cases to use bzrlib API.
95
        transport.delete('branch_b/c')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
96
        out, err = self.run_bzr('push', working_dir='branch_a')
1785.1.1 by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly.
97
        path = branch_a.get_push_location()
2220.2.38 by Martin Pool
Tag conflicts from push go to stdout.
98
        self.assertEquals(out,
3978.2.5 by Jelmer Vernooij
Fix trailing whitespace.
99
                          'Using saved push location: %s\n'
4420.1.1 by Vincent Ladeuil
Cleanup imports.
100
                          % urlutils.local_path_from_url(path))
2220.2.38 by Martin Pool
Tag conflicts from push go to stdout.
101
        self.assertEqual(err,
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
102
                         'All changes applied successfully.\n'
103
                         'Pushed up to revision 2.\n')
1785.1.1 by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly.
104
        self.assertEqual(path,
105
                         branch_b.bzrdir.root_transport.base)
1614.2.9 by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to
106
        # test explicit --remember
4420.1.1 by Vincent Ladeuil
Cleanup imports.
107
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
1785.1.1 by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly.
108
        self.assertEquals(branch_a.get_push_location(),
109
                          branch_c.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
110
1692.3.1 by Robert Collins
Fix push to work with just a branch, no need for a working tree.
111
    def test_push_without_tree(self):
112
        # bzr push from a branch that does not have a checkout should work.
113
        b = self.make_branch('.')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
114
        out, err = self.run_bzr('push pushed-location')
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
115
        self.assertEqual('', out)
116
        self.assertEqual('Created new branch.\n', err)
4420.1.1 by Vincent Ladeuil
Cleanup imports.
117
        b2 = branch.Branch.open('pushed-location')
1692.3.1 by Robert Collins
Fix push to work with just a branch, no need for a working tree.
118
        self.assertEndsWith(b2.base, 'pushed-location/')
1692.3.6 by Robert Collins
Show the correct number of revisions pushed when pushing a new branch (Robert Collins).
119
120
    def test_push_new_branch_revision_count(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
121
        # bzr push of a branch with revisions to a new location
122
        # should print the number of revisions equal to the length of the
1692.3.6 by Robert Collins
Show the correct number of revisions pushed when pushing a new branch (Robert Collins).
123
        # local branch.
124
        t = self.make_branch_and_tree('tree')
125
        self.build_tree(['tree/file'])
126
        t.add('file')
127
        t.commit('commit 1')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
128
        out, err = self.run_bzr('push -d tree pushed-to')
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
129
        self.assertEqual('', out)
130
        self.assertEqual('Created new branch.\n', err)
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
131
132
    def test_push_only_pushes_history(self):
133
        # Knit branches should only push the history for the current revision.
4420.1.1 by Vincent Ladeuil
Cleanup imports.
134
        format = bzrdir.BzrDirMetaFormat1()
135
        format.repository_format = knitrepo.RepositoryFormatKnit1()
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
136
        shared_repo = self.make_repository('repo', format=format, shared=True)
137
        shared_repo.set_make_working_trees(True)
138
139
        def make_shared_tree(path):
140
            shared_repo.bzrdir.root_transport.mkdir(path)
141
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
4420.1.1 by Vincent Ladeuil
Cleanup imports.
142
            return workingtree.WorkingTree.open('repo/' + path)
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
143
        tree_a = make_shared_tree('a')
144
        self.build_tree(['repo/a/file'])
145
        tree_a.add('file')
146
        tree_a.commit('commit a-1', rev_id='a-1')
147
        f = open('repo/a/file', 'ab')
148
        f.write('more stuff\n')
149
        f.close()
150
        tree_a.commit('commit a-2', rev_id='a-2')
151
152
        tree_b = make_shared_tree('b')
153
        self.build_tree(['repo/b/file'])
154
        tree_b.add('file')
155
        tree_b.commit('commit b-1', rev_id='b-1')
156
157
        self.assertTrue(shared_repo.has_revision('a-1'))
158
        self.assertTrue(shared_repo.has_revision('a-2'))
159
        self.assertTrue(shared_repo.has_revision('b-1'))
160
161
        # Now that we have a repository with shared files, make sure
162
        # that things aren't copied out by a 'push'
4420.1.1 by Vincent Ladeuil
Cleanup imports.
163
        self.run_bzr('push ../../push-b', working_dir='repo/b')
164
        pushed_tree = workingtree.WorkingTree.open('push-b')
1711.2.3 by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???)
165
        pushed_repo = pushed_tree.branch.repository
166
        self.assertFalse(pushed_repo.has_revision('a-1'))
167
        self.assertFalse(pushed_repo.has_revision('a-2'))
168
        self.assertTrue(pushed_repo.has_revision('b-1'))
169
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
170
    def test_push_funky_id(self):
171
        t = self.make_branch_and_tree('tree')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
172
        self.build_tree(['tree/filename'])
1843.2.1 by Aaron Bentley
Add failing tests for funky ids
173
        t.add('filename', 'funky-chars<>%&;"\'')
174
        t.commit('commit filename')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
175
        self.run_bzr('push -d tree new-tree')
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
176
2220.2.9 by Martin Pool
Add specific tests for push -d and pull -d
177
    def test_push_dash_d(self):
178
        t = self.make_branch_and_tree('from')
179
        t.commit(allow_pointless=True,
180
                message='first commit')
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
181
        self.run_bzr('push -d from to-one')
2220.2.9 by Martin Pool
Add specific tests for push -d and pull -d
182
        self.failUnlessExists('to-one')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
183
        self.run_bzr('push -d %s %s'
2220.2.9 by Martin Pool
Add specific tests for push -d and pull -d
184
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
185
        self.failUnlessExists('to-two')
2279.3.1 by mbp at sourcefrog
Add a -d option to push, pull, merge (ported from tags branch)
186
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
187
    def test_push_smart_non_stacked_streaming_acceptance(self):
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
188
        self.setup_smart_server_with_call_log()
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
189
        t = self.make_branch_and_tree('from')
190
        t.commit(allow_pointless=True, message='first commit')
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
191
        self.reset_smart_call_log()
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
192
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
4011.2.4 by Robert Collins
Make the ratchet aspect of the blackbox smart server push acceptance tests clearer.
193
        # This figure represent the amount of work to perform this use case. It
194
        # is entirely ok to reduce this number if a test fails due to rpc_count
195
        # being too low. If rpc_count increases, more network roundtrips have
196
        # become necessary for this use case. Please do not adjust this number
197
        # upwards without agreement from bzr's network support maintainers.
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
198
        self.assertLength(9, self.hpss_calls)
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
199
200
    def test_push_smart_stacked_streaming_acceptance(self):
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
201
        self.setup_smart_server_with_call_log()
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
202
        parent = self.make_branch_and_tree('parent', format='1.9')
203
        parent.commit(message='first commit')
204
        local = parent.bzrdir.sprout('local').open_workingtree()
205
        local.commit(message='local commit')
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
206
        self.reset_smart_call_log()
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
207
        self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
208
            self.get_url('public')], working_dir='local')
4011.2.4 by Robert Collins
Make the ratchet aspect of the blackbox smart server push acceptance tests clearer.
209
        # This figure represent the amount of work to perform this use case. It
210
        # is entirely ok to reduce this number if a test fails due to rpc_count
211
        # being too low. If rpc_count increases, more network roundtrips have
212
        # become necessary for this use case. Please do not adjust this number
213
        # upwards without agreement from bzr's network support maintainers.
4307.2.5 by Robert Collins
Remove too-early checks for revisions adding unnecessary round trips, at the cost of actually reading revision data when pulling (because we currently don't have a hint as about whats local for fetch).
214
        self.assertLength(14, self.hpss_calls)
4420.1.1 by Vincent Ladeuil
Cleanup imports.
215
        remote = branch.Branch.open('public')
4011.2.1 by Robert Collins
Add ratchet style blackbox effort tests for push over bzr+ssh. (Andrew Bennetts, Robert Collins)
216
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
217
4416.3.1 by Jonathan Lange
Add two tests, the second of which demonstrates bug 385132.
218
    def test_push_smart_with_default_stacking_url_path_segment(self):
4416.3.2 by Jonathan Lange
Comment the blackbox tests, for my own sanity.
219
        # If the default stacked-on location is a path element then branches
220
        # we push there over the smart server are stacked and their
221
        # stacked_on_url is that exact path segment. Added to nail bug 385132.
4416.3.1 by Jonathan Lange
Add two tests, the second of which demonstrates bug 385132.
222
        self.setup_smart_server_with_call_log()
223
        self.make_branch('stack-on', format='1.9')
4416.3.7 by Jonathan Lange
Update the test to fail correctly.
224
        self.make_bzrdir('.').get_config().set_default_stack_on(
4416.3.9 by Jonathan Lange
Put the test back the way it was.
225
            '/stack-on')
4416.3.1 by Jonathan Lange
Add two tests, the second of which demonstrates bug 385132.
226
        self.make_branch('from', format='1.9')
227
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
4416.3.10 by Jonathan Lange
Merge trunk
228
        b = branch.Branch.open(self.get_url('to'))
4416.3.12 by Jonathan Lange
This makes the test pass, but it's a bit ick.
229
        self.assertEqual('/extra/stack-on', b.get_stacked_on_url())
4416.3.1 by Jonathan Lange
Add two tests, the second of which demonstrates bug 385132.
230
231
    def test_push_smart_with_default_stacking_relative_path(self):
4416.3.2 by Jonathan Lange
Comment the blackbox tests, for my own sanity.
232
        # If the default stacked-on location is a relative path then branches
233
        # we push there over the smart server are stacked and their
234
        # stacked_on_url is a relative path. Added to nail bug 385132.
4416.3.1 by Jonathan Lange
Add two tests, the second of which demonstrates bug 385132.
235
        self.setup_smart_server_with_call_log()
236
        self.make_branch('stack-on', format='1.9')
237
        self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
238
        self.make_branch('from', format='1.9')
239
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
4416.3.10 by Jonathan Lange
Merge trunk
240
        b = branch.Branch.open(self.get_url('to'))
241
        self.assertEqual('../stack-on', b.get_stacked_on_url())
4416.3.1 by Jonathan Lange
Add two tests, the second of which demonstrates bug 385132.
242
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
243
    def create_simple_tree(self):
244
        tree = self.make_branch_and_tree('tree')
245
        self.build_tree(['tree/a'])
246
        tree.add(['a'], ['a-id'])
247
        tree.commit('one', rev_id='r1')
248
        return tree
249
250
    def test_push_create_prefix(self):
251
        """'bzr push --create-prefix' will create leading directories."""
252
        tree = self.create_simple_tree()
253
254
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
255
                           'push ../new/tree',
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
256
                           working_dir='tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
257
        self.run_bzr('push ../new/tree --create-prefix',
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
258
                     working_dir='tree')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
259
        new_tree = workingtree.WorkingTree.open('new/tree')
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
260
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
261
        self.failUnlessExists('new/tree/a')
262
263
    def test_push_use_existing(self):
2227.3.4 by John Arbash Meinel
Switch back to --use-existing-dir
264
        """'bzr push --use-existing-dir' can push into an existing dir.
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
265
266
        By default, 'bzr push' will not use an existing, non-versioned dir.
267
        """
268
        tree = self.create_simple_tree()
269
        self.build_tree(['target/'])
270
271
        self.run_bzr_error(['Target directory ../target already exists',
2227.3.4 by John Arbash Meinel
Switch back to --use-existing-dir
272
                            'Supply --use-existing-dir',
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
273
                           ],
274
                           'push ../target', working_dir='tree')
2227.3.4 by John Arbash Meinel
Switch back to --use-existing-dir
275
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
276
        self.run_bzr('push --use-existing-dir ../target',
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
277
                     working_dir='tree')
278
4420.1.1 by Vincent Ladeuil
Cleanup imports.
279
        new_tree = workingtree.WorkingTree.open('target')
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
280
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
281
        # The push should have created target/a
282
        self.failUnlessExists('target/a')
283
284
    def test_push_onto_repo(self):
285
        """We should be able to 'bzr push' into an existing bzrdir."""
286
        tree = self.create_simple_tree()
287
        repo = self.make_repository('repo', shared=True)
288
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
289
        self.run_bzr('push ../repo',
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
290
                     working_dir='tree')
291
292
        # Pushing onto an existing bzrdir will create a repository and
293
        # branch as needed, but will only create a working tree if there was
294
        # no BzrDir before.
4420.1.1 by Vincent Ladeuil
Cleanup imports.
295
        self.assertRaises(errors.NoWorkingTree,
296
                          workingtree.WorkingTree.open, 'repo')
297
        new_branch = branch.Branch.open('repo')
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
298
        self.assertEqual(tree.last_revision(), new_branch.last_revision())
299
300
    def test_push_onto_just_bzrdir(self):
301
        """We don't handle when the target is just a bzrdir.
302
303
        Because you shouldn't be able to create *just* a bzrdir in the wild.
304
        """
305
        # TODO: jam 20070109 Maybe it would be better to create the repository
306
        #       if at this point
307
        tree = self.create_simple_tree()
308
        a_bzrdir = self.make_bzrdir('dir')
309
310
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
311
                'push ../dir',
2227.3.1 by John Arbash Meinel
Allow push to create Branch when necessary, and add --use-existing
312
                working_dir='tree')
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
313
3256.1.1 by Daniel Watkins
Added test for push with a revspec.
314
    def test_push_with_revisionspec(self):
3256.1.3 by Daniel Watkins
Clarified test intent.
315
        """We should be able to push a revision older than the tip."""
3256.1.1 by Daniel Watkins
Added test for push with a revspec.
316
        tree_from = self.make_branch_and_tree('from')
317
        tree_from.commit("One.", rev_id="from-1")
318
        tree_from.commit("Two.", rev_id="from-2")
319
320
        self.run_bzr('push -r1 ../to', working_dir='from')
321
4420.1.1 by Vincent Ladeuil
Cleanup imports.
322
        tree_to = workingtree.WorkingTree.open('to')
3256.1.1 by Daniel Watkins
Added test for push with a revspec.
323
        repo_to = tree_to.branch.repository
324
        self.assertTrue(repo_to.has_revision('from-1'))
325
        self.assertFalse(repo_to.has_revision('from-2'))
326
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
327
3256.1.4 by Daniel Watkins
Added test to ensure that passing a range of revisions errors.
328
        self.run_bzr_error(
4325.4.6 by Vincent Ladeuil
Fixed as per John's and Markus reviews.
329
            ['bzr: ERROR: bzr push --revision '
330
             'takes exactly one revision identifier\n'],
3256.1.4 by Daniel Watkins
Added test to ensure that passing a range of revisions errors.
331
            'push -r0..2 ../to', working_dir='from')
332
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
333
    def create_trunk_and_feature_branch(self):
3221.11.12 by Robert Collins
Basic push --reference support, requires url, slow.
334
        # We have a mainline
335
        trunk_tree = self.make_branch_and_tree('target',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
336
            format='1.9')
3221.11.12 by Robert Collins
Basic push --reference support, requires url, slow.
337
        trunk_tree.commit('mainline')
338
        # and a branch from it
339
        branch_tree = self.make_branch_and_tree('branch',
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
340
            format='1.9')
3221.11.12 by Robert Collins
Basic push --reference support, requires url, slow.
341
        branch_tree.pull(trunk_tree.branch)
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
342
        branch_tree.branch.set_parent(trunk_tree.branch.base)
3221.11.12 by Robert Collins
Basic push --reference support, requires url, slow.
343
        # with some work on it
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
344
        branch_tree.commit('moar work plz')
345
        return trunk_tree, branch_tree
346
3221.11.14 by Robert Collins
Refactor to reduce duplication.
347
    def assertPublished(self, branch_revid, stacked_on):
348
        """Assert that the branch 'published' has been published correctly."""
4420.1.1 by Vincent Ladeuil
Cleanup imports.
349
        published_branch = branch.Branch.open('published')
3221.11.14 by Robert Collins
Refactor to reduce duplication.
350
        # The published branch refers to the mainline
3537.3.1 by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url
351
        self.assertEqual(stacked_on, published_branch.get_stacked_on_url())
3221.11.14 by Robert Collins
Refactor to reduce duplication.
352
        # and the branch's work was pushed
353
        self.assertTrue(published_branch.repository.has_revision(branch_revid))
354
3549.1.1 by Martin Pool
rename push --reference to --stacked-on
355
    def test_push_new_branch_stacked_on(self):
356
        """Pushing a new branch with --stacked-on creates a stacked branch."""
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
357
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
358
        # we publish branch_tree with a reference to the mainline.
3549.1.1 by Martin Pool
rename push --reference to --stacked-on
359
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
3221.11.12 by Robert Collins
Basic push --reference support, requires url, slow.
360
            self.get_url('published')], working_dir='branch')
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
361
        self.assertEqual('', out)
3221.19.4 by Ian Clatworthy
shallow -> stacked
362
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
363
            trunk_tree.branch.base, err)
3221.11.14 by Robert Collins
Refactor to reduce duplication.
364
        self.assertPublished(branch_tree.last_revision(),
365
            trunk_tree.branch.base)
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
366
3221.19.4 by Ian Clatworthy
shallow -> stacked
367
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
3221.11.17 by Robert Collins
no public location causes the parent to be used directly with push --shallow.
368
        """When the parent has no public url the parent is used as-is."""
369
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
3221.19.4 by Ian Clatworthy
shallow -> stacked
370
        # now we do a stacked push, which should determine the public location
3221.11.17 by Robert Collins
no public location causes the parent to be used directly with push --shallow.
371
        # for us.
3221.19.4 by Ian Clatworthy
shallow -> stacked
372
        out, err = self.run_bzr(['push', '--stacked',
3221.11.17 by Robert Collins
no public location causes the parent to be used directly with push --shallow.
373
            self.get_url('published')], working_dir='branch')
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
374
        self.assertEqual('', out)
3221.19.4 by Ian Clatworthy
shallow -> stacked
375
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
376
            trunk_tree.branch.base, err)
4420.1.1 by Vincent Ladeuil
Cleanup imports.
377
        self.assertPublished(branch_tree.last_revision(),
378
                             trunk_tree.branch.base)
3221.11.17 by Robert Collins
no public location causes the parent to be used directly with push --shallow.
379
3221.19.4 by Ian Clatworthy
shallow -> stacked
380
    def test_push_new_branch_stacked_uses_parent_public(self):
381
        """Pushing a new branch with --stacked creates a stacked branch."""
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
382
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
383
        # the trunk is published on a web server
4420.1.1 by Vincent Ladeuil
Cleanup imports.
384
        self.transport_readonly_server = http_server.HttpServer
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
385
        trunk_public = self.make_branch('public_trunk', format='1.9')
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
386
        trunk_public.pull(trunk_tree.branch)
387
        trunk_public_url = self.get_readonly_url('public_trunk')
388
        trunk_tree.branch.set_public_branch(trunk_public_url)
3221.19.4 by Ian Clatworthy
shallow -> stacked
389
        # now we do a stacked push, which should determine the public location
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
390
        # for us.
3221.19.4 by Ian Clatworthy
shallow -> stacked
391
        out, err = self.run_bzr(['push', '--stacked',
3221.11.13 by Robert Collins
Allow push --shallow to just work, and fix the testing HTTPServer to not be affected by chdir() calls.
392
            self.get_url('published')], working_dir='branch')
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
393
        self.assertEqual('', out)
3221.19.4 by Ian Clatworthy
shallow -> stacked
394
        self.assertEqual('Created new stacked branch referring to %s.\n' %
3978.2.2 by Jelmer Vernooij
Write status messages during push to stderr rather than stdout.
395
            trunk_public_url, err)
3221.11.14 by Robert Collins
Refactor to reduce duplication.
396
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
3221.11.12 by Robert Collins
Basic push --reference support, requires url, slow.
397
3221.19.4 by Ian Clatworthy
shallow -> stacked
398
    def test_push_new_branch_stacked_no_parent(self):
399
        """Pushing with --stacked and no parent branch errors."""
4241.6.8 by Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil
Add --development6-rich-root, disabling the legacy and unneeded development2 format, and activating the tests for CHK features disabled pending this format. (Robert Collins, John Arbash Meinel, Ian Clatworthy, Vincent Ladeuil)
400
        branch = self.make_branch_and_tree('branch', format='1.9')
3221.19.4 by Ian Clatworthy
shallow -> stacked
401
        # now we do a stacked push, which should fail as the place to refer too
3221.11.15 by Robert Collins
no parent branch causes an error on push --shallow.
402
        # cannot be determined.
403
        out, err = self.run_bzr_error(
3221.19.4 by Ian Clatworthy
shallow -> stacked
404
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
3221.11.15 by Robert Collins
no parent branch causes an error on push --shallow.
405
            self.get_url('published')], working_dir='branch')
406
        self.assertEqual('', out)
407
        self.assertFalse(self.get_transport('published').has('.'))
408
3606.8.3 by John Arbash Meinel
push doesn't notify because it doesn't notice by default.
409
    def test_push_notifies_default_stacking(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
410
        self.make_branch('stack_on', format='1.6')
3242.3.34 by Aaron Bentley
Add notification of default stacking
411
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
412
        self.make_branch('from', format='1.6')
3242.3.34 by Aaron Bentley
Add notification of default stacking
413
        out, err = self.run_bzr('push -d from to')
3641.1.1 by John Arbash Meinel
Merge in 1.6rc5 and revert disabling default stack on policy
414
        self.assertContainsRe(err,
415
                              'Using default stacking branch stack_on at .*')
3242.3.34 by Aaron Bentley
Add notification of default stacking
416
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
417
    def test_push_stacks_with_default_stacking_if_target_is_stackable(self):
418
        self.make_branch('stack_on', format='1.6')
419
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
420
        self.make_branch('from', format='pack-0.92')
421
        out, err = self.run_bzr('push -d from to')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
422
        b = branch.Branch.open('to')
423
        self.assertEqual('../stack_on', b.get_stacked_on_url())
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
424
425
    def test_push_does_not_change_format_with_default_if_target_cannot(self):
426
        self.make_branch('stack_on', format='pack-0.92')
427
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
428
        self.make_branch('from', format='pack-0.92')
429
        out, err = self.run_bzr('push -d from to')
4420.1.1 by Vincent Ladeuil
Cleanup imports.
430
        b = branch.Branch.open('to')
431
        self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
4165.2.1 by Robert Collins
Fix bzr failing to stack when a server requests it and the branch it is pushing from cannot stack but the branch it should stack on can.
432
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
433
    def test_push_doesnt_create_broken_branch(self):
3904.3.7 by Andrew Bennetts
Comment the new tests.
434
        """Pushing a new standalone branch works even when there's a default
435
        stacking policy at the destination.
436
437
        The new branch will preserve the repo format (even if it isn't the
438
        default for the branch), and will be stacked when the repo format
439
        allows (which means that the branch format isn't necessarly preserved).
440
        """
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
441
        self.make_repository('repo', shared=True, format='1.6')
442
        builder = self.make_branch_builder('repo/local', format='pack-0.92')
443
        builder.start_series()
444
        builder.build_snapshot('rev-1', None, [
445
            ('add', ('', 'root-id', 'directory', '')),
3904.3.3 by Andrew Bennetts
Simplify test slightly.
446
            ('add', ('filename', 'f-id', 'file', 'content\n'))])
447
        builder.build_snapshot('rev-2', ['rev-1'], [])
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
448
        builder.build_snapshot('rev-3', ['rev-2'],
3904.3.3 by Andrew Bennetts
Simplify test slightly.
449
            [('modify', ('f-id', 'new-content\n'))])
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
450
        builder.finish_series()
451
        branch = builder.get_branch()
3904.3.7 by Andrew Bennetts
Comment the new tests.
452
        # Push rev-1 to "trunk", so that we can stack on it.
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
453
        self.run_bzr('push -d repo/local trunk -r 1')
3904.3.7 by Andrew Bennetts
Comment the new tests.
454
        # Set a default stacking policy so that new branches will automatically
455
        # stack on trunk.
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
456
        self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
3904.3.7 by Andrew Bennetts
Comment the new tests.
457
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
458
        out, err = self.run_bzr('push -d repo/local remote -r 2')
459
        self.assertContainsRe(
460
            err, 'Using default stacking branch trunk at .*')
3904.3.7 by Andrew Bennetts
Comment the new tests.
461
        # Push rev-3 onto "remote".  If "remote" not stacked and is missing the
462
        # fulltext record for f-id @ rev-1, then this will fail.
3904.3.2 by Andrew Bennetts
Blackbox test that triggers the bug. Should get replaced with a unit test.
463
        out, err = self.run_bzr('push -d repo/local remote -r 3')
464
3848.1.19 by Aaron Bentley
Show log for non-initial push -v
465
    def test_push_verbose_shows_log(self):
466
        tree = self.make_branch_and_tree('source')
467
        tree.commit('rev1')
468
        out, err = self.run_bzr('push -v -d source target')
469
        # initial push contains log
470
        self.assertContainsRe(out, 'rev1')
471
        tree.commit('rev2')
472
        out, err = self.run_bzr('push -v -d source target')
473
        # subsequent push contains log
474
        self.assertContainsRe(out, 'rev2')
475
        # subsequent log is accurate
476
        self.assertNotContainsRe(out, 'rev1')
477
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
478
4420.1.1 by Vincent Ladeuil
Cleanup imports.
479
class RedirectingMemoryTransport(memory.MemoryTransport):
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
480
3878.4.4 by Vincent Ladeuil
Cleanup.
481
    def mkdir(self, relpath, mode=None):
482
        from bzrlib.trace import mutter
483
        if self._cwd == '/source/':
484
            raise errors.RedirectRequested(self.abspath(relpath),
485
                                           self.abspath('../target'),
486
                                           is_permanent=True)
487
        elif self._cwd == '/infinite-loop/':
488
            raise errors.RedirectRequested(self.abspath(relpath),
489
                                           self.abspath('../infinite-loop'),
490
                                           is_permanent=True)
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
491
        else:
492
            return super(RedirectingMemoryTransport, self).mkdir(
3878.4.4 by Vincent Ladeuil
Cleanup.
493
                relpath, mode)
494
3878.4.5 by Vincent Ladeuil
Don't use the exception as a parameter for _redirected_to.
495
    def _redirected_to(self, source, target):
3878.4.4 by Vincent Ladeuil
Cleanup.
496
        # We do accept redirections
3878.4.5 by Vincent Ladeuil
Don't use the exception as a parameter for _redirected_to.
497
        return transport.get_transport(target)
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
498
499
4420.1.1 by Vincent Ladeuil
Cleanup imports.
500
class RedirectingMemoryServer(memory.MemoryServer):
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
501
502
    def setUp(self):
503
        self._dirs = {'/': None}
504
        self._files = {}
505
        self._locks = {}
506
        self._scheme = 'redirecting-memory+%s:///' % id(self)
3878.4.4 by Vincent Ladeuil
Cleanup.
507
        transport.register_transport(self._scheme, self._memory_factory)
3066.3.3 by jml at canonical
Unregister the test transport in order to be clean and to make test_selftest pass.
508
509
    def _memory_factory(self, url):
510
        result = RedirectingMemoryTransport(url)
511
        result._dirs = self._dirs
512
        result._files = self._files
513
        result._locks = self._locks
514
        return result
515
516
    def tearDown(self):
3878.4.4 by Vincent Ladeuil
Cleanup.
517
        transport.unregister_transport(self._scheme, self._memory_factory)
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
518
519
4420.1.1 by Vincent Ladeuil
Cleanup imports.
520
class TestPushRedirect(tests.TestCaseWithTransport):
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
521
522
    def setUp(self):
4420.1.1 by Vincent Ladeuil
Cleanup imports.
523
        tests.TestCaseWithTransport.setUp(self)
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
524
        self.memory_server = RedirectingMemoryServer()
525
        self.memory_server.setUp()
526
        self.addCleanup(self.memory_server.tearDown)
527
3066.3.2 by jml at canonical
Add tests to check the handling of TooManyRedirections.
528
        # Make the branch and tree that we'll be pushing.
529
        t = self.make_branch_and_tree('tree')
530
        self.build_tree(['tree/file'])
531
        t.add('file')
532
        t.commit('commit 1')
533
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
534
    def test_push_redirects_on_mkdir(self):
535
        """If the push requires a mkdir, push respects redirect requests.
536
537
        This is added primarily to handle lp:/ URI support, so that users can
538
        push to new branches by specifying lp:/ URIs.
539
        """
540
        destination_url = self.memory_server.get_url() + 'source'
3878.4.4 by Vincent Ladeuil
Cleanup.
541
        self.run_bzr(['push', '-d', 'tree', destination_url])
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
542
4420.1.1 by Vincent Ladeuil
Cleanup imports.
543
        local_revision = branch.Branch.open('tree').last_revision()
544
        remote_revision = branch.Branch.open(
3066.3.1 by jml at canonical
Catch redirects raised by mkdir() in the push command. This is primarily
545
            self.memory_server.get_url() + 'target').last_revision()
546
        self.assertEqual(remote_revision, local_revision)
3066.3.2 by jml at canonical
Add tests to check the handling of TooManyRedirections.
547
548
    def test_push_gracefully_handles_too_many_redirects(self):
549
        """Push fails gracefully if the mkdir generates a large number of
550
        redirects.
551
        """
552
        destination_url = self.memory_server.get_url() + 'infinite-loop'
553
        out, err = self.run_bzr_error(
554
            ['Too many redirections trying to make %s\\.\n'
555
             % re.escape(destination_url)],
3878.4.4 by Vincent Ladeuil
Cleanup.
556
            ['push', '-d', 'tree', destination_url], retcode=3)
3066.3.2 by jml at canonical
Add tests to check the handling of TooManyRedirections.
557
        self.assertEqual('', out)
4420.1.2 by Vincent Ladeuil
Fix bug #284038 by adding a --strict option to push.
558
559
560
class TestPushStrict(tests.TestCaseWithTransport):
561
562
    def make_local_branch_and_tree(self):
563
        tree = self.make_branch_and_tree('local')
564
        self.build_tree_contents([('local/file', 'initial')])
565
        tree.add('file')
566
        tree.commit('adding file', rev_id='from-1')
567
        return tree
568
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
569
    def make_local_branch_and_tree_with_changes(self):
570
        tree = self.make_local_branch_and_tree()
571
        # Make some changes
572
        self.build_tree_contents([('local/file', 'modified')])
573
        return tree
574
575
    def set_config_push_strict(self, tree, value):
576
        # set config var (any of bazaar.conf, locations.conf, branch.conf
577
        # should do)
578
        conf = tree.branch.get_config()
579
        conf.set_user_option('push_strict', value)
580
581
    def assertPushFails(self, location, *args):
582
        self.run_bzr_error(['Working tree ".*/local/"'
583
                            ' has uncommitted changes.$',],
584
                           ['push', '../' + location] + list(args),
585
                           working_dir='local', retcode=3)
586
587
    def assertPushSucceeds(self, location, *args):
588
        self.run_bzr(['push', '../' + location] + list(args),
589
                     working_dir='local')
590
        tree_to = workingtree.WorkingTree.open(location)
4420.1.2 by Vincent Ladeuil
Fix bug #284038 by adding a --strict option to push.
591
        repo_to = tree_to.branch.repository
592
        self.assertTrue(repo_to.has_revision('from-1'))
593
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
594
595
    def test_push_default(self):
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
596
        tree = self.make_local_branch_and_tree_with_changes()
597
        self.assertPushSucceeds('to')
598
599
    def test_push_no_strict_with_changes(self):
600
        tree = self.make_local_branch_and_tree_with_changes()
601
        self.assertPushSucceeds('to', '--no-strict')
4420.1.2 by Vincent Ladeuil
Fix bug #284038 by adding a --strict option to push.
602
603
    def test_push_strict_with_changes(self):
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
604
        tree = self.make_local_branch_and_tree_with_changes()
605
        self.assertPushFails('to', '--strict')
4420.1.2 by Vincent Ladeuil
Fix bug #284038 by adding a --strict option to push.
606
607
    def test_push_strict_without_changes(self):
608
        tree = self.make_local_branch_and_tree()
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
609
        self.assertPushSucceeds('to', '--strict')
610
611
    def test_push_respect_config_var_strict(self):
612
        tree = self.make_local_branch_and_tree_with_changes()
613
        self.set_config_push_strict(tree, 'true')
614
        self.assertPushFails('to')
615
4420.1.6 by Vincent Ladeuil
Fixed as per John's review feedback.
616
    def test_push_bogus_config_var_ignored(self):
617
        tree = self.make_local_branch_and_tree_with_changes()
618
        self.set_config_push_strict(tree, "I don't want you to be strict")
619
        self.assertPushSucceeds('to')
620
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
621
    def test_push_no_strict_command_line_override_config(self):
622
        tree = self.make_local_branch_and_tree_with_changes()
4420.1.6 by Vincent Ladeuil
Fixed as per John's review feedback.
623
        self.set_config_push_strict(tree, 'yES')
624
        self.assertPushFails('to')
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
625
        self.assertPushSucceeds('to', '--no-strict')
626
627
    def test_push_strict_command_line_override_config(self):
628
        tree = self.make_local_branch_and_tree_with_changes()
4420.1.6 by Vincent Ladeuil
Fixed as per John's review feedback.
629
        self.set_config_push_strict(tree, 'oFF')
4420.1.5 by Vincent Ladeuil
Start implementing jam's review feedback.
630
        self.assertPushFails('to', '--strict')
4420.1.6 by Vincent Ladeuil
Fixed as per John's review feedback.
631
        self.assertPushSucceeds('to')