/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_push.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for bzr push."""
 
18
"""Black-box tests for brz push."""
19
19
 
20
20
import re
21
21
 
22
 
from bzrlib import (
 
22
from breezy import (
23
23
    branch,
24
 
    bzrdir,
25
24
    controldir,
 
25
    directory_service,
26
26
    errors,
27
27
    osutils,
28
28
    tests,
31
31
    urlutils,
32
32
    workingtree
33
33
    )
34
 
from bzrlib.repofmt import knitrepo
35
 
from bzrlib.tests import (
 
34
from breezy.bzr import (
 
35
    bzrdir,
 
36
    )
 
37
from breezy.bzr import knitrepo
 
38
from breezy.tests import (
36
39
    http_server,
37
40
    scenarios,
38
41
    script,
39
42
    test_foreign,
40
43
    )
41
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
42
 
from bzrlib.transport import memory
 
44
from breezy.transport import memory
43
45
 
44
46
 
45
47
load_tests = scenarios.load_tests_apply_scenarios
65
67
 
66
68
        # If there is no parent location set, :parent isn't mentioned.
67
69
        out = self.run_bzr('push', working_dir='a', retcode=3)
68
 
        self.assertEquals(out,
69
 
                ('','bzr: ERROR: No push location known or specified.\n'))
 
70
        self.assertEqual(out,
 
71
                         ('', 'brz: ERROR: No push location known or specified.\n'))
70
72
 
71
73
        # If there is a parent location set, the error suggests :parent.
72
74
        tree_a.branch.set_parent(tree_b.branch.base)
73
75
        out = self.run_bzr('push', working_dir='a', retcode=3)
74
 
        self.assertEquals(out,
75
 
            ('','bzr: ERROR: No push location known or specified. '
76
 
                'To push to the parent branch '
77
 
                '(at %s), use \'bzr push :parent\'.\n' %
78
 
                urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
 
76
        self.assertEqual(out,
 
77
                         ('', 'brz: ERROR: No push location known or specified. '
 
78
                          'To push to the parent branch '
 
79
                          '(at %s), use \'brz push :parent\'.\n' %
 
80
                          urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
79
81
 
80
82
    def test_push_remember(self):
81
83
        """Push changes from one branch to another and test push location."""
85
87
        self.build_tree(['branch_a/a'])
86
88
        tree_a.add('a')
87
89
        tree_a.commit('commit a')
88
 
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
 
90
        tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
89
91
        branch_b = tree_b.branch
90
 
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
 
92
        tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
91
93
        branch_c = tree_c.branch
92
94
        self.build_tree(['branch_a/b'])
93
95
        tree_a.add('b')
100
102
 
101
103
        # test push for failure without push location set
102
104
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
103
 
        self.assertEquals(out,
104
 
                ('','bzr: ERROR: No push location known or specified.\n'))
 
105
        self.assertEqual(out,
 
106
                         ('', 'brz: ERROR: No push location known or specified.\n'))
105
107
 
106
108
        # test not remembered if cannot actually push
107
109
        self.run_bzr('push path/which/doesnt/exist',
108
110
                     working_dir='branch_a', retcode=3)
109
111
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
110
 
        self.assertEquals(
111
 
                ('', 'bzr: ERROR: No push location known or specified.\n'),
112
 
                out)
 
112
        self.assertEqual(
 
113
            ('', 'brz: ERROR: No push location known or specified.\n'),
 
114
            out)
113
115
 
114
116
        # test implicit --remember when no push location set, push fails
115
117
        out = self.run_bzr('push ../branch_b',
116
118
                           working_dir='branch_a', retcode=3)
117
 
        self.assertEquals(out,
118
 
                ('','bzr: ERROR: These branches have diverged.  '
119
 
                 'See "bzr help diverged-branches" for more information.\n'))
 
119
        self.assertEqual(out,
 
120
                         ('', 'brz: ERROR: These branches have diverged.  '
 
121
                          'See "brz help diverged-branches" for more information.\n'))
120
122
        # Refresh the branch as 'push' modified it
121
 
        branch_a = branch_a.bzrdir.open_branch()
122
 
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
123
 
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
 
123
        branch_a = branch_a.controldir.open_branch()
 
124
        self.assertEqual(osutils.abspath(branch_a.get_push_location()),
 
125
                         osutils.abspath(branch_b.controldir.root_transport.base))
124
126
 
125
127
        # test implicit --remember after resolving previous failure
126
128
        uncommit.uncommit(branch=branch_b, tree=tree_b)
127
129
        transport.delete('branch_b/c')
128
130
        out, err = self.run_bzr('push', working_dir='branch_a')
129
131
        # Refresh the branch as 'push' modified it
130
 
        branch_a = branch_a.bzrdir.open_branch()
 
132
        branch_a = branch_a.controldir.open_branch()
131
133
        path = branch_a.get_push_location()
132
134
        self.assertEqual(err,
133
135
                         'Using saved push location: %s\n'
135
137
                         'Pushed up to revision 2.\n'
136
138
                         % urlutils.local_path_from_url(path))
137
139
        self.assertEqual(path,
138
 
                         branch_b.bzrdir.root_transport.base)
 
140
                         branch_b.controldir.root_transport.base)
139
141
        # test explicit --remember
140
142
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
141
143
        # Refresh the branch as 'push' modified it
142
 
        branch_a = branch_a.bzrdir.open_branch()
143
 
        self.assertEquals(branch_a.get_push_location(),
144
 
                          branch_c.bzrdir.root_transport.base)
 
144
        branch_a = branch_a.controldir.open_branch()
 
145
        self.assertEqual(branch_a.get_push_location(),
 
146
                         branch_c.controldir.root_transport.base)
145
147
 
146
148
    def test_push_without_tree(self):
147
 
        # bzr push from a branch that does not have a checkout should work.
 
149
        # brz push from a branch that does not have a checkout should work.
148
150
        b = self.make_branch('.')
149
151
        out, err = self.run_bzr('push pushed-location')
150
152
        self.assertEqual('', out)
153
155
        self.assertEndsWith(b2.base, 'pushed-location/')
154
156
 
155
157
    def test_push_no_tree(self):
156
 
        # bzr push --no-tree of a branch with working trees
 
158
        # brz push --no-tree of a branch with working trees
157
159
        b = self.make_branch_and_tree('push-from')
158
160
        self.build_tree(['push-from/file'])
159
161
        b.add('file')
164
166
        self.assertPathDoesNotExist('push-to/file')
165
167
 
166
168
    def test_push_new_branch_revision_count(self):
167
 
        # bzr push of a branch with revisions to a new location
 
169
        # brz push of a branch with revisions to a new location
168
170
        # should print the number of revisions equal to the length of the
169
171
        # local branch.
170
172
        t = self.make_branch_and_tree('tree')
183
185
        t.commit('commit 1')
184
186
        self.run_bzr('push -d tree pushed-to')
185
187
        # Refresh the branch as 'push' modified it and get the push location
186
 
        push_loc = t.branch.bzrdir.open_branch().get_push_location()
 
188
        push_loc = t.branch.controldir.open_branch().get_push_location()
187
189
        out, err = self.run_bzr('push', working_dir="tree")
188
190
        self.assertEqual('Using saved push location: %s\n'
189
191
                         'No new revisions or tags to push.\n' %
200
202
        shared_repo.set_make_working_trees(True)
201
203
 
202
204
        def make_shared_tree(path):
203
 
            shared_repo.bzrdir.root_transport.mkdir(path)
 
205
            shared_repo.controldir.root_transport.mkdir(path)
204
206
            controldir.ControlDir.create_branch_convenience('repo/' + path)
205
207
            return workingtree.WorkingTree.open('repo/' + path)
206
208
        tree_a = make_shared_tree('a')
207
209
        self.build_tree(['repo/a/file'])
208
210
        tree_a.add('file')
209
 
        tree_a.commit('commit a-1', rev_id='a-1')
 
211
        tree_a.commit('commit a-1', rev_id=b'a-1')
210
212
        f = open('repo/a/file', 'ab')
211
 
        f.write('more stuff\n')
 
213
        f.write(b'more stuff\n')
212
214
        f.close()
213
 
        tree_a.commit('commit a-2', rev_id='a-2')
 
215
        tree_a.commit('commit a-2', rev_id=b'a-2')
214
216
 
215
217
        tree_b = make_shared_tree('b')
216
218
        self.build_tree(['repo/b/file'])
217
219
        tree_b.add('file')
218
 
        tree_b.commit('commit b-1', rev_id='b-1')
 
220
        tree_b.commit('commit b-1', rev_id=b'b-1')
219
221
 
220
 
        self.assertTrue(shared_repo.has_revision('a-1'))
221
 
        self.assertTrue(shared_repo.has_revision('a-2'))
222
 
        self.assertTrue(shared_repo.has_revision('b-1'))
 
222
        self.assertTrue(shared_repo.has_revision(b'a-1'))
 
223
        self.assertTrue(shared_repo.has_revision(b'a-2'))
 
224
        self.assertTrue(shared_repo.has_revision(b'b-1'))
223
225
 
224
226
        # Now that we have a repository with shared files, make sure
225
227
        # that things aren't copied out by a 'push'
226
228
        self.run_bzr('push ../../push-b', working_dir='repo/b')
227
229
        pushed_tree = workingtree.WorkingTree.open('push-b')
228
230
        pushed_repo = pushed_tree.branch.repository
229
 
        self.assertFalse(pushed_repo.has_revision('a-1'))
230
 
        self.assertFalse(pushed_repo.has_revision('a-2'))
231
 
        self.assertTrue(pushed_repo.has_revision('b-1'))
 
231
        self.assertFalse(pushed_repo.has_revision(b'a-1'))
 
232
        self.assertFalse(pushed_repo.has_revision(b'a-2'))
 
233
        self.assertTrue(pushed_repo.has_revision(b'b-1'))
232
234
 
233
235
    def test_push_funky_id(self):
234
236
        t = self.make_branch_and_tree('tree')
235
237
        self.build_tree(['tree/filename'])
236
 
        t.add('filename', 'funky-chars<>%&;"\'')
 
238
        t.add('filename', b'funky-chars<>%&;"\'')
237
239
        t.commit('commit filename')
238
240
        self.run_bzr('push -d tree new-tree')
239
241
 
240
242
    def test_push_dash_d(self):
241
243
        t = self.make_branch_and_tree('from')
242
244
        t.commit(allow_pointless=True,
243
 
                message='first commit')
 
245
                 message='first commit')
244
246
        self.run_bzr('push -d from to-one')
245
247
        self.assertPathExists('to-one')
246
248
        self.run_bzr('push -d %s %s'
247
 
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
 
249
                     % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
248
250
        self.assertPathExists('to-two')
249
251
 
250
252
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
252
254
        target_repo = self.make_repository('target')
253
255
        source = self.make_branch_builder('source')
254
256
        source.start_series()
255
 
        source.build_snapshot('A', None, [
256
 
            ('add', ('', 'root-id', 'directory', None))])
257
 
        source.build_snapshot('B', ['A'], [])
258
 
        source.build_snapshot('C', ['A'], [])
 
257
        source.build_snapshot(None, [
 
258
            ('add', ('', b'root-id', 'directory', None))],
 
259
            revision_id=b'A')
 
260
        source.build_snapshot([b'A'], [], revision_id=b'B')
 
261
        source.build_snapshot([b'A'], [], revision_id=b'C')
259
262
        source.finish_series()
260
263
        self.run_bzr('push target -d source')
261
264
        self.addCleanup(target_repo.lock_read().unlock)
262
265
        # We should have pushed 'C', but not 'B', since it isn't in the
263
266
        # ancestry
264
 
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
265
 
 
266
 
    def test_push_smart_non_stacked_streaming_acceptance(self):
267
 
        self.setup_smart_server_with_call_log()
268
 
        t = self.make_branch_and_tree('from')
269
 
        t.commit(allow_pointless=True, message='first commit')
270
 
        self.reset_smart_call_log()
271
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
272
 
        # This figure represent the amount of work to perform this use case. It
273
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
274
 
        # being too low. If rpc_count increases, more network roundtrips have
275
 
        # become necessary for this use case. Please do not adjust this number
276
 
        # upwards without agreement from bzr's network support maintainers.
277
 
        self.assertLength(9, self.hpss_calls)
278
 
        self.assertLength(1, self.hpss_connections)
279
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
280
 
 
281
 
    def test_push_smart_stacked_streaming_acceptance(self):
282
 
        self.setup_smart_server_with_call_log()
283
 
        parent = self.make_branch_and_tree('parent', format='1.9')
284
 
        parent.commit(message='first commit')
285
 
        local = parent.bzrdir.sprout('local').open_workingtree()
286
 
        local.commit(message='local commit')
287
 
        self.reset_smart_call_log()
288
 
        self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
289
 
            self.get_url('public')], working_dir='local')
290
 
        # This figure represent the amount of work to perform this use case. It
291
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
292
 
        # being too low. If rpc_count increases, more network roundtrips have
293
 
        # become necessary for this use case. Please do not adjust this number
294
 
        # upwards without agreement from bzr's network support maintainers.
295
 
        self.assertLength(15, self.hpss_calls)
296
 
        self.assertLength(1, self.hpss_connections)
297
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
298
 
        remote = branch.Branch.open('public')
299
 
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
300
 
 
301
 
    def test_push_smart_tags_streaming_acceptance(self):
302
 
        self.setup_smart_server_with_call_log()
303
 
        t = self.make_branch_and_tree('from')
304
 
        rev_id = t.commit(allow_pointless=True, message='first commit')
305
 
        t.branch.tags.set_tag('new-tag', rev_id)
306
 
        self.reset_smart_call_log()
307
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
308
 
        # This figure represent the amount of work to perform this use case. It
309
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
310
 
        # being too low. If rpc_count increases, more network roundtrips have
311
 
        # become necessary for this use case. Please do not adjust this number
312
 
        # upwards without agreement from bzr's network support maintainers.
313
 
        self.assertLength(11, self.hpss_calls)
314
 
        self.assertLength(1, self.hpss_connections)
315
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
316
 
 
317
 
    def test_push_smart_incremental_acceptance(self):
318
 
        self.setup_smart_server_with_call_log()
319
 
        t = self.make_branch_and_tree('from')
320
 
        rev_id1 = t.commit(allow_pointless=True, message='first commit')
321
 
        rev_id2 = t.commit(allow_pointless=True, message='second commit')
322
 
        self.run_bzr(
323
 
            ['push', self.get_url('to-one'), '-r1'], working_dir='from')
324
 
        self.reset_smart_call_log()
325
 
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
326
 
        # This figure represent the amount of work to perform this use case. It
327
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
328
 
        # being too low. If rpc_count increases, more network roundtrips have
329
 
        # become necessary for this use case. Please do not adjust this number
330
 
        # upwards without agreement from bzr's network support maintainers.
331
 
        self.assertLength(11, self.hpss_calls)
332
 
        self.assertLength(1, self.hpss_connections)
333
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
267
        self.assertEqual([(b'A',), (b'C',)], sorted(
 
268
            target_repo.revisions.keys()))
334
269
 
335
270
    def test_push_smart_with_default_stacking_url_path_segment(self):
336
271
        # If the default stacked-on location is a path element then branches
338
273
        # stacked_on_url is that exact path segment. Added to nail bug 385132.
339
274
        self.setup_smart_server_with_call_log()
340
275
        self.make_branch('stack-on', format='1.9')
341
 
        self.make_bzrdir('.').get_config().set_default_stack_on(
 
276
        self.make_controldir('.').get_config().set_default_stack_on(
342
277
            '/stack-on')
343
278
        self.make_branch('from', format='1.9')
344
279
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
351
286
        # stacked_on_url is a relative path. Added to nail bug 385132.
352
287
        self.setup_smart_server_with_call_log()
353
288
        self.make_branch('stack-on', format='1.9')
354
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
 
289
        self.make_controldir('.').get_config().set_default_stack_on('stack-on')
355
290
        self.make_branch('from', format='1.9')
356
291
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
357
292
        b = branch.Branch.open(self.get_url('to'))
360
295
    def create_simple_tree(self):
361
296
        tree = self.make_branch_and_tree('tree')
362
297
        self.build_tree(['tree/a'])
363
 
        tree.add(['a'], ['a-id'])
364
 
        tree.commit('one', rev_id='r1')
 
298
        tree.add(['a'], [b'a-id'])
 
299
        tree.commit('one', rev_id=b'r1')
365
300
        return tree
366
301
 
367
302
    def test_push_create_prefix(self):
368
 
        """'bzr push --create-prefix' will create leading directories."""
 
303
        """'brz push --create-prefix' will create leading directories."""
369
304
        tree = self.create_simple_tree()
370
305
 
371
306
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
378
313
        self.assertPathExists('new/tree/a')
379
314
 
380
315
    def test_push_use_existing(self):
381
 
        """'bzr push --use-existing-dir' can push into an existing dir.
 
