/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: 2019-02-15 17:41:17 UTC
  • mto: (7290.1.2 work)
  • mto: This revision was merged to the branch mainline in revision 7295.
  • Revision ID: jelmer@jelmer.uk-20190215174117-o9w1am2z88mg9g1q
Update references to home location.

~/.config/breezy rather than ~/.bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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,
 
24
    controldir,
25
25
    errors,
26
26
    osutils,
27
27
    tests,
30
30
    urlutils,
31
31
    workingtree
32
32
    )
33
 
from bzrlib.repofmt import knitrepo
34
 
from bzrlib.tests import (
35
 
    blackbox,
 
33
from breezy.bzr import (
 
34
    bzrdir,
 
35
    )
 
36
from breezy.bzr import knitrepo
 
37
from breezy.tests import (
36
38
    http_server,
 
39
    scenarios,
 
40
    script,
37
41
    test_foreign,
38
 
    test_server,
39
42
    )
40
 
from bzrlib.transport import memory
41
 
 
42
 
 
43
 
def load_tests(standard_tests, module, loader):
44
 
    """Multiply tests for the push command."""
45
 
    result = loader.suiteClass()
46
 
 
47
 
    # one for each king of change
48
 
    changes_tests, remaining_tests = tests.split_suite_by_condition(
49
 
        standard_tests, tests.condition_isinstance((
50
 
                TestPushStrictWithChanges,
51
 
                )))
52
 
    changes_scenarios = [
53
 
        ('uncommitted',
54
 
         dict(_changes_type= '_uncommitted_changes')),
55
 
        ('pending-merges',
56
 
         dict(_changes_type= '_pending_merges')),
57
 
        ('out-of-sync-trees',
58
 
         dict(_changes_type= '_out_of_sync_trees')),
59
 
        ]
60
 
    tests.multiply_tests(changes_tests, changes_scenarios, result)
61
 
    # No parametrization for the remaining tests
62
 
    result.addTests(remaining_tests)
63
 
 
64
 
    return result
 
43
from breezy.tests.matchers import ContainsNoVfsCalls
 
44
from breezy.transport import memory
 
45
 
 
46
 
 
47
load_tests = scenarios.load_tests_apply_scenarios
65
48
 
66
49
 
67
50
class TestPush(tests.TestCaseWithTransport):
76
59
                           ['push', public_url],
77
60
                           working_dir='source')
78
61
 
 
62
    def test_push_suggests_parent_alias(self):
 
63
        """Push suggests using :parent if there is a known parent branch."""
 
64
        tree_a = self.make_branch_and_tree('a')
 
65
        tree_a.commit('this is a commit')
 
66
        tree_b = self.make_branch_and_tree('b')
 
67
 
 
68
        # If there is no parent location set, :parent isn't mentioned.
 
69
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
70
        self.assertEqual(out,
 
71
                         ('', 'brz: ERROR: No push location known or specified.\n'))
 
72
 
 
73
        # If there is a parent location set, the error suggests :parent.
 
74
        tree_a.branch.set_parent(tree_b.branch.base)
 
75
        out = self.run_bzr('push', working_dir='a', retcode=3)
 
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')))
 
81
 
79
82
    def test_push_remember(self):
80
83
        """Push changes from one branch to another and test push location."""
81
84
        transport = self.get_transport()
84
87
        self.build_tree(['branch_a/a'])
85
88
        tree_a.add('a')
86
89
        tree_a.commit('commit a')
87
 
        tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
 
90
        tree_b = branch_a.controldir.sprout('branch_b').open_workingtree()
88
91
        branch_b = tree_b.branch
89
 
        tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
 
92
        tree_c = branch_a.controldir.sprout('branch_c').open_workingtree()
90
93
        branch_c = tree_c.branch
91
94
        self.build_tree(['branch_a/b'])
92
95
        tree_a.add('b')
99
102
 
100
103
        # test push for failure without push location set
101
104
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
102
 
        self.assertEquals(out,
103
 
                ('','bzr: ERROR: No push location known or specified.\n'))
 
105
        self.assertEqual(out,
 
106
                         ('', 'brz: ERROR: No push location known or specified.\n'))
104
107
 
105
108
        # test not remembered if cannot actually push
106
109
        self.run_bzr('push path/which/doesnt/exist',
107
110
                     working_dir='branch_a', retcode=3)
108
111
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
109
 
        self.assertEquals(
110
 
                ('', 'bzr: ERROR: No push location known or specified.\n'),
111
 
                out)
 
112
        self.assertEqual(
 
113
            ('', 'brz: ERROR: No push location known or specified.\n'),
 
114
            out)
