/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: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from breezy import (
23
23
    branch,
 
24
    bzrdir,
24
25
    controldir,
25
 
    directory_service,
26
26
    errors,
27
27
    osutils,
28
28
    tests,
31
31
    urlutils,
32
32
    workingtree
33
33
    )
34
 
from breezy.bzr import (
35
 
    bzrdir,
36
 
    )
37
 
from breezy.bzr import knitrepo
 
34
from breezy.repofmt import knitrepo
38
35
from breezy.tests import (
39
36
    http_server,
40
37
    scenarios,
41
38
    script,
42
39
    test_foreign,
43
40
    )
 
41
from breezy.tests.matchers import ContainsNoVfsCalls
44
42
from breezy.transport import memory
45
43
 
46
44
 
68
66
        # If there is no parent location set, :parent isn't mentioned.
69
67
        out = self.run_bzr('push', working_dir='a', retcode=3)
70
68
        self.assertEqual(out,
71
 
                         ('', 'brz: ERROR: No push location known or specified.\n'))
 
69
                ('','brz: ERROR: No push location known or specified.\n'))
72
70
 
73
71
        # If there is a parent location set, the error suggests :parent.
74
72
        tree_a.branch.set_parent(tree_b.branch.base)
75
73
        out = self.run_bzr('push', working_dir='a', retcode=3)
76
74
        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')))
 
75
            ('','brz: ERROR: No push location known or specified. '
 
76
                'To push to the parent branch '
 
77
                '(at %s), use \'brz push :parent\'.\n' %
 
78
                urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
81
79
 
82
80
    def test_push_remember(self):
83
81
        """Push changes from one branch to another and test push location."""
87
85
        self.build_tree(['branch_a/a'])
88
86
        tree_a.add('a')
89
87
        tree_a.commit('commit a')
90
 
        tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
 
88
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
91
89
        branch_b = tree_b.branch
92
 
        tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
 
90
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
93
91
        branch_c = tree_c.branch
94
92
        self.build_tree(['branch_a/b'])
95
93
        tree_a.add('b')
103
101
        # test push for failure without push location set
104
102
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
105
103
        self.assertEqual(out,
106
 
                         ('', 'brz: ERROR: No push location known or specified.\n'))
 
104
                ('','brz: ERROR: No push location known or specified.\n'))
107
105
 
108
106
        # test not remembered if cannot actually push
109
107
        self.run_bzr('push path/which/doesnt/exist',
110
108
                     working_dir='branch_a', retcode=3)
111
109
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
112
110
        self.assertEqual(
113
 
            ('', 'brz: ERROR: No push location known or specified.\n'),
114
 
            out)
 
111
                ('', 'brz: ERROR: No push location known or specified.\n'),
 
112
                out)
115
113
 
116
114
        # test implicit --remember when no push location set, push fails
117
115
        out = self.run_bzr('push ../branch_b',
118
116
                           working_dir='branch_a', retcode=3)
119
117
        self.assertEqual(out,
120
 
                         ('', 'brz: ERROR: These branches have diverged.  '
121
 
                          'See "brz help diverged-branches" for more information.\n'))
 
118
                ('','brz: ERROR: These branches have diverged.  '
 
119
                 'See "brz help diverged-branches" for more information.\n'))
122
120
        # Refresh the branch as 'push' modified it
123
 
        branch_a = branch_a.controldir.open_branch()
 
121
        branch_a = branch_a.bzrdir.open_branch()
124
122
        self.assertEqual(osutils.abspath(branch_a.get_push_location()),
125
 
                         osutils.abspath(branch_b.controldir.root_transport.base))
 
123
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
126
124
 
127
125
        # test implicit --remember after resolving previous failure
128
126
        uncommit.uncommit(branch=branch_b, tree=tree_b)
129
127
        transport.delete('branch_b/c')
130
128
        out, err = self.run_bzr('push', working_dir='branch_a')