316
        """'brz push --use-existing-dir' can push into an existing dir.
382
317
 
383
 
        By default, 'bzr push' will not use an existing, non-versioned dir.
 
318
        By default, 'brz push' will not use an existing, non-versioned dir.
384
319
        """
385
320
        tree = self.create_simple_tree()
386
321
        self.build_tree(['target/'])
387
322
 
388
323
        self.run_bzr_error(['Target directory ../target already exists',
389
324
                            'Supply --use-existing-dir',
390
 
                           ],
 
325
                            ],
391
326
                           'push ../target', working_dir='tree')
392
327
 
393
328
        self.run_bzr('push --use-existing-dir ../target',
399
334
        self.assertPathExists('target/a')
400
335
 
401
336
    def test_push_use_existing_into_empty_bzrdir(self):
402
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
 
337
        """'brz push --use-existing-dir' into a dir with an empty .bzr dir
403
338
        fails.
404
339
        """
405
340
        tree = self.create_simple_tree()
410
345
            'push ../target --use-existing-dir', working_dir='tree')
411
346
 
412
347
    def test_push_onto_repo(self):
413
 
        """We should be able to 'bzr push' into an existing bzrdir."""
 
348
        """We should be able to 'brz push' into an existing bzrdir."""
414
349
        tree = self.create_simple_tree()