112
115
 
113
116
        # test implicit --remember when no push location set, push fails
114
117
        out = self.run_bzr('push ../branch_b',
115
118
                           working_dir='branch_a', retcode=3)
116
 
        self.assertEquals(out,
117
 
                ('','bzr: ERROR: These branches have diverged.  '
118
 
                 'See "bzr help diverged-branches" for more information.\n'))
119
 
        self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
 
                          osutils.abspath(branch_b.bzrdir.root_transport.base))
 
119
        self.assertEqual(out,
 
120
                         ('', 'brz: ERROR: These branches have diverged.  '
 
121
                          'See "brz help diverged-branches" for more information.\n'))
 
122
        # Refresh the branch as 'push' modified it
 
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))
121
126
 
122
127
        # test implicit --remember after resolving previous failure
123
128
        uncommit.uncommit(branch=branch_b, tree=tree_b)
124
129
        transport.delete('branch_b/c')
125
130
        out, err = self.run_bzr('push', working_dir='branch_a')
 
131
        # Refresh the branch as 'push' modified it
 
132
        branch_a = branch_a.controldir.open_branch()
126
133
        path = branch_a.get_push_location()
127
 
        self.assertEquals(out,
128
 
                          'Using saved push location: %s\n'
129
 
                          % urlutils.local_path_from_url(path))
130
134
        self.assertEqual(err,
 
135
                         'Using saved push location: %s\n'
131
136
                         'All changes applied successfully.\n'
132
 
                         'Pushed up to revision 2.\n')
 
137
                         'Pushed up to revision 2.\n'
 
138
                         % urlutils.local_path_from_url(path))
133
139
        self.assertEqual(path,
134
 
                         branch_b.bzrdir.root_transport.base)
 
140
                         branch_b.controldir.root_transport.base)
135
141
        # test explicit --remember
136
142
        self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
137
 
        self.assertEquals(branch_a.get_push_location(),
138
 
                          branch_c.bzrdir.root_transport.base)
 
143
        # Refresh the branch as 'push' modified it
 
144
        branch_a = branch_a.controldir.open_branch()
 
145
        self.assertEqual(branch_a.get_push_location(),
 
146
                         branch_c.controldir.root_transport.base)
139
147
 
140
148
    def test_push_without_tree(self):
141
 
        # 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.
142
150
        b = self.make_branch('.')
143
151
        out, err = self.run_bzr('push pushed-location')
144
152
        self.assertEqual('', out)
146
154
        b2 = branch.Branch.open('pushed-location')
147
155
        self.assertEndsWith(b2.base, 'pushed-location/')
148
156
 
 
157
    def test_push_no_tree(self):
 
158
        # brz push --no-tree of a branch with working trees
 
159
        b = self.make_branch_and_tree('push-from')
 
160
        self.build_tree(['push-from/file'])
 
161
        b.add('file')
 
162
        b.commit('commit 1')
 
163
        out, err = self.run_bzr('push --no-tree -d push-from push-to')
 
164
        self.assertEqual('', out)
 
165
        self.assertEqual('Created new branch.\n', err)
 
166
        self.assertPathDoesNotExist('push-to/file')
 
167
 
149
168
    def test_push_new_branch_revision_count(self):
150
 
        # bzr push of a branch with revisions to a new location
 
169
        # brz push of a branch with revisions to a new location
151
170
        # should print the number of revisions equal to the length of the
152
171
        # local branch.
153
172
        t = self.make_branch_and_tree('tree')
158
177
        self.assertEqual('', out)
159
178
        self.assertEqual('Created new branch.\n', err)
160
179
 
 
180
    def test_push_quiet(self):
 
181
        # test that using -q makes output quiet
 
182
        t = self.make_branch_and_tree('tree')
 
183
        self.build_tree(['tree/file'])
 
184
        t.add('file')
 
185
        t.commit('commit 1')
 
186
        self.run_bzr('push -d tree pushed-to')
 
187
        # Refresh the branch as 'push' modified it and get the push location
 
188
        push_loc = t.branch.controldir.open_branch().get_push_location()
 
189
        out, err = self.run_bzr('push', working_dir="tree")
 
190
        self.assertEqual('Using saved push location: %s\n'
 
191
                         'No new revisions or tags to push.\n' %
 
192
                         urlutils.local_path_from_url(push_loc), err)
 
193
        out, err = self.run_bzr('push -q', working_dir="tree")
 
194
        self.assertEqual('', out)
 
195
        self.assertEqual('', err)
 
196
 
161
197
    def test_push_only_pushes_history(self):