131
129
        # Refresh the branch as 'push' modified it
132
 
        branch_a = branch_a.controldir.open_branch()
 
130
        branch_a = branch_a.bzrdir.open_branch()
133
131
        path = branch_a.get_push_location()
134
132
        self.assertEqual(err,
135
133
                         'Using saved push location: %s\n'
137
135
                         'Pushed up to revision 2.\n'
138
136
                         % urlutils.local_path_from_url(path))
139
137
        self.assertEqual(path,
140
 
                         branch_b.controldir.root_transport.base)
 
138
                         branch_b.bzrdir.root_transport.base)
141
139
        # test explicit --remember
142
140
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
143
141
        # Refresh the branch as 'push' modified it
144
 
        branch_a = branch_a.controldir.open_branch()
 
142
        branch_a = branch_a.bzrdir.open_branch()
145
143
        self.assertEqual(branch_a.get_push_location(),
146
 
                         branch_c.controldir.root_transport.base)
 
144
                          branch_c.bzrdir.root_transport.base)
147
145
 
148
146
    def test_push_without_tree(self):
149
147
        # brz push from a branch that does not have a checkout should work.
185
183
        t.commit('commit 1')
186
184
        self.run_bzr('push -d tree pushed-to')
187
185
        # Refresh the branch as 'push' modified it and get the push location
188
 
        push_loc = t.branch.controldir.open_branch().get_push_location()
 
186
        push_loc = t.branch.bzrdir.open_branch().get_push_location()
189
187
        out, err = self.run_bzr('push', working_dir="tree")
190
188
        self.assertEqual('Using saved push location: %s\n'
191
189
                         'No new revisions or tags to push.\n' %
202
200
        shared_repo.set_make_working_trees(True)
203
201
 
204
202
        def make_shared_tree(path):
205
 
            shared_repo.controldir.root_transport.mkdir(path)
 
203
            shared_repo.bzrdir.root_transport.mkdir(path)
206
204
            controldir.ControlDir.create_branch_convenience('repo/' + path)
207
205
            return workingtree.WorkingTree.open('repo/' + path)
208
206
        tree_a = make_shared_tree('a')
209
207
        self.build_tree(['repo/a/file'])
210
208
        tree_a.add('file')
211
 
        tree_a.commit('commit a-1', rev_id=b'a-1')
 
209
        tree_a.commit('commit a-1', rev_id='a-1')
212
210
        f = open('repo/a/file', 'ab')
213
 
        f.write(b'more stuff\n')
 
211
        f.write('more stuff\n')
214
212
        f.close()
215
 
        tree_a.commit('commit a-2', rev_id=b'a-2')
 
213
        tree_a.commit('commit a-2', rev_id='a-2')
216
214
 
217
215
        tree_b = make_shared_tree('b')
218
216
        self.build_tree(['repo/b/file'])
219
217
        tree_b.add('file')
220
 
        tree_b.commit('commit b-1', rev_id=b'b-1')
 
218
        tree_b.commit('commit b-1', rev_id='b-1')
221
219
 
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'))
 
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'))
225
223
 
226
224
        # Now that we have a repository with shared files, make sure
227
225
        # that things aren't copied out by a 'push'
228
226
        self.run_bzr('push ../../push-b', working_dir='repo/b')
229
227
        pushed_tree = workingtree.WorkingTree.open('push-b')
230
228
        pushed_repo = pushed_tree.branch.repository
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'))
 
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'))
234
232
 
235
233
    def test_push_funky_id(self):
236
234
        t = self.make_branch_and_tree('tree')
237
235
        self.build_tree(['tree/filename'])
238
 
        t.add('filename', b'funky-chars<>%&;"\'')
 
236
        t.add('filename', 'funky-chars<>%&;"\'')
239
237
        t.commit('commit filename')
240
238
        self.run_bzr('push -d tree new-tree')
241
239
 
242
240
    def test_push_dash_d(self):
243
241
        t = self.make_branch_and_tree('from')
244
242
        t.commit(allow_pointless=True,
245
 
                 message='first commit')
 
243
                message='first commit')