415
350
        repo = self.make_repository('repo', shared=True)
416
351
 
433
368
        # TODO: jam 20070109 Maybe it would be better to create the repository
434
369
        #       if at this point
435
370
        tree = self.create_simple_tree()
436
 
        a_bzrdir = self.make_bzrdir('dir')
 
371
        a_controldir = self.make_controldir('dir')
437
372
 
438
373
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
439
 
                'push ../dir',
440
 
                working_dir='tree')
 
374
                           'push ../dir',
 
375
                           working_dir='tree')
441
376
 
442
377
    def test_push_with_revisionspec(self):
443
378
        """We should be able to push a revision older than the tip."""
444
379
        tree_from = self.make_branch_and_tree('from')
445
 
        tree_from.commit("One.", rev_id="from-1")
446
 
        tree_from.commit("Two.", rev_id="from-2")
 
380
        tree_from.commit("One.", rev_id=b"from-1")
 
381
        tree_from.commit("Two.", rev_id=b"from-2")
447
382
 
448
383
        self.run_bzr('push -r1 ../to', working_dir='from')
449
384
 
450
385
        tree_to = workingtree.WorkingTree.open('to')
451
386
        repo_to = tree_to.branch.repository
452
 
        self.assertTrue(repo_to.has_revision('from-1'))