162
198
        # Knit branches should only push the history for the current revision.
163
199
        format = bzrdir.BzrDirMetaFormat1()
166
202
        shared_repo.set_make_working_trees(True)
167
203
 
168
204
        def make_shared_tree(path):
169
 
            shared_repo.bzrdir.root_transport.mkdir(path)
170
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
205
            shared_repo.controldir.root_transport.mkdir(path)
 
206
            controldir.ControlDir.create_branch_convenience('repo/' + path)
171
207
            return workingtree.WorkingTree.open('repo/' + path)
172
208
        tree_a = make_shared_tree('a')
173
209
        self.build_tree(['repo/a/file'])
174
210
        tree_a.add('file')
175
 
        tree_a.commit('commit a-1', rev_id='a-1')
 
211
        tree_a.commit('commit a-1', rev_id=b'a-1')
176
212
        f = open('repo/a/file', 'ab')
177
 
        f.write('more stuff\n')
 
213
        f.write(b'more stuff\n')
178
214
        f.close()
179
 
        tree_a.commit('commit a-2', rev_id='a-2')
 
215
        tree_a.commit('commit a-2', rev_id=b'a-2')
180
216
 
181
217
        tree_b = make_shared_tree('b')
182
218
        self.build_tree(['repo/b/file'])
183
219
        tree_b.add('file')
184
 
        tree_b.commit('commit b-1', rev_id='b-1')
 
220
        tree_b.commit('commit b-1', rev_id=b'b-1')
185
221
 
186
 
        self.assertTrue(shared_repo.has_revision('a-1'))
187
 
        self.assertTrue(shared_repo.has_revision('a-2'))
188
 
        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'))
189
225
 
190
226
        # Now that we have a repository with shared files, make sure
191
227
        # that things aren't copied out by a 'push'
192
228
        self.run_bzr('push ../../push-b', working_dir='repo/b')
193
229
        pushed_tree = workingtree.WorkingTree.open('push-b')
194
230
        pushed_repo = pushed_tree.branch.repository
195
 
        self.assertFalse(pushed_repo.has_revision('a-1'))
196
 
        self.assertFalse(pushed_repo.has_revision('a-2'))
197
 
        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'))
198
234
 
199
235
    def test_push_funky_id(self):
200
236
        t = self.make_branch_and_tree('tree')
201
237
        self.build_tree(['tree/filename'])
202
 
        t.add('filename', 'funky-chars<>%&;"\'')
 
238
        t.add('filename', b'funky-chars<>%&;"\'')
203
239
        t.commit('commit filename')
204
240
        self.run_bzr('push -d tree new-tree')
205
241
 
206
242
    def test_push_dash_d(self):
207
243
        t = self.make_branch_and_tree('from')
208
244
        t.commit(allow_pointless=True,
209
 
                message='first commit')
 
245
                 message='first commit')
210
246
        self.run_bzr('push -d from to-one')
211
 
        self.failUnlessExists('to-one')
 
247
        self.assertPathExists('to-one')
212
248
        self.run_bzr('push -d %s %s'
213
 
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
 
        self.failUnlessExists('to-two')
 
249
                     % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
 
250
        self.assertPathExists('to-two')
 
251
 
 
252
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
 
253
        # See https://bugs.launchpad.net/bzr/+bug/465517
 
254
        target_repo = self.make_repository('target')
 
255
        source = self.make_branch_builder('source')
 
256
        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')
 
262
        source.finish_series()
 
263
        self.run_bzr('push target -d source')
 
264
        self.addCleanup(target_repo.lock_read().unlock)
 
265
        # We should have pushed 'C', but not 'B', since it isn't in the
 
266
        # ancestry
 
267
        self.assertEqual([(b'A',), (b'C',)], sorted(
 
268
            target_repo.revisions.keys()))
215
269
 
216
270
    def test_push_smart_non_stacked_streaming_acceptance(self):
217
271
        self.setup_smart_server_with_call_log()
225
279
        # become necessary for this use case. Please do not adjust this number
226
280
        # upwards without agreement from bzr's network support maintainers.
227
281
        self.assertLength(9, self.hpss_calls)
 
282
        self.assertLength(1, self.hpss_connections)
 
283
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
228
284
 
229
285
    def test_push_smart_stacked_streaming_acceptance(self):
230
286
        self.setup_smart_server_with_call_log()
231
287
        parent = self.make_branch_and_tree('parent', format='1.9')
232
288
        parent.commit(message='first commit')
233
 
        local = parent.bzrdir.sprout('local').open_workingtree()
 
289
        local = parent.controldir.sprout('local').open_workingtree()
234
290
        local.commit(message='local commit')
235
291
        self.reset_smart_call_log()
236
292
        self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
237
 
            self.get_url('public')], working_dir='local')
 
