/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: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

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):
72
55
        self.transport_readonly_server = http_server.HttpServer
73
56
        self.make_branch('source')
74
57
        public_url = self.get_readonly_url('target')
75
 
        self.run_bzr_error(['http does not support mkdir'],
 
58
        self.run_bzr_error([b'http does not support mkdir'],
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
                (b'', b'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
            (b'', b'brz: ERROR: No push location known or specified. '
 
78
                b'To push to the parent branch '
 
79
                b'(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'),
 
112
        self.assertEqual(
 
113
                ('', 'brz: ERROR: No push location known or specified.\n'),
111
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
 
        self.assertEqual('', out)
145
 
        self.assertEqual('Created new branch.\n', err)
 
152
        self.assertEqual(b'', out)
 
153
        self.assertEqual(b'Created new branch.\n', err)
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(b'', out)
 
165
        self.assertEqual(b'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')
155
174
        t.add('file')
156
175
        t.commit('commit 1')
157
176
        out, err = self.run_bzr('push -d tree pushed-to')
158
 
        self.assertEqual('', out)
159
 
        self.assertEqual('Created new branch.\n', err)
 
177
        self.assertEqual(b'', out)
 
178
        self.assertEqual(b'Created new branch.\n', err)
 
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(b'', out)
 
195
        self.assertEqual(b'', err)
160
196
 
161
197
    def test_push_only_pushes_history(self):
162
198
        # Knit branches should only push the history for the current revision.
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')
208
244
        t.commit(allow_pointless=True,
209
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
249
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
 
        self.failUnlessExists('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(target_repo.revisions.keys()))
215
268
 
216
269
    def test_push_smart_non_stacked_streaming_acceptance(self):
217
270
        self.setup_smart_server_with_call_log()
225
278
        # become necessary for this use case. Please do not adjust this number
226
279
        # upwards without agreement from bzr's network support maintainers.
227
280
        self.assertLength(9, self.hpss_calls)
 
281
        self.assertLength(1, self.hpss_connections)
 
282
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
228
283
 
229
284
    def test_push_smart_stacked_streaming_acceptance(self):
230
285
        self.setup_smart_server_with_call_log()
231
286
        parent = self.make_branch_and_tree('parent', format='1.9')
232
287
        parent.commit(message='first commit')
233
 
        local = parent.bzrdir.sprout('local').open_workingtree()
 
288
        local = parent.controldir.sprout('local').open_workingtree()
234
289
        local.commit(message='local commit')
235
290
        self.reset_smart_call_log()
236
291
        self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
240
295
        # being too low. If rpc_count increases, more network roundtrips have
241
296
        # become necessary for this use case. Please do not adjust this number
242
297
        # upwards without agreement from bzr's network support maintainers.
243
 
        self.assertLength(14, self.hpss_calls)
 
298
        self.assertLength(15, self.hpss_calls)
 
299
        self.assertLength(1, self.hpss_connections)
 
300
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
301
        remote = branch.Branch.open('public')
245
302
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
246
303
 
257
314
        # become necessary for this use case. Please do not adjust this number
258
315
        # upwards without agreement from bzr's network support maintainers.
259
316
        self.assertLength(11, self.hpss_calls)
 
317
        self.assertLength(1, self.hpss_connections)
 
318
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
260
319
 
261
320
    def test_push_smart_incremental_acceptance(self):
262
321
        self.setup_smart_server_with_call_log()
273
332
        # become necessary for this use case. Please do not adjust this number
274
333
        # upwards without agreement from bzr's network support maintainers.
275
334
        self.assertLength(11, self.hpss_calls)
 
335
        self.assertLength(1, self.hpss_connections)
 
336
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
276
337
 
277
338
    def test_push_smart_with_default_stacking_url_path_segment(self):
278
339
        # If the default stacked-on location is a path element then branches
280
341
        # stacked_on_url is that exact path segment. Added to nail bug 385132.
281
342
        self.setup_smart_server_with_call_log()
282
343
        self.make_branch('stack-on', format='1.9')
283
 
        self.make_bzrdir('.').get_config().set_default_stack_on(
 
344
        self.make_controldir('.').get_config().set_default_stack_on(
284
345
            '/stack-on')
285
346
        self.make_branch('from', format='1.9')
286
347
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
293
354
        # stacked_on_url is a relative path. Added to nail bug 385132.
294
355
        self.setup_smart_server_with_call_log()
295
356
        self.make_branch('stack-on', format='1.9')
296
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
 
357
        self.make_controldir('.').get_config().set_default_stack_on('stack-on')
297
358
        self.make_branch('from', format='1.9')
298
359
        out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
299
360
        b = branch.Branch.open(self.get_url('to'))
302
363
    def create_simple_tree(self):
303
364
        tree = self.make_branch_and_tree('tree')
304
365
        self.build_tree(['tree/a'])
305
 
        tree.add(['a'], ['a-id'])
306
 
        tree.commit('one', rev_id='r1')
 
366
        tree.add(['a'], [b'a-id'])
 
367
        tree.commit('one', rev_id=b'r1')
307
368
        return tree
308
369
 
309
370
    def test_push_create_prefix(self):
310
 
        """'bzr push --create-prefix' will create leading directories."""
 
371
        """'brz push --create-prefix' will create leading directories."""
311
372
        tree = self.create_simple_tree()
312
373
 
313
 
        self.run_bzr_error(['Parent directory of ../new/tree does not exist'],
 
374
        self.run_bzr_error([b'Parent directory of ../new/tree does not exist'],
314
375
                           'push ../new/tree',
315
376
                           working_dir='tree')
316
377
        self.run_bzr('push ../new/tree --create-prefix',
317
378
                     working_dir='tree')
318
379
        new_tree = workingtree.WorkingTree.open('new/tree')
319
380
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
 
        self.failUnlessExists('new/tree/a')
 
381
        self.assertPathExists('new/tree/a')
321
382
 
322
383
    def test_push_use_existing(self):
323
 
        """'bzr push --use-existing-dir' can push into an existing dir.
 
384
        """'brz push --use-existing-dir' can push into an existing dir.
324
385
 
325
 
        By default, 'bzr push' will not use an existing, non-versioned dir.
 
386
        By default, 'brz push' will not use an existing, non-versioned dir.
326
387
        """
327
388
        tree = self.create_simple_tree()
328
389
        self.build_tree(['target/'])
329
390
 
330
 
        self.run_bzr_error(['Target directory ../target already exists',
331
 
                            'Supply --use-existing-dir',
 
391
        self.run_bzr_error([b'Target directory ../target already exists',
 
392
                            b'Supply --use-existing-dir',
332
393
                           ],
333
394
                           'push ../target', working_dir='tree')
334
395
 
338
399
        new_tree = workingtree.WorkingTree.open('target')
339
400
        self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
401
        # The push should have created target/a
341
 
        self.failUnlessExists('target/a')
 
402
        self.assertPathExists('target/a')
342
403
 
343
404
    def test_push_use_existing_into_empty_bzrdir(self):
344
 
        """'bzr push --use-existing-dir' into a dir with an empty .bzr dir
 
405
        """'brz push --use-existing-dir' into a dir with an empty .bzr dir
345
406
        fails.
346
407
        """
347
408
        tree = self.create_simple_tree()
352
413
            'push ../target --use-existing-dir', working_dir='tree')
353
414
 
354
415
    def test_push_onto_repo(self):
355
 
        """We should be able to 'bzr push' into an existing bzrdir."""
 
416
        """We should be able to 'brz push' into an existing bzrdir."""
356
417
        tree = self.create_simple_tree()
357
418
        repo = self.make_repository('repo', shared=True)
358
419
 
375
436
        # TODO: jam 20070109 Maybe it would be better to create the repository
376
437
        #       if at this point
377
438
        tree = self.create_simple_tree()
378
 
        a_bzrdir = self.make_bzrdir('dir')
 
439
        a_controldir = self.make_controldir('dir')
379
440
 
380
 
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
 
441
        self.run_bzr_error([b'At ../dir you have a valid .bzr control'],
381
442
                'push ../dir',
382
443
                working_dir='tree')
383
444
 
384
445
    def test_push_with_revisionspec(self):
385
446
        """We should be able to push a revision older than the tip."""
386
447
        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")
 
448
        tree_from.commit("One.", rev_id=b"from-1")
 
449
        tree_from.commit("Two.", rev_id=b"from-2")
389
450
 
390
451
        self.run_bzr('push -r1 ../to', working_dir='from')
391
452
 
392
453
        tree_to = workingtree.WorkingTree.open('to')
393
454
        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')
 
455
        self.assertTrue(repo_to.has_revision(b'from-1'))
 
456
        self.assertFalse(repo_to.has_revision(b'from-2'))
 
457
        self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
 
458
        self.assertFalse(
 
459
            tree_to.changes_from(tree_to.basis_tree()).has_changed())
397
460
 
398
461
        self.run_bzr_error(
399
 
            ['bzr: ERROR: bzr push --revision '
 
462
            ['brz: ERROR: brz push --revision '
400
463
             'takes exactly one revision identifier\n'],
401
464
            'push -r0..2 ../to', working_dir='from')
402
465
 
428
491
        # we publish branch_tree with a reference to the mainline.
429
492
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
430
493
            self.get_url('published')], working_dir='branch')
431
 
        self.assertEqual('', out)
432
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
494
        self.assertEqual(b'', out)
 
495
        self.assertEqual(b'Created new stacked branch referring to %s.\n' %
433
496
            trunk_tree.branch.base, err)
434
497
        self.assertPublished(branch_tree.last_revision(),
435
498
            trunk_tree.branch.base)
441
504
        # for us.
442
505
        out, err = self.run_bzr(['push', '--stacked',
443
506
            self.get_url('published')], working_dir='branch')
444
 
        self.assertEqual('', out)
445
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
507
        self.assertEqual(b'', out)
 
508
        self.assertEqual(b'Created new stacked branch referring to %s.\n' %
446
509
            trunk_tree.branch.base, err)
447
510
        self.assertPublished(branch_tree.last_revision(),
448
511
                             trunk_tree.branch.base)
455
518
        trunk_public = self.make_branch('public_trunk', format='1.9')
456
519
        trunk_public.pull(trunk_tree.branch)
457
520
        trunk_public_url = self.get_readonly_url('public_trunk')
458
 
        trunk_tree.branch.set_public_branch(trunk_public_url)
 
521
        br = trunk_tree.branch
 
522
        br.set_public_branch(trunk_public_url)
459
523
        # now we do a stacked push, which should determine the public location
460
524
        # for us.
461
525
        out, err = self.run_bzr(['push', '--stacked',
462
526
            self.get_url('published')], working_dir='branch')
463
 
        self.assertEqual('', out)
464
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
527
        self.assertEqual(b'', out)
 
528
        self.assertEqual(b'Created new stacked branch referring to %s.\n' %
465
529
            trunk_public_url, err)
466
530
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
467
531
 
473
537
        out, err = self.run_bzr_error(
474
538
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
475
539
            self.get_url('published')], working_dir='branch')
476
 
        self.assertEqual('', out)
 
540
        self.assertEqual(b'', out)
477
541
        self.assertFalse(self.get_transport('published').has('.'))
478
542
 
479
543
    def test_push_notifies_default_stacking(self):
480
544
        self.make_branch('stack_on', format='1.6')
481
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
545
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
482
546
        self.make_branch('from', format='1.6')
483
547
        out, err = self.run_bzr('push -d from to')
484
548
        self.assertContainsRe(err,
485
 
                              'Using default stacking branch stack_on at .*')
 
549
                              b'Using default stacking branch stack_on at .*')
486
550
 
487
551
    def test_push_stacks_with_default_stacking_if_target_is_stackable(self):
488
552
        self.make_branch('stack_on', format='1.6')
489
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
553
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
490
554
        self.make_branch('from', format='pack-0.92')
491
555
        out, err = self.run_bzr('push -d from to')
492
556
        b = branch.Branch.open('to')
494
558
 
495
559
    def test_push_does_not_change_format_with_default_if_target_cannot(self):
496
560
        self.make_branch('stack_on', format='pack-0.92')
497
 
        self.make_bzrdir('.').get_config().set_default_stack_on('stack_on')
 
561
        self.make_controldir('.').get_config().set_default_stack_on('stack_on')
498
562
        self.make_branch('from', format='pack-0.92')
499
563
        out, err = self.run_bzr('push -d from to')
500
564
        b = branch.Branch.open('to')
501
 
        self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
 
565
        self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
502
566
 
503
567
    def test_push_doesnt_create_broken_branch(self):
504
568
        """Pushing a new standalone branch works even when there's a default
511
575
        self.make_repository('repo', shared=True, format='1.6')
512
576
        builder = self.make_branch_builder('repo/local', format='pack-0.92')
513
577
        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'))])
 
578
        builder.build_snapshot(None, [
 
579
            ('add', ('', b'root-id', 'directory', '')),
 
580
            ('add', ('filename', b'f-id', 'file', 'content\n'))],
 
581
            revision_id=b'rev-1')
 
582
        builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
 
583
        builder.build_snapshot([b'rev-2'],
 
584
            [('modify', ('filename', b'new-content\n'))],
 
585
            revision_id=b'rev-3')
520
586
        builder.finish_series()
521
587
        branch = builder.get_branch()
522
588
        # Push rev-1 to "trunk", so that we can stack on it.
523
589
        self.run_bzr('push -d repo/local trunk -r 1')
524
590
        # Set a default stacking policy so that new branches will automatically
525
591
        # stack on trunk.
526
 
        self.make_bzrdir('.').get_config().set_default_stack_on('trunk')
 
592
        self.make_controldir('.').get_config().set_default_stack_on('trunk')
527
593
        # Push rev-2 to a new branch "remote".  It will be stacked on "trunk".
528
594
        out, err = self.run_bzr('push -d repo/local remote -r 2')
529
595
        self.assertContainsRe(
530
 
            err, 'Using default stacking branch trunk at .*')
 
596
            err, b'Using default stacking branch trunk at .*')
531
597
        # Push rev-3 onto "remote".  If "remote" not stacked and is missing the
532
598
        # fulltext record for f-id @ rev-1, then this will fail.
533
599
        out, err = self.run_bzr('push -d repo/local remote -r 3')
537
603
        tree.commit('rev1')
538
604
        out, err = self.run_bzr('push -v -d source target')
539
605
        # initial push contains log
540
 
        self.assertContainsRe(out, 'rev1')
 
606
        self.assertContainsRe(out, b'rev1')
541
607
        tree.commit('rev2')
542
608
        out, err = self.run_bzr('push -v -d source target')
543
609
        # subsequent push contains log
544
 
        self.assertContainsRe(out, 'rev2')
 
610
        self.assertContainsRe(out, b'rev2')
545
611
        # subsequent log is accurate
546
 
        self.assertNotContainsRe(out, 'rev1')
 
612
        self.assertNotContainsRe(out, b'rev1')
547
613
 
548
614
    def test_push_from_subdir(self):
549
615
        t = self.make_branch_and_tree('tree')
550
616
        self.build_tree(['tree/dir/', 'tree/dir/file'])
551
 
        t.add('dir', 'dir/file')
 
617
        t.add(['dir', 'dir/file'])
552
618
        t.commit('r1')
553
619
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
554
 
        self.assertEqual('', out)
555
 
        self.assertEqual('Created new branch.\n', err)
 
620
        self.assertEqual(b'', out)
 
621
        self.assertEqual(b'Created new branch.\n', err)
 
622
 
 
623
    def test_overwrite_tags(self):
 
624
        """--overwrite-tags only overwrites tags, not revisions."""
 
625
        from_tree = self.make_branch_and_tree('from')
 
626
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
627
        to_tree = self.make_branch_and_tree('to')
 
628
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
629
        revid1 = to_tree.commit('my commit')
 
630
        out = self.run_bzr(['push', '-d', 'from', 'to'])
 
631
        self.assertEqual(out,
 
632
            ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
633
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
 
634
        self.assertEqual(out, ('', '1 tag updated.\n'))
 
635
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
 
636
                          'somerevid')
 
637
        self.assertEqual(to_tree.branch.last_revision(), revid1)
556
638
 
557
639
 
558
640
class RedirectingMemoryTransport(memory.MemoryTransport):
606
688
class TestPushRedirect(tests.TestCaseWithTransport):
607
689
 
608
690
    def setUp(self):
609
 
        tests.TestCaseWithTransport.setUp(self)
 
691
        super(TestPushRedirect, self).setUp()
610
692
        self.memory_server = RedirectingMemoryServer()
611
693
        self.start_server(self.memory_server)
612
694
        # Make the branch and tree that we'll be pushing.
638
720
            ['Too many redirections trying to make %s\\.\n'
639
721
             % re.escape(destination_url)],
640
722
            ['push', '-d', 'tree', destination_url], retcode=3)
641
 
        self.assertEqual('', out)
 
723
        self.assertEqual(b'', out)
642
724
 
643
725
 
644
726
class TestPushStrictMixin(object):
645
727
 
646
728
    def make_local_branch_and_tree(self):
647
729
        self.tree = self.make_branch_and_tree('local')
648
 
        self.build_tree_contents([('local/file', 'initial')])
 
730
        self.build_tree_contents([('local/file', b'initial')])
649
731
        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')
 
732
        self.tree.commit('adding file', rev_id=b'added')
 
733
        self.build_tree_contents([('local/file', b'modified')])
 
734
        self.tree.commit('modify file', rev_id=b'modified')
653
735
 
654
736
    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)
 
737
        br = branch.Branch.open('local')
 
738
        br.get_config_stack().set('push_strict', value)
659
739
 
660
740
    _default_command = ['push', '../to']
661
741
    _default_wd = 'local'
662
 
    _default_errors = ['Working tree ".*/local/" has uncommitted '
663
 
                       'changes \(See bzr status\)\.',]
664
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
665
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
 
742
    _default_errors = [b'Working tree ".*/local/" has uncommitted '
 
743
                       b'changes \\(See brz status\\)\\.',]
 
744
    _default_additional_error = b'Use --no-strict to force the push.\n'
 
745
    _default_additional_warning = b'Uncommitted changes will not be pushed.'
666
746
 
667
747
 
668
748
    def assertPushFails(self, args):
718
798
        self.assertPushSucceeds([])
719
799
 
720
800
 
 
801
strict_push_change_scenarios = [
 
802
    ('uncommitted',
 
803
        dict(_changes_type= '_uncommitted_changes')),
 
804
    ('pending-merges',
 
805
        dict(_changes_type= '_pending_merges')),
 
806
    ('out-of-sync-trees',
 
807
        dict(_changes_type= '_out_of_sync_trees')),
 
808
    ]
 
809
 
 
810
 
721
811
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
812
                                TestPushStrictMixin):
723
813
 
 
814
    scenarios = strict_push_change_scenarios 
724
815
    _changes_type = None # Set by load_tests
725
816
 
726
817
    def setUp(self):
732
823
    def _uncommitted_changes(self):
733
824
        self.make_local_branch_and_tree()
734
825
        # Make a change without committing it
735
 
        self.build_tree_contents([('local/file', 'in progress')])
 
826
        self.build_tree_contents([('local/file', b'in progress')])
736
827
 
737
828
    def _pending_merges(self):
738
829
        self.make_local_branch_and_tree()
739
830
        # Create 'other' branch containing a new file
740
 
        other_bzrdir = self.tree.bzrdir.sprout('other')
 
831
        other_bzrdir = self.tree.controldir.sprout('other')
741
832
        other_tree = other_bzrdir.open_workingtree()
742
 
        self.build_tree_contents([('other/other-file', 'other')])
 
833
        self.build_tree_contents([('other/other-file', b'other')])
743
834
        other_tree.add('other-file')
744
 
        other_tree.commit('other commit', rev_id='other')
 
835
        other_tree.commit('other commit', rev_id=b'other')
745
836
        # Merge and revert, leaving a pending merge
746
837
        self.tree.merge_from_branch(other_tree.branch)
747
838
        self.tree.revert(filenames=['other-file'], backups=False)
750
841
        self.make_local_branch_and_tree()
751
842
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
752
843
        # 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')
 
844
        self.build_tree_contents([('local/file', b'modified in local')])
 
845
        self.tree.commit('modify file', rev_id=b'modified-in-local')
755
846
        # Exercise commands from the checkout directory
756
847
        self._default_wd = 'checkout'
757
848
        self._default_errors = ["Working tree is out of date, please run"
758
 
                                " 'bzr update'\.",]
 
849
                                " 'brz update'\\.",]
759
850
 
760
851
    def test_push_default(self):
761
852
        self.assertPushSucceeds([], with_warning=True)
788
879
        self.assertPushSucceeds([])
789
880
 
790
881
 
791
 
class TestPushForeign(blackbox.ExternalBase):
 
882
class TestPushForeign(tests.TestCaseWithTransport):
792
883
 
793
884
    def setUp(self):
794
885
        super(TestPushForeign, self).setUp()
797
888
    def make_dummy_builder(self, relpath):
798
889
        builder = self.make_branch_builder(
799
890
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
 
        builder.build_snapshot('revid', None,
801
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
802
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
 
891
        builder.build_snapshot(None,
 
892
            [('add', ('', b'TREE_ROOT', 'directory', None)),
 
893
             ('add', ('foo', b'fooid', 'file', 'bar'))],
 
894
            revision_id=b'revid')
803
895
        return builder
804
896
 
805
897
    def test_no_roundtripping(self):
806
898
        target_branch = self.make_dummy_builder('dp').get_branch()
807
899
        source_tree = self.make_branch_and_tree("dc")
808
900
        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"
 
901
        self.assertEqual("", output)
 
902
        self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
811
903
            " push to dummy. You may want to use dpush instead.\n")
 
904
 
 
905
 
 
906
class TestPushOutput(script.TestCaseWithTransportAndScript):
 
907
 
 
908
    def test_push_log_format(self):
 
909
        self.run_script("""
 
910
            $ brz init trunk
 
911
            Created a standalone tree (format: 2a)
 
912
            $ cd trunk
 
913
            $ echo foo > file
 
914
            $ brz add
 
915
            adding file
 
916
            $ brz commit -m 'we need some foo'
 
917
            2>Committing to:...trunk/
 
918
            2>added file
 
919
            2>Committed revision 1.
 
920
            $ brz init ../feature
 
921
            Created a standalone tree (format: 2a)
 
922
            $ brz push -v ../feature -Olog_format=line
 
923
            Added Revisions:
 
924
            1: jrandom@example.com ...we need some foo
 
925
            2>All changes applied successfully.
 
926
            2>Pushed up to revision 1.
 
927
            """)
 
928
 
 
929
    def test_push_with_revspec(self):
 
930
        self.run_script("""
 
931
            $ brz init-repo .
 
932
            Shared repository with trees (format: 2a)
 
933
            Location:
 
934
              shared repository: .
 
935
            $ brz init trunk
 
936
            Created a repository tree (format: 2a)
 
937
            Using shared repository...
 
938
            $ cd trunk
 
939
            $ brz commit -m 'first rev' --unchanged
 
940
            2>Committing to:...trunk/
 
941
            2>Committed revision 1.
 
942
            $ echo foo > file
 
943
            $ brz add
 
944
            adding file
 
945
            $ brz commit -m 'we need some foo'
 
946
            2>Committing to:...trunk/
 
947
            2>added file
 
948
            2>Committed revision 2.
 
949
            $ brz push -r 1 ../other
 
950
            2>Created new branch.
 
951
            $ brz st ../other # checking that file is not created (#484516)
 
952
            """)