453
 
        self.assertFalse(repo_to.has_revision('from-2'))
454
 
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
387
        self.assertTrue(repo_to.has_revision(b'from-1'))
 
388
        self.assertFalse(repo_to.has_revision(b'from-2'))
 
389
        self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
455
390
        self.assertFalse(
456
391
            tree_to.changes_from(tree_to.basis_tree()).has_changed())
457
392
 
458
393
        self.run_bzr_error(
459
 
            ['bzr: ERROR: bzr push --revision '
 
394
            ['brz: ERROR: brz push --revision '
460
395
             'takes exactly one revision identifier\n'],
461
396
            'push -r0..2 ../to', working_dir='from')
462
397
 
463
398
    def create_trunk_and_feature_branch(self):
464
399
        # We have a mainline
465
400
        trunk_tree = self.make_branch_and_tree('target',
466
 
            format='1.9')
 
401
                                               format='1.9')
467
402
        trunk_tree.commit('mainline')
468
403
        # and a branch from it
469
404
        branch_tree = self.make_branch_and_tree('branch',
470
 
            format='1.9')
 
405
                                                format='1.9')
471
406
        branch_tree.pull(trunk_tree.branch)
472
407
        branch_tree.branch.set_parent(trunk_tree.branch.base)
473
408
        # with some work on it