293
                      self.get_url('public')], working_dir='local')
238
294
        # This figure represent the amount of work to perform this use case. It
239
295
        # is entirely ok to reduce this number if a test fails due to rpc_count
240
296
        # being too low. If rpc_count increases, more network roundtrips have
241
297
        # become necessary for this use case. Please do not adjust this number
242
298
        # upwards without agreement from bzr's network support maintainers.
243
 
        self.assertLength(14, self.hpss_calls)
 
299
        self.assertLength(15, self.hpss_calls)
 
300
        self.assertLength(1, self.hpss_connections)
 
301
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
302
        remote = branch.Branch.open('public')
245
303
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
304
 
257
315
        # become necessary for this use case. Please do not adjust this number
258
316
        # upwards without agreement from bzr's network support maintainers.
259
317
        self.assertLength(11, self.hpss_calls)
 
318
        self.assertLength(1, self.hpss_connections)
 
319
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
260
320
 
261
321
    def test_push_smart_incremental_acceptance(self):
262
322
        self.setup_smart_server_with_call_log()
273
333
        # become necessary for this use case. Please do not adjust this number
274
334
        # upwards without agreement from bzr's network support maintainers.
275
335
        self.assertLength(11, self.hpss_calls)
 
336
        self.assertLength(1, self.hpss_connections)
 
337
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
276
338
 
277
339
    def test_push_smart_with_default_stacking_url_path_segment(self):
278
340
        # If the default stacked-on location is a path element then branches
280
342
        # stacked_on_url is that exact path segment. Added to nail bug 385132.
281
343
        self.setup_smart_server_with_call_log()
282
344
        self.make_branch('stack-on', format='1.9')
283
 
        self.make_bzrdir('.').get_config().set_default_stack_on(
 
345
        self.make_controldir('.').get_config().set_default_stack_on(
284
346
            '/stack-on')
285
347
        self.make_branch('from', format='1.9')
286
348
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
293
355
        # stacked_on_url is a relative path. Added to nail bug 385132.
294
356
        self.setup_smart_server_with_call_log()
295
357
        self.make_branch('stack-on', format='1.9')
296
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
 
358
        self.make_controldir('.').get_config().set_default_stack_on('stack-on')
297
359
        self.make_branch('from', format='1.9')
298
360
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
299
361
        b = branch.Branch.open(self.get_url('to'))
302
364
    def create_simple_tree(self):
303
365
        tree = self.make_branch_and_tree('tree')
304
366
        self.build_tree(['tree/a'])
305
 
        tree.add(['a'], ['a-id'])
306
 
        tree.commit('one', rev_id='r1')
 
367
        tree.add(['a'], [b'a-id'])
 
368
        tree.commit('one', rev_id=b'r1')
307
369
        return tree
308
370
 
309
371
    def test_push_create_prefix(self):
310
 
        """'bzr push --create-prefix' will create leading directories."""
 
372
        """'brz push --create-prefix' will create leading directories."""
311
373
        tree = self.create_simple_tree()
312
374
 
313
375
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
317
379
                     working_dir='tree')
318
380
        new_tree = workingtree.WorkingTree.open('new/tree')
319
381
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
 
        self.failUnlessExists('new/tree/a')
 
382
        self.assertPathExists('new/tree/a')
321
383
 
322
384
    def test_push_use_existing(self):
323
 
        """'bzr push --use-existing-dir' can push into an existing dir.
 
385
        """'brz push --use-existing-dir' can push into an existing dir.
324
386
 
325
 
        By default, 'bzr push' will not use an existing, non-versioned dir.
 
387
        By default, 'brz push' will not use an existing, non-versioned dir.
326
388
        """
327
389
        tree = self.create_simple_tree()
328
390
        self.build_tree(['target/'])
329
391
 
330
392
        self.run_bzr_error(['Target directory ../target already exists',
331
393
                            'Supply --use-existing-dir',
332
 
                           ],
 
394
                            ],
333
395
                           'push ../target', working_dir='tree')
334
396
 
335
397
        self.run_bzr('push --use-existing-dir ../target',
338
400
        new_tree = workingtree.WorkingTree.open('target')
339
401
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
402
        # The push should have created target/a
341
 
        self.failUnlessExists('target/a')
 
403
        self.assertPathExists('target/a')
342
404
 
343
405
    def test_push_use_existing_into_empty_bzrdir(self):
344
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
 
406
        """'brz push --use-existing-dir' into a dir with an empty .bzr dir