246
244
        self.run_bzr('push -d from to-one')
247
245
        self.assertPathExists('to-one')
248
246
        self.run_bzr('push -d %s %s'
249
 
                     % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
 
247
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
250
248
        self.assertPathExists('to-two')
251
249
 
252
250
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
254
252
        target_repo = self.make_repository('target')
255
253
        source = self.make_branch_builder('source')
256
254
        source.start_series()
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')
 
255
        source.build_snapshot('A', None, [
 
256
            ('add', ('', 'root-id', 'directory', None))])
 
257
        source.build_snapshot('B', ['A'], [])
 
258
        source.build_snapshot('C', ['A'], [])
262
259
        source.finish_series()
263
260
        self.run_bzr('push target -d source')
264
261
        self.addCleanup(target_repo.lock_read().unlock)
265
262
        # We should have pushed 'C', but not 'B', since it isn't in the
266
263
        # ancestry
267
 
        self.assertEqual([(b'A',), (b'C',)], sorted(
268
 
            target_repo.revisions.keys()))
 
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)
269
334
 
270
335
    def test_push_smart_with_default_stacking_url_path_segment(self):
271
336
        # If the default stacked-on location is a path element then branches
273
338
        # stacked_on_url is that exact path segment. Added to nail bug 385132.
274
339
        self.setup_smart_server_with_call_log()
275
340
        self.make_branch('stack-on', format='1.9')
276
 
        self.make_controldir('.').get_config().set_default_stack_on(
 
341
        self.make_bzrdir('.').get_config().set_default_stack_on(
277
342
            '/stack-on')
278
343
        self.make_branch('from', format='1.9')
279
344
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
286
351
        # stacked_on_url is a relative path. Added to nail bug 385132.
287
352
        self.setup_smart_server_with_call_log()
288
353
        self.make_branch('stack-on', format='1.9')
289
 
        self.make_controldir('.').get_config().set_default_stack_on('stack-on')
 
354
        self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
290
355
        self.make_branch('from', format='1.9')
291
356
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
292
357
        b = branch.Branch.open(self.get_url('to'))
295
360
    def create_simple_tree(self):
296
361
        tree = self.make_branch_and_tree('tree')
297
362
        self.build_tree(['tree/a'])
298
 
        tree.add(['a'], [b'a-id'])
299
 
        tree.commit('one', rev_id=b'r1')
 
363
        tree.add(['a'], ['a-id'])
 
364
        tree.commit('one', rev_id='r1')
300
365
        return tree
301
366
 
302
367
    def test_push_create_prefix(self):
322
387
 
323
388
        self.run_bzr_error(['Target directory ../target already exists',
324
389
                            'Supply --use-existing-dir',
325
 
                            ],
 
390
                           ],
326
391
                           'push ../target', working_dir='tree')
327
392
 
328
393
        self.run_bzr('push --use-existing-dir ../target',
368
433
        # TODO: jam 20070109 Maybe it would be better to create the repository
369
434
        #       if at this point
370
435
        tree = self.create_simple_tree()
371
 
        a_controldir = self.make_controldir('dir')
 
436
        a_bzrdir = self.make_bzrdir('dir')
372
437
 
373
438
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
374
 
                           'push ../dir',
375
 
                           working_dir='tree')
 
439
                'push ../dir',
 
440
                working_dir='tree')
376
441
 
377
442
    def test_push_with_revisionspec(self):
378
443
        """We should be able to push a revision older than the tip."""
379
444
        tree_from = self.make_branch_and_tree('from')
380
 
        tree_from.commit("One.", rev_id=b"from-1")
381
 
        tree_from.commit("Two.", rev_id=b"from-2")
 