487
422
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
488
423
        # we publish branch_tree with a reference to the mainline.
489
424
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
490
 
            self.get_url('published')], working_dir='branch')
491
 
        self.assertEqual('', out)
492
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
493
 
            trunk_tree.branch.base, err)
494
 
        self.assertPublished(branch_tree.last_revision(),
495
 
            trunk_tree.branch.base)
 
425
                                 self.get_url('published')], working_dir='branch')
 
426
        self.assertEqual('', out)
 
427
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
428
                         trunk_tree.branch.base, err)
 
429
        self.assertPublished(branch_tree.last_revision(),
 
430
                             trunk_tree.branch.base)
 
431
 
 
432
    def test_push_new_branch_stacked_on(self):
 
433
        """Pushing a new branch with --stacked-on can use directory URLs."""
 
434
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
 
435
        class FooDirectory(object):
 
436
            def look_up(self, name, url, purpose=None):
 
437
                if url == 'foo:':
 
438
                    return trunk_tree.branch.base
 
439
                return url
 
440
        directory_service.directories.register('foo:', FooDirectory, 'Foo directory')
 
441
        self.addCleanup(directory_service.directories.remove, 'foo:')
 
442
        # we publish branch_tree with a reference to the mainline.
 
443
        out, err = self.run_bzr(['push', '--stacked-on', 'foo:',
 
444
                                 self.get_url('published')], working_dir='branch')
 
445
        self.assertEqual('', out)
 
446
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
447
                         trunk_tree.branch.base, err)
 
448
        self.assertPublished(branch_tree.last_revision(),
 
449
                             trunk_tree.branch.base)
496
450
 
497
451
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
498
452
        """When the parent has no public url the parent is used as-is."""
500
454
        # now we do a stacked push, which should determine the public location
501
455
        # for us.
502
456
        out, err = self.run_bzr(['push', '--stacked',
503
 
            self.get_url('published')], working_dir='branch')
 
457
                                 self.get_url('published')], working_dir='branch')