345
407
        fails.
346
408
        """
347
409
        tree = self.create_simple_tree()
352
414
            'push ../target --use-existing-dir', working_dir='tree')
353
415
 
354
416
    def test_push_onto_repo(self):
355
 
        """We should be able to 'bzr push' into an existing bzrdir."""
 
417
        """We should be able to 'brz push' into an existing bzrdir."""
356
418
        tree = self.create_simple_tree()
357
419
        repo = self.make_repository('repo', shared=True)
358
420
 
375
437
        # TODO: jam 20070109 Maybe it would be better to create the repository
376
438
        #       if at this point
377
439
        tree = self.create_simple_tree()
378
 
        a_bzrdir = self.make_bzrdir('dir')
 
440
        a_controldir = self.make_controldir('dir')
379
441
 
380
442
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
381
 
                'push ../dir',
382
 
                working_dir='tree')
 
443
                           'push ../dir',
 
444
                           working_dir='tree')
383
445
 
384
446
    def test_push_with_revisionspec(self):
385
447
        """We should be able to push a revision older than the tip."""
386
448
        tree_from = self.make_branch_and_tree('from')
387
 
        tree_from.commit("One.", rev_id="from-1")
388
 
        tree_from.commit("Two.", rev_id="from-2")
 
449
        tree_from.commit("One.", rev_id=b"from-1")
 
450
        tree_from.commit("Two.", rev_id=b"from-2")
389
451
 
390
452
        self.run_bzr('push -r1 ../to', working_dir='from')
391
453
 
392
454
        tree_to = workingtree.WorkingTree.open('to')
393
455
        repo_to = tree_to.branch.repository
394
 
        self.assertTrue(repo_to.has_revision('from-1'))
395
 
        self.assertFalse(repo_to.has_revision('from-2'))
396
 
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
 
456
        self.assertTrue(repo_to.has_revision(b'from-1'))
 
457
        self.assertFalse(repo_to.has_revision(b'from-2'))
 
458
        self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
 
459
        self.assertFalse(
 
460
            tree_to.changes_from(tree_to.basis_tree()).has_changed())
397
461
 
398
462
        self.run_bzr_error(
399
 
            ['bzr: ERROR: bzr push --revision '
 
463
            ['brz: ERROR: brz push --revision '
400
464
             'takes exactly one revision identifier\n'],
401
465
            'push -r0..2 ../to', working_dir='from')
402
466
 
403
467
    def create_trunk_and_feature_branch(self):
404
468
        # We have a mainline
405
469
        trunk_tree = self.make_branch_and_tree('target',
406
 
            format='1.9')
 
470
                                               format='1.9')
407
471
        trunk_tree.commit('mainline')
408
472
        # and a branch from it
409
473
        branch_tree = self.make_branch_and_tree('branch',
410
 
            format='1.9')
 
474
                                                format='1.9')
411
475
        branch_tree.pull(trunk_tree.branch)
412
476
        branch_tree.branch.set_parent(trunk_tree.branch.base)
413
477
        # with some work on it
427
491
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
428
492
        # we publish branch_tree with a reference to the mainline.
429
493
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
430
 
            self.get_url('published')], working_dir='branch')
 
494
                                 self.get_url('published')], working_dir='branch')
431
495
        self.assertEqual('', out)
432
496
        self.assertEqual('Created new stacked branch referring to %s.\n' %
433
 
            trunk_tree.branch.base, err)
 
497
                         trunk_tree.branch.base, err)
434
498
        self.assertPublished(branch_tree.last_revision(),
435
 
            trunk_tree.branch.base)
 
499
                             trunk_tree.branch.base)
436
500
 
437
501
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
438
502
        """When the parent has no public url the parent is used as-is."""
440
504
        # now we do a stacked push, which should determine the public location
441
505
        # for us.
442
506
        out, err = self.run_bzr(['push', '--stacked',
443
 
            self.get_url('published')], working_dir='branch')
 
507
                                 self.get_url('published')], working_dir='branch')
444
508
        self.assertEqual('', out)
445
509
        self.assertEqual('Created new stacked branch referring to %s.\n' %
446
 
            trunk_tree.branch.base, err)
 
510
                         trunk_tree.branch.base, err)
447
511
        self.assertPublished(branch_tree.last_revision(),
448
512
                             trunk_tree.branch.base)
449
513
 
455
519
        trunk_public = self.make_branch('public_trunk', format='1.9')
456
520
        trunk_public.pull(trunk_tree.branch)
457
521
        trunk_public_url = self.get_readonly_url('public_trunk')
458
 
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
522
        br = trunk_tree.branch
 
523
        br.set_public_branch(trunk_public_url)
459
524
        # now we do a stacked push, which should determine the public location
460
525
        # for us.
461
526
        out, err = self.run_bzr(['push', '--stacked',
462
 
            self.get_url('published')], working_dir='branch')
 
527
                                 self.get_url('published')], working_dir='branch')
463
528
        self.assertEqual('', out)
464
529
        self.assertEqual('Created new stacked branch referring to %s.\n' %
465
 
            trunk_public_url, err)
 
530
                         trunk_public_url, err)
466
531
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
467
532
 
468
533
    def test_push_new_branch_stacked_no_parent(self):
472
537
        # cannot be determined.
473
538
        out, err = self.run_bzr_error(
474
539
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
475
 
            self.get_url('published')], working_dir='branch')
 
540
                                                            self.get_url('published')], working_dir='branch')
476
541
        self.assertEqual('', out)
477
542
        self.assertFalse(self.get_transport('published').has('.'))
478
543
 
479
544
    def test_push_notifies_default_stacking(self):
480
545
        self.make_branch('stack_on', format='1.6')
481
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
546
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
482
547
        self.make_branch('from', format='1.6')
483
548
        out, err = self.run_bzr('push -d from to')
484
549
        self.assertContainsRe(err,
486
551
 
487
552
    def test_push_stacks_with_default_stacking_if_target_is_stackable(self):
488
553
        self.make_branch('stack_on', format='1.6')
489
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
554
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
490
555
        self.make_branch('from', format='pack-0.92')
491
556
        out, err = self.run_bzr('push -d from to')
492
557
        b = branch.Branch.open('to')
494
559
 
495
560
    def test_push_does_not_change_format_with_default_if_target_cannot(self):
496
561
        self.make_branch('stack_on', format='pack-0.92')
497
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
562
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
498
563
        self.make_branch('from', format='pack-0.92')
499
564
        out, err = self.run_bzr('push -d from to')
500
565
        b = branch.Branch.open('to')
501
 
        self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
 
566
        self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
502
567
 
503
568
    def test_push_doesnt_create_broken_branch(self):
504
569
        """Pushing a new standalone branch works even when there's a default