445
        tree_from.commit("One.", rev_id="from-1")
 
446
        tree_from.commit("Two.", rev_id="from-2")
382
447
 
383
448
        self.run_bzr('push -r1 ../to', working_dir='from')
384
449
 
385
450
        tree_to = workingtree.WorkingTree.open('to')
386
451
        repo_to = tree_to.branch.repository
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')
 
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')
390
455
        self.assertFalse(
391
456
            tree_to.changes_from(tree_to.basis_tree()).has_changed())
392
457
 
398
463
    def create_trunk_and_feature_branch(self):
399
464
        # We have a mainline
400
465
        trunk_tree = self.make_branch_and_tree('target',
401
 
                                               format='1.9')
 
466
            format='1.9')
402
467
        trunk_tree.commit('mainline')
403
468
        # and a branch from it
404
469
        branch_tree = self.make_branch_and_tree('branch',
405
 
                                                format='1.9')
 
470
            format='1.9')
406
471
        branch_tree.pull(trunk_tree.branch)
407
472
        branch_tree.branch.set_parent(trunk_tree.branch.base)
408
473
        # with some work on it
422
487
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
423
488
        # we publish branch_tree with a reference to the mainline.
424
489
        out, err = self.run_bzr(['push', '--stacked-on', 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)
 
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)
450
496
 
451
497
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
452
498
        """When the parent has no public url the parent is used as-is."""
454
500
        # now we do a stacked push, which should determine the public location
455
501
        # for us.
456
502
        out, err = self.run_bzr(['push', '--stacked',
457
 
                                 self.get_url('published')], working_dir='branch')
 
503
            self.get_url('published')], working_dir='branch')
458
504
        self.assertEqual('', out)
459
505
        self.assertEqual('Created new stacked branch referring to %s.\n' %
460
 
                         trunk_tree.branch.base, err)
 
506
            trunk_tree.branch.base, err)
461
507
        self.assertPublished(branch_tree.last_revision(),
462
508
                             trunk_tree.branch.base)
463
509
 
474
520
        # now we do a stacked push, which should determine the public location
475
521
        # for us.
476
522
        out, err = self.run_bzr(['push', '--stacked',
477
 
                                 self.get_url('published')], working_dir='branch')
 
523
            self.get_url('published')], working_dir='branch')
478
524
        self.assertEqual('', out)
479
525
        self.assertEqual('Created new stacked branch referring to %s.\n' %
480
 
                         trunk_public_url, err)
 
526
            trunk_public_url, err)
481
527
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
482
528
 
483
529
    def test_push_new_branch_stacked_no_parent(self):
487
533
        # cannot be determined.
488
534
        out, err = self.run_bzr_error(
489
535
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
490
 
                                                            self.get_url('published')], working_dir='branch')
 
536
            self.get_url('published')], working_dir='branch')
491
537
        self.assertEqual('', out)
492
538
        self.assertFalse(self.get_transport('published').has('.'))
493
539
 
494
540
    def test_push_notifies_default_stacking(self):
495
541
        self.make_branch('stack_on', format='1.6')
496
 
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
 
542
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
497
543
        self.make_branch('from', format='1.6')
498
544
        out, err = self.run_bzr('push -d from to')