504
458
        self.assertEqual('', out)
505
459
        self.assertEqual('Created new stacked branch referring to %s.\n' %
506
 
            trunk_tree.branch.base, err)
 
460
                         trunk_tree.branch.base, err)
507
461
        self.assertPublished(branch_tree.last_revision(),
508
462
                             trunk_tree.branch.base)
509
463
 
520
474
        # now we do a stacked push, which should determine the public location
521
475
        # for us.
522
476
        out, err = self.run_bzr(['push', '--stacked',
523
 
            self.get_url('published')], working_dir='branch')
 
477
                                 self.get_url('published')], working_dir='branch')
524
478
        self.assertEqual('', out)
525
479
        self.assertEqual('Created new stacked branch referring to %s.\n' %
526
 
            trunk_public_url, err)
 
480
                         trunk_public_url, err)
527
481
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
528
482
 
529
483
    def test_push_new_branch_stacked_no_parent(self):
533
487
        # cannot be determined.
534
488
        out, err = self.run_bzr_error(
535
489
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
536
 
            self.get_url('published')], working_dir='branch')
 
490
                                                            self.get_url('published')], working_dir='branch')
537
491
        self.assertEqual('', out)
538
492
        self.assertFalse(self.get_transport('published').has('.'))
539
493
 
540
494
    def test_push_notifies_default_stacking(self):
541
495
        self.make_branch('stack_on', format='1.6')
542
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
496
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
543
497
        self.make_branch('from', format='1.6')
544
498
        out, err = self.run_bzr('push -d from to')