511
576
        self.make_repository('repo', shared=True, format='1.6')
512
577
        builder = self.make_branch_builder('repo/local', format='pack-0.92')
513
578
        builder.start_series()
514
 
        builder.build_snapshot('rev-1', None, [
515
 
            ('add', ('', 'root-id', 'directory', '')),
516
 
            ('add', ('filename', 'f-id', 'file', 'content\n'))])
517
 
        builder.build_snapshot('rev-2', ['rev-1'], [])
518
 
        builder.build_snapshot('rev-3', ['rev-2'],
519
 
            [('modify', ('f-id', 'new-content\n'))])
 
579
        builder.build_snapshot(None, [
 
580
            ('add', ('', b'root-id', 'directory', '')),
 
581
            ('add', ('filename', b'f-id', 'file', b'content\n'))],
 
582
            revision_id=b'rev-1')
 
583
        builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
 
584
        builder.build_snapshot([b'rev-2'],
 
585
                               [('modify', ('filename', b'new-content\n'))],
 
586
                               revision_id=b'rev-3')
520
587
        builder.finish_series()
521
588
        branch = builder.get_branch()
522
589
        # Push rev-1 to "trunk", so that we can stack on it.
523
590
        self.run_bzr('push -d repo/local trunk -r 1')
524
591
        # Set a default stacking policy so that new branches will automatically
525
592
        # stack on trunk.
526
 
        self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
 
593
        self.make_controldir('.').get_config().set_default_stack_on('trunk')
527
594
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
528
595
        out, err = self.run_bzr('push -d repo/local remote -r 2')