499
545
        self.assertContainsRe(err,
501
547
 
502
548
    def test_push_stacks_with_default_stacking_if_target_is_stackable(self):
503
549
        self.make_branch('stack_on', format='1.6')
504
 
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
 
550
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
505
551
        self.make_branch('from', format='pack-0.92')
506
552
        out, err = self.run_bzr('push -d from to')
507
553
        b = branch.Branch.open('to')
509
555
 
510
556
    def test_push_does_not_change_format_with_default_if_target_cannot(self):
511
557
        self.make_branch('stack_on', format='pack-0.92')
512
 
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
 
558
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
513
559
        self.make_branch('from', format='pack-0.92')
514
560
        out, err = self.run_bzr('push -d from to')
515
561
        b = branch.Branch.open('to')
516
 
        self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
 
562
        self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
517
563
 
518
564
    def test_push_doesnt_create_broken_branch(self):
519
565
        """Pushing a new standalone branch works even when there's a default
526
572
        self.make_repository('repo', shared=True, format='1.6')
527
573
        builder = self.make_branch_builder('repo/local', format='pack-0.92')
528
574
        builder.start_series()
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')
 
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'))])
537
581
        builder.finish_series()
538
582
        branch = builder.get_branch()
539
583
        # Push rev-1 to "trunk", so that we can stack on it.
540
584
        self.run_bzr('push -d repo/local trunk -r 1')
541
585
        # Set a default stacking policy so that new branches will automatically
542
586
        # stack on trunk.
543
 
        self.make_controldir('.').get_config().set_default_stack_on('trunk')
 
587
        self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
544
588
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
545
589
        out, err = self.run_bzr('push -d repo/local remote -r 2')
546
590
        self.assertContainsRe(
565
609
    def test_push_from_subdir(self):
566
610
        t = self.make_branch_and_tree('tree')
567
611
        self.build_tree(['tree/dir/', 'tree/dir/file'])
568
 
        t.add(['dir', 'dir/file'])
 
612
        t.add('dir', 'dir/file')
569
613
        t.commit('r1')
570
614
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
571
615
        self.assertEqual('', out)
574
618
    def test_overwrite_tags(self):
575
619
        """--overwrite-tags only overwrites tags, not revisions."""
576
620
        from_tree = self.make_branch_and_tree('from')
577
 
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
 
621
        from_tree.branch.tags.set_tag("mytag", "somerevid")
578
622
        to_tree = self.make_branch_and_tree('to')
579
 
        to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
 
623
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
580
624
        revid1 = to_tree.commit('my commit')
581
625
        out = self.run_bzr(['push', '-d', 'from', 'to'])
582
626
        self.assertEqual(out,
583
 
                         ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
627
            ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
584
628
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
585
629
        self.assertEqual(out, ('', '1 tag updated.\n'))
586
630
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
587
 
                         b'somerevid')
 
631
                          'somerevid')
588
632
        self.assertEqual(to_tree.branch.last_revision(), revid1)
589
633
 
590
634
 
678
722
 
679
723
    def make_local_branch_and_tree(self):
680
724
        self.tree = self.make_branch_and_tree('local')
681
 
        self.build_tree_contents([('local/file', b'initial')])
 
725
        self.build_tree_contents([('local/file', 'initial')])
682
726
        self.tree.add('file')
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')
 
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')
686
730
 
687
731
    def set_config_push_strict(self, value):
688
732
        br = branch.Branch.open('local')
691
735
    _default_command = ['push', '../to']
692
736
    _default_wd = 'local'
693
737
    _default_errors = ['Working tree ".*/local/" has uncommitted '
694
 
                       'changes \\(See brz status\\)\\.', ]
 
738
                       'changes \(See brz status\)\.',]
695
739
    _default_additional_error = 'Use --no-strict to force the push.\n'
696
740
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
697
741
 
 
742
 
698
743
    def assertPushFails(self, args):
699
744
        out, err = self.run_bzr_error(self._default_errors,
700
745
                                      self._default_command + args,
722
767
        self.assertEqual(revid_to_push, branch_to.last_revision())
723
768
 
724
769
 
 
770
 
725
771
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
726
772
                                   TestPushStrictMixin):
727
773
 
749
795
 
750
796
strict_push_change_scenarios = [
751
797
    ('uncommitted',
752
 
        dict(_changes_type='_uncommitted_changes')),
 
798
        dict(_changes_type= '_uncommitted_changes')),
753
799
    ('pending-merges',
754
 
        dict(_changes_type='_pending_merges')),
 
800
        dict(_changes_type= '_pending_merges')),
755
801
    ('out-of-sync-trees',
756
 
        dict(_changes_type='_out_of_sync_trees')),
 
802
        dict(_changes_type= '_out_of_sync_trees')),
757
803
    ]
758
804
 
759
805
 
760
806
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
761
807
                                TestPushStrictMixin):
762
808
 
763
 
    scenarios = strict_push_change_scenarios
764
 
    _changes_type = None  # Set by load_tests
 
809
    scenarios = strict_push_change_scenarios 
 
810
    _changes_type = None # Set by load_tests
765
811
 
766
812
    def setUp(self):
767
813
        super(TestPushStrictWithChanges, self).setUp()
772
818
    def _uncommitted_changes(self):
773
819
        self.make_local_branch_and_tree()
774
820
        # Make a change without committing it
775
 
        self.build_tree_contents([('local/file', b'in progress')])
 
821
        self.build_tree_contents([('local/file', 'in progress')])
776
822
 
777
823
    def _pending_merges(self):
778
824
        self.make_local_branch_and_tree()
779
825
        # Create 'other' branch containing a new file
780
 
        other_bzrdir = self.tree.controldir.sprout('other')
 
826
        other_bzrdir = self.tree.bzrdir.sprout('other')
781
827
        other_tree = other_bzrdir.open_workingtree()
782
 
        self.build_tree_contents([('other/other-file', b'other')])
 
828
        self.build_tree_contents([('other/other-file', 'other')])
783
829
        other_tree.add('other-file')
784
 
        other_tree.commit('other commit', rev_id=b'other')
 
830
        other_tree.commit('other commit', rev_id='other')
785
831
        # Merge and revert, leaving a pending merge
786
832
        self.tree.merge_from_branch(other_tree.branch)
787
833
        self.tree.revert(filenames=['other-file'], backups=False)
790
836
        self.make_local_branch_and_tree()
791
837
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
792
838
        # Make a change and commit it
793
 
        self.build_tree_contents([('local/file', b'modified in local')])
794
 
        self.tree.commit('modify file', rev_id=b'modified-in-local')
 
839
        self.build_tree_contents([('local/file', 'modified in local')])
 
840
        self.tree.commit('modify file', rev_id='modified-in-local')
795
841
        # Exercise commands from the checkout directory
796
842
        self._default_wd = 'checkout'
797
843
        self._default_errors = ["Working tree is out of date, please run"
798
 
                                " 'brz update'\\.", ]
 
844
                                " 'brz update'\.",]
799
845
 
800
846
    def test_push_default(self):
801
847
        self.assertPushSucceeds([], with_warning=True)
802
848
 
803
849
    def test_push_with_revision(self):
804
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
 
850
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
805
851
 
806
852
    def test_push_no_strict(self):
807
853
        self.assertPushSucceeds(['--no-strict'])
837
883
    def make_dummy_builder(self, relpath):
838
884
        builder = self.make_branch_builder(
839
885
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
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')
 
886
        builder.build_snapshot('revid', None,
 
887
            [('add', ('', 'TREE_ROOT', 'directory', None)),
 
888
             ('add', ('foo', 'fooid', 'file', 'bar'))])
844
889
        return builder
845
890
 
846
891
    def test_no_roundtripping(self):
848
893
        source_tree = self.make_branch_and_tree("dc")
849
894
        output, error = self.run_bzr("push -d dc dp", retcode=3)
850
895
        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")
 
896
        self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
 
897
            " push to dummy. You may want to use dpush instead.\n")
855
898
 
856
899
 
857
900
class TestPushOutput(script.TestCaseWithTransportAndScript):
879
922
 
880
923
    def test_push_with_revspec(self):
881
924
        self.run_script("""
882
 
            $ brz init-shared-repo .
 
925
            $ brz init-repo .
883
926
            Shared repository with trees (format: 2a)
884
927
            Location:
885
928
              shared repository: .