/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 brzlib/tests/blackbox/test_push.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

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