529
596
        self.assertContainsRe(
548
615
    def test_push_from_subdir(self):
549
616
        t = self.make_branch_and_tree('tree')
550
617
        self.build_tree(['tree/dir/', 'tree/dir/file'])
551
 
        t.add('dir', 'dir/file')
 
618
        t.add(['dir', 'dir/file'])
552
619
        t.commit('r1')
553
620
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
554
621
        self.assertEqual('', out)
555
622
        self.assertEqual('Created new branch.\n', err)
556
623
 
 
624
    def test_overwrite_tags(self):
 
625
        """--overwrite-tags only overwrites tags, not revisions."""
 
626
        from_tree = self.make_branch_and_tree('from')
 
627
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
 
628
        to_tree = self.make_branch_and_tree('to')
 
629
        to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
 
630
        revid1 = to_tree.commit('my commit')
 
631
        out = self.run_bzr(['push', '-d', 'from', 'to'])
 
632
        self.assertEqual(out,
 
633
                         ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
634
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
 
635
        self.assertEqual(out, ('', '1 tag updated.\n'))
 
636
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
 
637
                         b'somerevid')
 
638
        self.assertEqual(to_tree.branch.last_revision(), revid1)
 
639
 
557
640
 
558
641
class RedirectingMemoryTransport(memory.MemoryTransport):
559
642
 
606
689
class TestPushRedirect(tests.TestCaseWithTransport):
607
690
 
608
691
    def setUp(self):
609
 
        tests.TestCaseWithTransport.setUp(self)
 
692
        super(TestPushRedirect, self).setUp()
610
693
        self.memory_server = RedirectingMemoryServer()
611
694
        self.start_server(self.memory_server)
612
695
        # Make the branch and tree that we'll be pushing.
645
728
 
646
729
    def make_local_branch_and_tree(self):
647
730
        self.tree = self.make_branch_and_tree('local')
648
 
        self.build_tree_contents([('local/file', 'initial')])
 
731
        self.build_tree_contents([('local/file', b'initial')])
649
732
        self.tree.add('file')
650
 
        self.tree.commit('adding file', rev_id='added')
651
 
        self.build_tree_contents([('local/file', 'modified')])
652
 
        self.tree.commit('modify file', rev_id='modified')
 
733
        self.tree.commit('adding file', rev_id=b'added')
 
734
        self.build_tree_contents([('local/file', b'modified')])
 
735
        self.tree.commit('modify file', rev_id=b'modified')
653
736
 
654
737
    def set_config_push_strict(self, value):
655
 
        # set config var (any of bazaar.conf, locations.conf, branch.conf
656
 
        # should do)
657
 
        conf = self.tree.branch.get_config()
658
 
        conf.set_user_option('push_strict', value)
 
738
        br = branch.Branch.open('local')
 
739
        br.get_config_stack().set('push_strict', value)
659
740
 
660
741
    _default_command = ['push', '../to']
661
742
    _default_wd = 'local'
662
743
    _default_errors = ['Working tree ".*/local/" has uncommitted '
663
 
                       'changes \(See bzr status\)\.',]
 
744
                       'changes \\(See brz status\\)\\.', ]
664
745
    _default_additional_error = 'Use --no-strict to force the push.\n'
665
746
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
666
747
 
667
 
 
668
748
    def assertPushFails(self, args):
669
749
        out, err = self.run_bzr_error(self._default_errors,
670
750
                                      self._default_command + args,
692
772
        self.assertEqual(revid_to_push, branch_to.last_revision())
693
773
 
694
774
 
695
 
 
696
775
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
697
776
                                   TestPushStrictMixin):
698
777
 
718
797
        self.assertPushSucceeds([])
719
798
 
720
799
 
 
800
strict_push_change_scenarios = [
 
801
    ('uncommitted',
 
802
        dict(_changes_type='_uncommitted_changes')),
 
803
    ('pending-merges',
 
804
        dict(_changes_type='_pending_merges')),
 
805
    ('out-of-sync-trees',
 
806
        dict(_changes_type='_out_of_sync_trees')),
 
807
    ]
 
808
 
 
809
 
721
810
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
811
                                TestPushStrictMixin):
723
812
 
724
 
    _changes_type = None # Set by load_tests
 
813
    scenarios = strict_push_change_scenarios
 
814
    _changes_type = None  # Set by load_tests
725
815
 
726
816
    def setUp(self):
727
817
        super(TestPushStrictWithChanges, self).setUp()
732
822
    def _uncommitted_changes(self):
733
823
        self.make_local_branch_and_tree()
734
824
        # Make a change without committing it
735
 
        self.build_tree_contents([('local/file', 'in progress')])
 
825
        self.build_tree_contents([('local/file', b'in progress')])
736
826
 
737
827
    def _pending_merges(self):
738
828
        self.make_local_branch_and_tree()
739
829
        # Create 'other' branch containing a new file
740
 
        other_bzrdir = self.tree.bzrdir.sprout('other')
 
830
        other_bzrdir = self.tree.controldir.sprout('other')
741
831
        other_tree = other_bzrdir.open_workingtree()
742
 
        self.build_tree_contents([('other/other-file', 'other')])
 
832
        self.build_tree_contents([('other/other-file', b'other')])