545
499
        self.assertContainsRe(err,
547
501
 
548
502
    def test_push_stacks_with_default_stacking_if_target_is_stackable(self):
549
503
        self.make_branch('stack_on', format='1.6')
550
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
504
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
551
505
        self.make_branch('from', format='pack-0.92')
552
506
        out, err = self.run_bzr('push -d from to')
553
507
        b = branch.Branch.open('to')
555
509
 
556
510
    def test_push_does_not_change_format_with_default_if_target_cannot(self):
557
511
        self.make_branch('stack_on', format='pack-0.92')
558
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
512
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
559
513
        self.make_branch('from', format='pack-0.92')
560
514
        out, err = self.run_bzr('push -d from to')
561
515
        b = branch.Branch.open('to')
562
 
        self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
 
516
        self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
563
517
 
564
518
    def test_push_doesnt_create_broken_branch(self):
565
519
        """Pushing a new standalone branch works even when there's a default
572
526
        self.make_repository('repo', shared=True, format='1.6')
573
527
        builder = self.make_branch_builder('repo/local', format='pack-0.92')
574
528
        builder.start_series()
575
 
        builder.build_snapshot('rev-1', None, [
576
 
            ('add', ('', 'root-id', 'directory', '')),
577
 
            ('add', ('filename', 'f-id', 'file', 'content\n'))])
578
 
        builder.build_snapshot('rev-2', ['rev-1'], [])
579
 
        builder.build_snapshot('rev-3', ['rev-2'],
580
 
            [('modify', ('f-id', 'new-content\n'))])
 
529
        builder.build_snapshot(None, [
 
530
            ('add', ('', b'root-id', 'directory', '')),
 
531
            ('add', ('filename', b'f-id', 'file', b'content\n'))],
 
532
            revision_id=b'rev-1')
 
533
        builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
 
534
        builder.build_snapshot([b'rev-2'],
 
535
                               [('modify', ('filename', b'new-content\n'))],
 
536
                               revision_id=b'rev-3')
581
537
        builder.finish_series()
582
538
        branch = builder.get_branch()
583
539
        # Push rev-1 to "trunk", so that we can stack on it.
584
540
        self.run_bzr('push -d repo/local trunk -r 1')
585
541
        # Set a default stacking policy so that new branches will automatically
586
542
        # stack on trunk.
587
 
        self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
 
543
        self.make_controldir('.').get_config().set_default_stack_on('trunk')
588
544
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
589
545
        out, err = self.run_bzr('push -d repo/local remote -r 2')
590
546
        self.assertContainsRe(
609
565
    def test_push_from_subdir(self):
610
566
        t = self.make_branch_and_tree('tree')
611
567
        self.build_tree(['tree/dir/', 'tree/dir/file'])
612
 
        t.add('dir', 'dir/file')
 
568
        t.add(['dir', 'dir/file'])
613
569
        t.commit('r1')
614
570
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
615
571
        self.assertEqual('', out)
618
574
    def test_overwrite_tags(self):
619
575
        """--overwrite-tags only overwrites tags, not revisions."""
620
576
        from_tree = self.make_branch_and_tree('from')
621
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
577
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
622
578
        to_tree = self.make_branch_and_tree('to')
623
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
579
        to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
624
580
        revid1 = to_tree.commit('my commit')
625
581
        out = self.run_bzr(['push', '-d', 'from', 'to'])
626
 
        self.assertEquals(out,
627
 
            ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
582
        self.assertEqual(out,
 
583
                         ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
628
584
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
629
 
        self.assertEquals(out, ('', '1 tag updated.\n'))
630
 
        self.assertEquals(to_tree.branch.tags.lookup_tag('mytag'),
631
 
                          'somerevid')
632
 
        self.assertEquals(to_tree.branch.last_revision(), revid1)
 
585
        self.assertEqual(out, ('', '1 tag updated.\n'))
 
586
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
 
587
                         b'somerevid')
 
588
        self.assertEqual(to_tree.branch.last_revision(), revid1)
633
589
 
634
590
 
635
591
class RedirectingMemoryTransport(memory.MemoryTransport):
722
678
 
723
679
    def make_local_branch_and_tree(self):
724
680
        self.tree = self.make_branch_and_tree('local')
725
 
        self.build_tree_contents([('local/file', 'initial')])
 
681
        self.build_tree_contents([('local/file', b'initial')])
726
682
        self.tree.add('file')
727
 
        self.tree.commit('adding file', rev_id='added')
728
 
        self.build_tree_contents([('local/file', 'modified')])
729
 
        self.tree.commit('modify file', rev_id='modified')
 
683
        self.tree.commit('adding file', rev_id=b'added')
 
684
        self.build_tree_contents([('local/file', b'modified')])
 
685
        self.tree.commit('modify file', rev_id=b'modified')
730
686
 
731
687
    def set_config_push_strict(self, value):
732
688
        br = branch.Branch.open('local')
735
691
    _default_command = ['push', '../to']
736
692
    _default_wd = 'local'
737
693
    _default_errors = ['Working tree ".*/local/" has uncommitted '
738
 
                       'changes \(See bzr status\)\.',]
 
694
                       'changes \\(See brz status\\)\\.', ]
739
695
    _default_additional_error = 'Use --no-strict to force the push.\n'
740
696
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
741
697
 
742
 
 
743
698
    def assertPushFails(self, args):
744
699
        out, err = self.run_bzr_error(self._default_errors,
745
700
                                      self._default_command + args,
767
722
        self.assertEqual(revid_to_push, branch_to.last_revision())
768
723
 
769
724
 
770
 
 
771
725
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
772
726
                                   TestPushStrictMixin):
773
727
 
795
749
 
796
750
strict_push_change_scenarios = [
797
751
    ('uncommitted',
798
 
        dict(_changes_type= '_uncommitted_changes')),
 
752
        dict(_changes_type='_uncommitted_changes')),
799
753
    ('pending-merges',
800
 
        dict(_changes_type= '_pending_merges')),
 
754
        dict(_changes_type='_pending_merges')),
801
755
    ('out-of-sync-trees',
802
 
        dict(_changes_type= '_out_of_sync_trees')),
 
756
        dict(_changes_type='_out_of_sync_trees')),
803
757
    ]
804
758
 
805
759
 
806
760
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
807
761
                                TestPushStrictMixin):
808
762
 
809
 
    scenarios = strict_push_change_scenarios 
810
 
    _changes_type = None # Set by load_tests
 
763
    scenarios = strict_push_change_scenarios
 
764
    _changes_type = None  # Set by load_tests
811
765
 
812
766
    def setUp(self):
813
767
        super(TestPushStrictWithChanges, self).setUp()
818
772
    def _uncommitted_changes(self):
819
773
        self.make_local_branch_and_tree()
820
774
        # Make a change without committing it
821
 
        self.build_tree_contents([('local/file', 'in progress')])
 
775
        self.build_tree_contents([('local/file', b'in progress')])
822
776
 
823
777
    def _pending_merges(self):
824
778
        self.make_local_branch_and_tree()
825
779
        # Create 'other' branch containing a new file
826
 
        other_bzrdir = self.tree.bzrdir.sprout('other')
 
780
        other_bzrdir = self.tree.controldir.sprout('other')
827
781
        other_tree = other_bzrdir.open_workingtree()
828
 
        self.build_tree_contents([('other/other-file', 'other')])
 
782
        self.build_tree_contents([('other/other-file', b'other')])
829
783
        other_tree.add('other-file')
830
 
        other_tree.commit('other commit', rev_id='other')
 
784
        other_tree.commit('other commit', rev_id=b'other')
831
785
        # Merge and revert, leaving a pending merge
832
786
        self.tree.merge_from_branch(other_tree.branch)
833
787
        self.tree.revert(filenames=['other-file'], backups=False)
836
790
        self.make_local_branch_and_tree()
837
791
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
838
792
        # Make a change and commit it
839
 
        self.build_tree_contents([('local/file', 'modified in local')])
840
 
        self.tree.commit('modify file', rev_id='modified-in-local')
 
793
        self.build_tree_contents([('local/file', b'modified in local')])
 
794
        self.tree.commit('modify file', rev_id=b'modified-in-local')
841
795
        # Exercise commands from the checkout directory
842
796
        self._default_wd = 'checkout'
843
797
        self._default_errors = ["Working tree is out of date, please run"
844
 
                                " 'bzr update'\.",]
 
798
                                " 'brz update'\\.", ]
845
799
 
846
800
    def test_push_default(self):
847
801
        self.assertPushSucceeds([], with_warning=True)
848
802
 
849
803
    def test_push_with_revision(self):
850
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
804
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
851
805
 
852
806
    def test_push_no_strict(self):
853
807
        self.assertPushSucceeds(['--no-strict'])
883
837
    def make_dummy_builder(self, relpath):
884
838
        builder = self.make_branch_builder(
885
839
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
886
 
        builder.build_snapshot('revid', None,
887
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
888
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
 
840
        builder.build_snapshot(None,
 
841
                               [('add', ('', b'TREE_ROOT', 'directory', None)),
 
842
                                ('add', ('foo', b'fooid', 'file', b'bar'))],
 
843
                               revision_id=b'revid')
889
844
        return builder
890
845
 
891
846
    def test_no_roundtripping(self):
892
847
        target_branch = self.make_dummy_builder('dp').get_branch()
893
848
        source_tree = self.make_branch_and_tree("dc")
894
849
        output, error = self.run_bzr("push -d dc dp", retcode=3)
895
 
        self.assertEquals("", output)
896
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
897
 
            " push to dummy. You may want to use dpush instead.\n")
 
850
        self.assertEqual("", output)
 
851
        self.assertEqual(
 
852
            error,
 
853
            "brz: ERROR: It is not possible to losslessly"
 
854
            " push to dummy. You may want to use --lossy.\n")
898
855
 
899
856
 
900
857
class TestPushOutput(script.TestCaseWithTransportAndScript):
901
858
 
902
859
    def test_push_log_format(self):
903
860
        self.run_script("""
904
 
            $ bzr init trunk
 
861
            $ brz init trunk
905
862
            Created a standalone tree (format: 2a)
906
863
            $ cd trunk
907
864
            $ echo foo > file
908
 
            $ bzr add
 
865
            $ brz add
909
866
            adding file
910
 
            $ bzr commit -m 'we need some foo'
 
867
            $ brz commit -m 'we need some foo'
911
868
            2>Committing to:...trunk/
912
869
            2>added file
913
870
            2>Committed revision 1.
914
 
            $ bzr init ../feature
 
871
            $ brz init ../feature
915
872
            Created a standalone tree (format: 2a)
916
 
            $ bzr push -v ../feature -Olog_format=line
 
873
            $ brz push -v ../feature -Olog_format=line
917
874
            Added Revisions:
918
875
            1: jrandom@example.com ...we need some foo
919
876
            2>All changes applied successfully.
922
879
 
923
880
    def test_push_with_revspec(self):
924
881
        self.run_script("""
925
 
            $ bzr init-repo .
 
882
            $ brz init-shared-repo .
926
883
            Shared repository with trees (format: 2a)
927
884
            Location:
928
885
              shared repository: .
929
 
            $ bzr init trunk
 
886
            $ brz init trunk
930
887
            Created a repository tree (format: 2a)
931
888
            Using shared repository...
932
889
            $ cd trunk
933
 
            $ bzr commit -m 'first rev' --unchanged
 
890
            $ brz commit -m 'first rev' --unchanged
934
891
            2>Committing to:...trunk/
935
892
            2>Committed revision 1.
936
893
            $ echo foo > file
937
 
            $ bzr add
 
894
            $ brz add
938
895
            adding file
939
 
            $ bzr commit -m 'we need some foo'
 
896
            $ brz commit -m 'we need some foo'
940
897
            2>Committing to:...trunk/
941
898
            2>added file
942
899
            2>Committed revision 2.
943
 
            $ bzr push -r 1 ../other
 
900
            $ brz push -r 1 ../other
944
901
            2>Created new branch.
945
 
            $ bzr st ../other # checking that file is not created (#484516)
 
902
            $ brz st ../other # checking that file is not created (#484516)
946
903
            """)