743
833
        other_tree.add('other-file')
744
 
        other_tree.commit('other commit', rev_id='other')
 
834
        other_tree.commit('other commit', rev_id=b'other')
745
835
        # Merge and revert, leaving a pending merge
746
836
        self.tree.merge_from_branch(other_tree.branch)
747
837
        self.tree.revert(filenames=['other-file'], backups=False)
750
840
        self.make_local_branch_and_tree()
751
841
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
752
842
        # Make a change and commit it
753
 
        self.build_tree_contents([('local/file', 'modified in local')])
754
 
        self.tree.commit('modify file', rev_id='modified-in-local')
 
843
        self.build_tree_contents([('local/file', b'modified in local')])
 
844
        self.tree.commit('modify file', rev_id=b'modified-in-local')
755
845
        # Exercise commands from the checkout directory
756
846
        self._default_wd = 'checkout'
757
847
        self._default_errors = ["Working tree is out of date, please run"
758
 
                                " 'bzr update'\.",]
 
848
                                " 'brz update'\\.", ]
759
849
 
760
850
    def test_push_default(self):
761
851
        self.assertPushSucceeds([], with_warning=True)
762
852
 
763
853
    def test_push_with_revision(self):
764
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
854
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
765
855
 
766
856
    def test_push_no_strict(self):
767
857
        self.assertPushSucceeds(['--no-strict'])
788
878
        self.assertPushSucceeds([])
789
879
 
790
880
 
791
 
class TestPushForeign(blackbox.ExternalBase):
 
881
class TestPushForeign(tests.TestCaseWithTransport):
792
882
 
793
883
    def setUp(self):
794
884
        super(TestPushForeign, self).setUp()
797
887
    def make_dummy_builder(self, relpath):
798
888
        builder = self.make_branch_builder(
799
889
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
 
        builder.build_snapshot('revid', None,
801
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
802
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
 
890
        builder.build_snapshot(None,
 
891
                               [('add', ('', b'TREE_ROOT', 'directory', None)),
 
892
                                ('add', ('foo', b'fooid', 'file', b'bar'))],
 
893
                               revision_id=b'revid')
803
894
        return builder
804
895
 
805
896
    def test_no_roundtripping(self):
806
897
        target_branch = self.make_dummy_builder('dp').get_branch()
807
898
        source_tree = self.make_branch_and_tree("dc")
808
899
        output, error = self.run_bzr("push -d dc dp", retcode=3)
809
 
        self.assertEquals("", output)
810
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
 
            " push to dummy. You may want to use dpush instead.\n")
 
900
        self.assertEqual("", output)
 
901
        self.assertEqual(
 
902
            error,
 
903
            "brz: ERROR: It is not possible to losslessly"
 
904
            " push to dummy. You may want to use --lossy.\n")
 
905
 
 
906
 
 
907
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
908
 
 
909
    def test_push_log_format(self):
 
910
        self.run_script("""
 
911
            $ brz init trunk
 
912
            Created a standalone tree (format: 2a)
 
913
            $ cd trunk
 
914
            $ echo foo > file
 
915
            $ brz add
 
916
            adding file
 
917
            $ brz commit -m 'we need some foo'
 
918
            2>Committing to:...trunk/
 
919
            2>added file
 
920
            2>Committed revision 1.
 
921
            $ brz init ../feature
 
922
            Created a standalone tree (format: 2a)
 
923
            $ brz push -v ../feature -Olog_format=line
 
924
            Added Revisions:
 
925
            1: jrandom@example.com ...we need some foo
 
926
            2>All changes applied successfully.
 
927
            2>Pushed up to revision 1.
 
928
            """)
 
929
 
 
930
    def test_push_with_revspec(self):
 
931
        self.run_script("""
 
932
            $ brz init-repo .
 
933
            Shared repository with trees (format: 2a)
 
934
            Location:
 
935
              shared repository: .
 
936
            $ brz init trunk
 
937
            Created a repository tree (format: 2a)
 
938
            Using shared repository...
 
939
            $ cd trunk
 
940
            $ brz commit -m 'first rev' --unchanged
 
941
            2>Committing to:...trunk/
 
942
            2>Committed revision 1.
 
943
            $ echo foo > file
 
944
            $ brz add
 
945
            adding file
 
946
            $ brz commit -m 'we need some foo'
 
947
            2>Committing to:...trunk/
 
948
            2>added file
 
949
            2>Committed revision 2.
 
950
            $ brz push -r 1 ../other
 
951
            2>Created new branch.
 
952
            $ brz st ../other # checking that file is not created (#484516)
 
953
            """)